From d828122009cdaaf5f84dd178798e4901f07c326e 2010-02-19 16:33:01 From: Eric Davis Date: 2010-02-19 16:33:01 Subject: [PATCH] Refactor: extract AuthSourceLdap#search_attributes git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3453 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index 4f73621..43a0fc8 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -41,8 +41,7 @@ class AuthSourceLdap < AuthSource dn = String.new ldap_con.search( :base => self.base_dn, :filter => object_filter & login_filter, - # only ask for the DN if on-the-fly registration is disabled - :attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry| + :attributes=> search_attributes) do |entry| dn = entry.dn attrs = get_user_attributes_from_ldap_entry(entry) if onthefly_register? logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug? @@ -95,6 +94,16 @@ class AuthSourceLdap < AuthSource ] 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 def authenticate_dn(dn, password) if dn.present? && password.present?