Reputation: 7451
I'm using Ruby and trying to bind an LDAP server. The Ruby documentation seems to be very vague here and it's not obvious what I need to do after the following:
>> 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?>
What do I need to do to bind then query my LDAP service?
Upvotes: 1
Views: 2321
Reputation: 19238
URI::LDAP is only for parsing and generating LDAP URIs. If you want to query the LDAP server you need to use a different tool like net-ldap or ruby-ldap.
An example of binding with simple authentication using 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
Upvotes: 2