Created
June 12, 2014 04:08
-
-
Save qianjigui/844a15b3c7e881be57a1 to your computer and use it in GitHub Desktop.
Ruby_LDAP_Use_Example
This file contains 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
class LdapRequest | |
HOST = 'mail.example.com' | |
PORT = 636 | |
TREEBASE='DC=example.com,DC=com' | |
ATTRS=['mail', 'department', 'telephoneNumber', 'mobile'] | |
def initialize(username, password) | |
@ldap = Net::LDAP.new :host => HOST, | |
:port => PORT, | |
:encryption => :simple_tls, | |
:auth => { | |
:method => :simple, | |
:username => username, | |
:password => password | |
} | |
end | |
def search_by_email(email) | |
filter = Net::LDAP::Filter.eq('mail', email) | |
params = {} | |
@ldap.search(:base => TREEBASE, :filter=>filter, :attributes => ATTRS) do |entry| | |
params['department'] = entry['department'].join(',') | |
params['mobile'] = entry['mobile'].join(',') | |
params['telephone'] = entry['telephoneNumber'].join(',') | |
end | |
params | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment