Skip to content

Instantly share code, notes, and snippets.

@sriram15690
Created June 27, 2015 20:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriram15690/4512094cead7254ba331 to your computer and use it in GitHub Desktop.
Save sriram15690/4512094cead7254ba331 to your computer and use it in GitHub Desktop.
LDAP with Ruby
#dc - domain component
#cn - common name
#ou - org units
require 'net/ldap'
class Ldap
attr_accessor :ldap_connection, :params, :ldap_response
def initialize(params = {})
self.ldap_connection = connect_to_ldap_server()
self.params = params
end
def connect_to_ldap_server
ldap = Net::LDAP.new :host => "ldap.forumsys.com",
:port => 389,
:base => "dc=example,dc=com",
:auth => {
:method => :simple,
:username => "",
:password => ""
}
puts ldap.inspect
ldap
end
def search_ldap
#to get all groups
groups = Net::LDAP::Filter.eq("objectclass", "groupOfUniqueNames")
puts ldap_connection.search(:filter => groups).inspect
#to get All Mathematicians
mathematician_filter = Net::LDAP::Filter.eq("ou", "mathematicians")
puts ldap_connection.search(:filter => mathematician_filter).inspect
particular_mathematician = Net::LDAP::Filter.eq("uid", "euclid")
#to get particular Mathematician
puts ldap_connection.search(:filter => particular_mathematician).inspect
end
end
obj = Ldap.new()
obj.search_ldap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment