Refactor: extract an #authenticate_dn method in AuthSourceLdap

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3441 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-02-17 16:35:35 +00:00
parent 9e22faa640
commit 4f268c5606
1 changed files with 13 additions and 6 deletions

View File

@ -49,12 +49,13 @@ class AuthSourceLdap < AuthSource
end end
return nil if dn.empty? return nil if dn.empty?
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug? logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
# authenticate user
ldap_con = initialize_ldap_con(dn, password) if authenticate_dn(dn, password)
return nil unless ldap_con.bind
# return user's attributes
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
attrs return attrs
else
return nil
end
rescue Net::LDAP::LdapError => text rescue Net::LDAP::LdapError => text
raise "LdapError: " + text raise "LdapError: " + text
end end
@ -97,6 +98,12 @@ class AuthSourceLdap < AuthSource
] ]
end end
# Check if a DN (user record) authenticates with the password
def authenticate_dn(dn, password)
ldap_con = initialize_ldap_con(dn, password)
return ldap_con.bind
end
def self.get_attr(entry, attr_name) def self.get_attr(entry, attr_name)
if !attr_name.blank? if !attr_name.blank?
entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name] entry[attr_name].is_a?(Array) ? entry[attr_name].first : entry[attr_name]