Ruby连接到LDAP技巧分享

开发 开发工具
Ruby连接到LDAP实在实际编程中经常遇到的问题。我们会为大家详细介绍有关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的方法能够帮助大家。

责任编辑:曹凯 来源: ddvip.com
相关推荐

2009-12-15 18:24:02

Ruby连接到orac

2009-12-15 10:23:23

Ruby应用技巧

2009-12-18 10:47:16

Ruby装饰模式

2009-12-16 10:10:16

Ruby打开关闭文件

2009-12-17 10:18:17

Ruby创建构造器

2009-12-18 14:10:29

Ruby访问剪贴板

2009-12-16 11:04:51

Ruby操作文件权限

2009-12-16 15:46:41

Ruby on rai

2009-12-16 10:49:42

Ruby操作二进制文件

2009-12-15 18:03:46

Ruby连接数据库

2009-12-14 09:33:04

Ruby安装

2009-12-18 17:01:37

Ruby基础代码

2009-12-16 16:37:59

Ruby on Rai

2009-12-14 15:30:43

安装Ruby on R

2009-12-14 18:23:38

Ruby DSL测试

2009-12-16 15:23:33

Ruby on rai

2009-12-18 17:24:12

Ruby配置Mysql

2009-12-15 14:51:50

Ruby继承

2009-12-17 09:49:18

Ruby代码管理

2010-01-15 19:24:42

点赞
收藏

51CTO技术栈公众号