LDAP: adds the ability to bind with user's account (#1913).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9241 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-03-17 12:09:59 +00:00
parent ef77825f10
commit fdeb398c5e
2 changed files with 58 additions and 3 deletions
+9 -3
View File
@@ -17,6 +17,7 @@
require 'iconv'
require 'net/ldap'
require 'net/ldap/dn'
class AuthSourceLdap < AuthSource
validates_presence_of :host, :port, :attr_login
@@ -35,7 +36,7 @@ class AuthSourceLdap < AuthSource
def authenticate(login, password)
return nil if login.blank? || password.blank?
attrs = get_user_dn(login)
attrs = get_user_dn(login, password)
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
@@ -116,8 +117,13 @@ class AuthSourceLdap < AuthSource
end
# Get the user's dn and any attributes for them, given their login
def get_user_dn(login)
ldap_con = initialize_ldap_con(self.account, self.account_password)
def get_user_dn(login, password)
ldap_con = nil
if self.account && self.account.include?("login")
ldap_con = initialize_ldap_con(self.account.sub("$login", Net::LDAP::DN.escape(login)), password)
else
ldap_con = initialize_ldap_con(self.account, self.account_password)
end
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
attrs = {}