Skip to content

Instantly share code, notes, and snippets.

@qianjigui
Created June 12, 2014 04:08
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 qianjigui/844a15b3c7e881be57a1 to your computer and use it in GitHub Desktop.
Save qianjigui/844a15b3c7e881be57a1 to your computer and use it in GitHub Desktop.
Ruby_LDAP_Use_Example
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