Feature #1913 » Redmine-app-models-auth_source_ldap-0.9.1-2.diff
| redmine/app/models/auth_source_ldap.rb 2010-02-21 16:00:19.000000000 -0500 | ||
|---|---|---|
|
return nil if login.blank? || password.blank?
|
||
|
attrs = []
|
||
|
# get user's DN
|
||
|
ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||
|
if self.account.include? "$login" then
|
||
|
logger.debug "LDAP-Auth with User login"
|
||
|
ldap_con = initialize_ldap_con(self.account.sub("$login", login), password)
|
||
|
else
|
||
|
logger.debug "LDAP-Auth with Admin User"
|
||
|
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", "*" )
|
||
|
dn = String.new
|
||
| ... | ... | |
|
:auth_source_id => self.id ] if onthefly_register?
|
||
|
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?
|
||
|
if not self.account.include? "$login" then
|
||
|
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?
|
||
|
end
|
||
|
attrs
|
||
|
rescue Net::LDAP::LdapError => text
|
||
|
raise "LdapError: " + text
|
||