Skip to content

Instantly share code, notes, and snippets.

@ketanghumatkar
Created June 12, 2018 09:53
Show Gist options
  • Save ketanghumatkar/b56e0b6bcf5fbe9cba8f7149abbd5d42 to your computer and use it in GitHub Desktop.
Save ketanghumatkar/b56e0b6bcf5fbe9cba8f7149abbd5d42 to your computer and use it in GitHub Desktop.
Sample LDAP connection script
## 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