Skip to content

Commit 4f268c5

Browse files
committed
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
1 parent 9e22faa commit 4f268c5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/models/auth_source_ldap.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ def authenticate(login, password)
4949
end
5050
return nil if dn.empty?
5151
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
52-
# authenticate user
53-
ldap_con = initialize_ldap_con(dn, password)
54-
return nil unless ldap_con.bind
55-
# return user's attributes
56-
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
57-
attrs
52+
53+
if authenticate_dn(dn, password)
54+
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
55+
return attrs
56+
else
57+
return nil
58+
end
5859
rescue Net::LDAP::LdapError => text
5960
raise "LdapError: " + text
6061
end
@@ -96,6 +97,12 @@ def get_user_attributes_from_ldap_entry(entry)
9697
:auth_source_id => self.id
9798
]
9899
end
100+
101+
# Check if a DN (user record) authenticates with the password
102+
def authenticate_dn(dn, password)
103+
ldap_con = initialize_ldap_con(dn, password)
104+
return ldap_con.bind
105+
end
99106

100107
def self.get_attr(entry, attr_name)
101108
if !attr_name.blank?

0 commit comments

Comments
 (0)