summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-29 11:51:46 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-29 11:51:46 -0700
commitc388f3db56c7804efa5ac945f55d6261be39d1fd (patch)
tree2f95e645a24d4f84ae023452687e89db9cd948ce /lib
parenta429eb4d455cabde26c5cdf8a3b38e65966531dc (diff)
parent12d8b01eb2df532815306db602d116e3177d750e (diff)
downloadgitlab-ce-c388f3db56c7804efa5ac945f55d6261be39d1fd.tar.gz
Merge branch 'joelkoglin/gitlab-ce-feature_fix_ldap_auth_issue_993'
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ldap/user.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb
index f7f3ba9ad7d..04a22237478 100644
--- a/lib/gitlab/ldap/user.rb
+++ b/lib/gitlab/ldap/user.rb
@@ -44,9 +44,14 @@ module Gitlab
gl_user.skip_reconfirmation!
gl_user.email = auth_hash.email
- # Build new identity only if we dont have have same one
- gl_user.identities.find_or_initialize_by(provider: auth_hash.provider,
- extern_uid: auth_hash.uid)
+ # find_or_initialize_by doesn't update `gl_user.identities`, and isn't autosaved.
+ identity = gl_user.identities.find { |identity| identity.provider == auth_hash.provider }
+ identity ||= gl_user.identities.build(provider: auth_hash.provider)
+
+ # For a new user set extern_uid to the LDAP DN
+ # For an existing user with matching email but changed DN, update the DN.
+ # For an existing user with no change in DN, this line changes nothing.
+ identity.extern_uid = auth_hash.uid
gl_user
end