Advertisement
Guest User

Untitled

a guest
Apr 5th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. require 'net-ldap'
  2.  
  3. class Ldap
  4. def initialize(username, password, host, port, base)
  5. ldap_settings = { host: host, port: port, auth: { method: :simple, username: username, password: password } }
  6. @ldap = Net::LDAP.new(ldap_settings)
  7. @base = base
  8. end
  9.  
  10. def find_user_by_email(email)
  11. search_for_user_by_attribute('proxyAddresses', "smtp:#{email}")
  12. end
  13.  
  14. def find_user_by_username(username)
  15. search_for_user_by_attribute('sAMAccountName', username)
  16. end
  17.  
  18. private
  19. def search_for_user_by_attribute(attribute, value)
  20. filter = Net::LDAP::Filter.eq(attribute, value)
  21. result = @ldap.search(base: @base, filter: filter)
  22. result.first unless result.nil?
  23. end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement