Created
December 16, 2010 02:44
-
-
Save baconpat/742953 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveDirectory | |
include EnvironmentConfigurable | |
configure_with "config/active_directory.yml" | |
def self.valid_credentials?(login, password) | |
ldap = Net::LDAP.new( | |
:host => config.host, # active_directory.atomicobject.com | |
:port => config.port, # 389 | |
:base => config.base, # dc=atomicobject,dc=com | |
:auth => { | |
:method => :simple, | |
:username => config.server_username, # cn=server,dc=atomicobject,dc=com | |
:password => config.server_password # server password | |
} | |
) | |
filter = Net::LDAP::Filter.eq('sAMAccountName', login) | |
if ldap.bind_as(:filter => filter, :password => password) | |
true | |
else | |
Rails.logger.error("Active Directory validation failed for '#{login}': #{ldap.get_operation_result.message}") | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment