Created
June 27, 2015 20:24
-
-
Save sriram15690/4512094cead7254ba331 to your computer and use it in GitHub Desktop.
LDAP with Ruby
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
#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