Feature #1913 » 1913_redmine_bind_as_user.diff
| app/models/auth_source_ldap.rb | ||
|---|---|---|
|
|
||
|
def authenticate(login, password)
|
||
|
return nil if login.blank? || password.blank?
|
||
|
attrs = get_user_dn(login)
|
||
|
|
||
|
if attrs.first && attrs.first[:dn] && authenticate_dn(attrs.first[:dn], password)
|
||
|
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||
|
return attrs
|
||
|
if self.account.include? "$login" then
|
||
|
logger.debug "LDAP-Auth with User login"
|
||
|
self.ldap_con = initialize_ldap_con(self.account.sub("$login", login), password)
|
||
|
if self.ldap_con.bind then
|
||
|
return get_user_dn(login)
|
||
|
end
|
||
|
else
|
||
|
logger.debug "LDAP-Auth with Admin User"
|
||
|
self.ldap_con = initialize_ldap_con(self.account, self.account_password)
|
||
|
attrs = get_user_dn(login)
|
||
|
if attrs.first && attrs.first[:dn] && authenticate_dn(attrs.first[:dn], password) then
|
||
|
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
|
||
|
return attrs
|
||
|
end
|
||
|
end
|
||
|
rescue Net::LDAP::LdapError => text
|
||
|
raise "LdapError: " + text
|
||
| ... | ... | |
|
# 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)
|
||
|
login_filter = Net::LDAP::Filter.eq( self.attr_login, login )
|
||
|
object_filter = Net::LDAP::Filter.eq( "objectClass", "*" )
|
||
|
attrs = []
|
||
|
|
||
|
ldap_con.search( :base => self.base_dn,
|
||
|
self.ldap_con.search( :base => self.base_dn,
|
||
|
:filter => object_filter & login_filter,
|
||
|
:attributes=> search_attributes) do |entry|
|
||