Refactor: extract AuthSourceLdap#search_attributes

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3453 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-02-19 16:33:01 +00:00
parent 026fbb99a6
commit d828122009
1 changed files with 11 additions and 2 deletions

View File

@ -41,8 +41,7 @@ class AuthSourceLdap < AuthSource
dn = String.new dn = String.new
ldap_con.search( :base => self.base_dn, ldap_con.search( :base => self.base_dn,
:filter => object_filter & login_filter, :filter => object_filter & login_filter,
# only ask for the DN if on-the-fly registration is disabled :attributes=> search_attributes) do |entry|
:attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
dn = entry.dn dn = entry.dn
attrs = get_user_attributes_from_ldap_entry(entry) if onthefly_register? attrs = get_user_attributes_from_ldap_entry(entry) if onthefly_register?
logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug? logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
@ -95,6 +94,16 @@ class AuthSourceLdap < AuthSource
] ]
end end
# Return the attributes needed for the LDAP search. It will only
# include the user attributes if on-the-fly registration is enabled
def search_attributes
if onthefly_register?
['dn', self.attr_firstname, self.attr_lastname, self.attr_mail]
else
['dn']
end
end
# Check if a DN (user record) authenticates with the password # Check if a DN (user record) authenticates with the password
def authenticate_dn(dn, password) def authenticate_dn(dn, password)
if dn.present? && password.present? if dn.present? && password.present?