Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HomeController < ApplicationController
- require 'rubygems'
- require 'ldap'
- def index
- # simple query to an Active Directory server
- host = 'adserver' # illustration only
- port = 389
- conn = LDAP::Conn.new(host,port)
- query = 'bogus'
- searcher_username = 'domain.com\user' # illustration only
- searcher_password = 'password' # illustration only
- search_dn = 'cn=users,dc=domain,dc=com' # illustration only
- conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
- filter="(&(objectClass=user)" +
- "(|(samaccountname=*#{query}*)" +
- "(givenName=*#{query}*)" +
- "(sn=*#{query}*)))"
- conn.bind searcher_username, searcher_password do
- conn.search(search_dn,
- LDAP::LDAP_SCOPE_SUBTREE,
- filter,
- ['samaccountname','mail','givenName','sn']
- ) do |e|
- logger.info(e.inspect)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment