Created
June 12, 2018 09:53
-
-
Save ketanghumatkar/b56e0b6bcf5fbe9cba8f7149abbd5d42 to your computer and use it in GitHub Desktop.
Sample LDAP connection script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Sample ldap example with free testing ldap server | |
require 'rubygems' | |
require 'net/ldap' | |
# direct connect without admin user and password | |
ldap = Net::LDAP.new :host => 'ldap.forumsys.com', | |
:port => 389 | |
# return true if connection successful | |
ldap.bind | |
# search for user with uid | |
filter = Net::LDAP::Filter.eq("uid", "riemann") | |
# connect with filter with base search | |
ldap.bind_as(:base => 'dc=example,dc=com', :size => 1, :password => 'password', :filter => filter) | |
ldap.search(:base => treebase, :filter => filter) do |entry| | |
puts "DN: #{entry.dn}" | |
entry.each do |attribute, values| | |
puts " #{attribute}:" | |
values.each do |value| | |
puts " --->#{value}" | |
end | |
end | |
end | |
p ldap.get_operation_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment