return nil if login.blank? || password.blank?
attrs = get_user_dn(login)
- if attrs.first && attrs.first[:dn] && authenticate_dn(attrs.first[:dn], password)
+ if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
- return [] << attrs.first.except(:dn)
+ return attrs.except(:dn)
end
rescue Net::LDAP::LdapError => text
raise "LdapError: " + text
end
def get_user_attributes_from_ldap_entry(entry)
- [
+ {
:dn => entry.dn,
:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
:lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
:mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
:auth_source_id => self.id
- ]
+ }
end
# Return the attributes needed for the LDAP search. It will only
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 = []
+ attrs = {}
ldap_con.search( :base => self.base_dn,
:filter => object_filter & login_filter,
if onthefly_register?
attrs = get_user_attributes_from_ldap_entry(entry)
else
- attrs = [:dn => entry.dn]
+ attrs = {:dn => entry.dn}
end
- logger.debug "DN found for #{login}: #{attrs.first[:dn]}" if logger && logger.debug?
+ logger.debug "DN found for #{login}: #{attrs[:dn]}" if logger && logger.debug?
end
attrs
# user is not yet registered, try to authenticate with available sources
attrs = AuthSource.authenticate(login, password)
if attrs
- user = new(*attrs)
+ user = new(attrs)
user.login = login
user.language = Setting.default_language
if user.save
def test_onthefly_registration
# disable registration
Setting.self_registration = '0'
- AuthSource.expects(:authenticate).returns([:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66])
+ AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66})
post 'account/login', :username => 'foo', :password => 'bar'
assert_redirected_to 'my/page'
def test_onthefly_registration_with_invalid_attributes
# disable registration
Setting.self_registration = '0'
- AuthSource.expects(:authenticate).returns([:login => 'foo', :lastname => 'Smith', :auth_source_id => 66])
+ AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
post 'account/login', :username => 'foo', :password => 'bar'
assert_response :success
context 'with a valid LDAP user' do
should 'return the user attributes' do
- response = @auth.authenticate('example1','123456')
- assert response.is_a?(Array), "An array was not returned"
- assert response.first.present?, "No user data returned"
- attributes = response.first
+ attributes = @auth.authenticate('example1','123456')
+ assert attributes.is_a?(Hash), "An hash was not returned"
assert_equal 'Example', attributes[:firstname]
assert_equal 'One', attributes[:lastname]
assert_equal 'example1@redmine.org', attributes[:mail]