Ruby连接到LDAP技巧分享

我们在实际编写Ruby语言代码时,在实现Ruby连接到LDAP的情况下,通常都可以使用到三种方法。在这里我们将会学到其中的两种。#t#

Ruby连接到LDAP代码示例:

  1. conn = LDAP::Conn.new("rsads02.foo.com")   
  2. conn.bind("CN=username,CN=Users,DC=foo,
    DC=com","password") do |bound|   
  3. bound.search("DC=foo,DC=com", 
    LDAP::LDAP_SCOPE_SUBTREE,"(&(name=*) 
    (objectCategory=person))", 
    ['name','ipPhone']) do |user|   
  4. puts "#{user['name']} #{user['ipPhone']}"   
  5. end   
  6. end  
  7. require 'net/ldap'   
  8. ldap = Net::LDAP.new :host => 
    server_ip_address,   
  9. :port => 389,   
  10. :auth => {   
  11. :method => :simple,   
  12. :username =>"cn=manager,dc=example,dc=com",   
  13. :password => "opensesame"   
  14.  }   
  15. filter = Net::LDAP::Filter.eq( 
    "cn", "George*" )   
  16. treebase = "dc=example,dc=com"   
  17. ldap.search( :base => treebase,
     :filter => filter )do |entry|   
  18. puts "DN: #{entry.dn}"   
  19. entry.each do |attribute, values|   
  20. puts "  #{attribute}:"   
  21. values.each do |value|   
  22. puts "   --->#{value}"   
  23. end   
  24. end   
  25. end   
  26. p ldap.get_operation_result 

希望以上介绍的这些Ruby连接到LDAP的方法能够帮助大家。

网站题目:Ruby连接到LDAP技巧分享
当前URL:http://www.csdahua.cn/qtweb/news7/444407.html

网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网