Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'net/ldap'
- LDAP_Servers_Transit = ['trn02svpdc01', 'trn02svpdc02']
- LDAP_Servers_Corporate = ['cowsvpdc01', 'cowsvpdc02', 'cowsvpdc03', 'cowsvpdc04', 'cowsvpdc05']
- def authenticate(user_name, password, ldap_servers = LDAP_Servers_Transit, port = 389)
- ldap_servers.each do |server|
- begin
- # Try to connect to the LDAP server as the user
- ldap = Net::LDAP.new( {:host => server, :port => port, :auth => { :method => :simple, :username => user_name, :password => password }} )
- return ldap.bind
- rescue Net::LDAP::LdapError
- # Log failure and try next server
- puts "Error connecting to server #{server}"
- end
- end
- false # Unable to connect to any of the servers
- end
- user_id = 'slamotte'
- password = 'pw'
- if authenticate(user_id, password)
- puts 'Authenticated'
- else
- puts 'Not Authenticated'
- end
- if authenticate("cowdmp01\\#{user_id}", password, LDAP_Servers_Corporate)
- puts 'Authenticated'
- else
- puts 'Not Authenticated'
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement