Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net-ldap'
- class Ldap
- def initialize(username, password, host, port, base)
- ldap_settings = { host: host, port: port, auth: { method: :simple, username: username, password: password } }
- @ldap = Net::LDAP.new(ldap_settings)
- @base = base
- end
- def find_user_by_email(email)
- search_for_user_by_attribute('proxyAddresses', "smtp:#{email}")
- end
- def find_user_by_username(username)
- search_for_user_by_attribute('sAMAccountName', username)
- end
- private
- def search_for_user_by_attribute(attribute, value)
- filter = Net::LDAP::Filter.eq(attribute, value)
- result = @ldap.search(base: @base, filter: filter)
- result.first unless result.nil?
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement