2013-04-04 200 views
1

我正在使用Ruby并试图绑定LDAP服务器。 Ruby的文档似乎是非常含糊这里不是很明显我需要以下后做:绑定到LDAP服务

>> require 'uri' 
=> true 

>> newuri = URI::LDAP.build({:host => '10.1.1.1', :dc => 'cjndemo' , :dc => 'com',  :user =>'admin', :password => 'Passw0rd'}) 
=> #<URI::LDAP:0x007fea9d0cef60 URL:ldap://10.1.1.1?> 

什么我需要做绑定,然后查询我的LDAP服务?

回答

2

URI :: LDAP仅用于解析和生成LDAP URI。如果您想查询LDAP服务器,则需要使用其他工具,如net-ldapruby-ldap

的使用net-LDAP简单验证绑定一个例子:

require 'net/ldap' 

ldap = Net::LDAP.new(:host => '10.1.1.1', 
        :auth => { 
         :method => :simple, 
         :username => 'cn=admin,dc=cjndemo,dc=com', 
         :password => 'Passw0rd' 
         }) 

if ldap.bind 
    base = 'dc=cjndemo,dc=com' 
    filter = Net::LDAP::Filter.eq('objectclass', '*') 
    ldap.search(:base => base, :filter => filter) do |object| 
    puts "dn: #{object.dn}" 
    end 
else 
    # authentication error 
end 
+0

编曲 - 我明白了。这两个库有什么不同? – user1513388 2013-04-04 15:21:17