Skip to content

Commit

Permalink
Refactor: extract an #authenticate_dn method in AuthSourceLdap
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3441 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Feb 17, 2010
1 parent 9e22faa commit 4f268c5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/models/auth_source_ldap.rb
Expand Up @@ -49,12 +49,13 @@ def authenticate(login, password)
end
return nil if dn.empty?
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
# authenticate user
ldap_con = initialize_ldap_con(dn, password)
return nil unless ldap_con.bind
# return user's attributes
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
attrs

if authenticate_dn(dn, password)
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
return attrs
else
return nil
end
rescue Net::LDAP::LdapError => text
raise "LdapError: " + text
end
Expand Down Expand Up @@ -96,6 +97,12 @@ def get_user_attributes_from_ldap_entry(entry)
:auth_source_id => self.id
]
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)
if !attr_name.blank?
Expand Down

0 comments on commit 4f268c5

Please sign in to comment.