@@ -35,9 +35,9 class AuthSourceLdap < AuthSource | |||||
35 | return nil if login.blank? || password.blank? |
|
35 | return nil if login.blank? || password.blank? | |
36 | attrs = get_user_dn(login) |
|
36 | attrs = get_user_dn(login) | |
37 |
|
37 | |||
38 |
if attrs |
|
38 | if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password) | |
39 | logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? |
|
39 | logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? | |
40 |
return |
|
40 | return attrs.except(:dn) | |
41 | end |
|
41 | end | |
42 | rescue Net::LDAP::LdapError => text |
|
42 | rescue Net::LDAP::LdapError => text | |
43 | raise "LdapError: " + text |
|
43 | raise "LdapError: " + text | |
@@ -73,13 +73,13 class AuthSourceLdap < AuthSource | |||||
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def get_user_attributes_from_ldap_entry(entry) |
|
75 | def get_user_attributes_from_ldap_entry(entry) | |
76 |
|
|
76 | { | |
77 | :dn => entry.dn, |
|
77 | :dn => entry.dn, | |
78 | :firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname), |
|
78 | :firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname), | |
79 | :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname), |
|
79 | :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname), | |
80 | :mail => AuthSourceLdap.get_attr(entry, self.attr_mail), |
|
80 | :mail => AuthSourceLdap.get_attr(entry, self.attr_mail), | |
81 | :auth_source_id => self.id |
|
81 | :auth_source_id => self.id | |
82 |
|
|
82 | } | |
83 | end |
|
83 | end | |
84 |
|
84 | |||
85 | # Return the attributes needed for the LDAP search. It will only |
|
85 | # Return the attributes needed for the LDAP search. It will only | |
@@ -104,7 +104,7 class AuthSourceLdap < AuthSource | |||||
104 | ldap_con = initialize_ldap_con(self.account, self.account_password) |
|
104 | ldap_con = initialize_ldap_con(self.account, self.account_password) | |
105 | login_filter = Net::LDAP::Filter.eq( self.attr_login, login ) |
|
105 | login_filter = Net::LDAP::Filter.eq( self.attr_login, login ) | |
106 | object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) |
|
106 | object_filter = Net::LDAP::Filter.eq( "objectClass", "*" ) | |
107 |
attrs = |
|
107 | attrs = {} | |
108 |
|
108 | |||
109 | ldap_con.search( :base => self.base_dn, |
|
109 | ldap_con.search( :base => self.base_dn, | |
110 | :filter => object_filter & login_filter, |
|
110 | :filter => object_filter & login_filter, | |
@@ -113,10 +113,10 class AuthSourceLdap < AuthSource | |||||
113 | if onthefly_register? |
|
113 | if onthefly_register? | |
114 | attrs = get_user_attributes_from_ldap_entry(entry) |
|
114 | attrs = get_user_attributes_from_ldap_entry(entry) | |
115 | else |
|
115 | else | |
116 |
attrs = |
|
116 | attrs = {:dn => entry.dn} | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 |
logger.debug "DN found for #{login}: #{attrs |
|
119 | logger.debug "DN found for #{login}: #{attrs[:dn]}" if logger && logger.debug? | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | attrs |
|
122 | attrs |
@@ -111,7 +111,7 class User < Principal | |||||
111 | # user is not yet registered, try to authenticate with available sources |
|
111 | # user is not yet registered, try to authenticate with available sources | |
112 | attrs = AuthSource.authenticate(login, password) |
|
112 | attrs = AuthSource.authenticate(login, password) | |
113 | if attrs |
|
113 | if attrs | |
114 |
user = new( |
|
114 | user = new(attrs) | |
115 | user.login = login |
|
115 | user.login = login | |
116 | user.language = Setting.default_language |
|
116 | user.language = Setting.default_language | |
117 | if user.save |
|
117 | if user.save |
@@ -149,7 +149,7 class AccountTest < ActionController::IntegrationTest | |||||
149 | def test_onthefly_registration |
|
149 | def test_onthefly_registration | |
150 | # disable registration |
|
150 | # disable registration | |
151 | Setting.self_registration = '0' |
|
151 | Setting.self_registration = '0' | |
152 |
AuthSource.expects(:authenticate).returns( |
|
152 | AuthSource.expects(:authenticate).returns({:login => 'foo', :firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com', :auth_source_id => 66}) | |
153 |
|
153 | |||
154 | post 'account/login', :username => 'foo', :password => 'bar' |
|
154 | post 'account/login', :username => 'foo', :password => 'bar' | |
155 | assert_redirected_to 'my/page' |
|
155 | assert_redirected_to 'my/page' | |
@@ -163,7 +163,7 class AccountTest < ActionController::IntegrationTest | |||||
163 | def test_onthefly_registration_with_invalid_attributes |
|
163 | def test_onthefly_registration_with_invalid_attributes | |
164 | # disable registration |
|
164 | # disable registration | |
165 | Setting.self_registration = '0' |
|
165 | Setting.self_registration = '0' | |
166 |
AuthSource.expects(:authenticate).returns( |
|
166 | AuthSource.expects(:authenticate).returns({:login => 'foo', :lastname => 'Smith', :auth_source_id => 66}) | |
167 |
|
167 | |||
168 | post 'account/login', :username => 'foo', :password => 'bar' |
|
168 | post 'account/login', :username => 'foo', :password => 'bar' | |
169 | assert_response :success |
|
169 | assert_response :success |
@@ -43,10 +43,8 class AuthSourceLdapTest < ActiveSupport::TestCase | |||||
43 |
|
43 | |||
44 | context 'with a valid LDAP user' do |
|
44 | context 'with a valid LDAP user' do | |
45 | should 'return the user attributes' do |
|
45 | should 'return the user attributes' do | |
46 |
res |
|
46 | attributes = @auth.authenticate('example1','123456') | |
47 |
assert res |
|
47 | assert attributes.is_a?(Hash), "An hash was not returned" | |
48 | assert response.first.present?, "No user data returned" |
|
|||
49 | attributes = response.first |
|
|||
50 | assert_equal 'Example', attributes[:firstname] |
|
48 | assert_equal 'Example', attributes[:firstname] | |
51 | assert_equal 'One', attributes[:lastname] |
|
49 | assert_equal 'One', attributes[:lastname] | |
52 | assert_equal 'example1@redmine.org', attributes[:mail] |
|
50 | assert_equal 'example1@redmine.org', attributes[:mail] |
General Comments 0
You need to be logged in to leave comments.
Login now