Guest User

Untitled

a guest
May 23rd, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. class HomeController < ApplicationController
  2. require 'rubygems'
  3. require 'ldap'
  4. def index
  5. # simple query to an Active Directory server
  6. host = 'adserver' # illustration only
  7. port = 389
  8. conn = LDAP::Conn.new(host,port)
  9. query = 'bogus'
  10. searcher_username = 'domain.com\user' # illustration only
  11. searcher_password = 'password' # illustration only
  12. search_dn = 'cn=users,dc=domain,dc=com' # illustration only
  13.  
  14. conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
  15. filter="(&(objectClass=user)" +
  16. "(|(samaccountname=*#{query}*)" +
  17. "(givenName=*#{query}*)" +
  18. "(sn=*#{query}*)))"
  19. conn.bind searcher_username, searcher_password do
  20. conn.search(search_dn,
  21. LDAP::LDAP_SCOPE_SUBTREE,
  22. filter,
  23. ['samaccountname','mail','givenName','sn']
  24. ) do |e|
  25. logger.info(e.inspect)
  26. end
  27. end
  28. end
  29.  
  30. end
Add Comment
Please, Sign In to add comment