diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-06-09 13:48:31 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-06-09 13:48:31 +0300 |
commit | 30ee4ea6659c91ac6a249d700a9fcdd266676942 (patch) | |
tree | d8f75d19b9bff13fd93d8fe38ce4373404d7b331 /lib | |
parent | 1e4db9ed0f538d17e876ec36b538f05a31989cc0 (diff) | |
parent | 9282810fb7b6102657a0ddb2a02f71b6da22067f (diff) |
Merge branch 'saml-ldap-link-flow' into 'master'
Adjust the SAML control flow to allow LDAP identities to be added to an existing SAML user.
## What does this MR do?
It correctly lets an existing SAML user to add their LDAP identity automatically at login.
## Why was this MR needed?
A customer had issues with the `auto_link_ldap_user` feature. The flow was not working if there was an account with a SAML identity, but no LDAP identity. GitLab would pick up the correct LDAP person, but due to the order of the flow, that LDAP person was never associated with the user.
## What are the relevant issue numbers?
Fixes #17346
/cc @dblessing @balameb @stanhu
See merge request !4498
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/o_auth/user.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/saml/user.rb | 4 |
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/gitlab/o_auth/user.rb b/lib/gitlab/o_auth/user.rb index 356e96fcbab..78f3ecb4cb4 100644 --- a/lib/gitlab/o_auth/user.rb +++ b/lib/gitlab/o_auth/user.rb @@ -69,13 +69,20 @@ module Gitlab return unless ldap_person # If a corresponding person exists with same uid in a LDAP server, - # set up a Gitlab user with dual LDAP and Omniauth identities. - if user = Gitlab::LDAP::User.find_by_uid_and_provider(ldap_person.dn, ldap_person.provider) - # Case when a LDAP user already exists in Gitlab. Add the Omniauth identity to existing account. + # check if the user already has a GitLab account. + user = Gitlab::LDAP::User.find_by_uid_and_provider(ldap_person.dn, ldap_person.provider) + if user + # Case when a LDAP user already exists in Gitlab. Add the OAuth identity to existing account. + log.info "LDAP account found for user #{user.username}. Building new #{auth_hash.provider} identity." user.identities.build(extern_uid: auth_hash.uid, provider: auth_hash.provider) else - # No account in Gitlab yet: create it and add the LDAP identity - user = build_new_user + log.info "No existing LDAP account was found in GitLab. Checking for #{auth_hash.provider} account." + user = find_by_uid_and_provider + if user.nil? + log.info "No user found using #{auth_hash.provider} provider. Creating a new one." + user = build_new_user + end + log.info "Correct account has been found. Adding LDAP identity to user: #{user.username}." user.identities.new(provider: ldap_person.provider, extern_uid: ldap_person.dn) end diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index dba4bbfc899..8943022612c 100644 --- a/lib/gitlab/saml/user.rb +++ b/lib/gitlab/saml/user.rb @@ -12,12 +12,12 @@ module Gitlab end def gl_user - @user ||= find_by_uid_and_provider - if auto_link_ldap_user? @user ||= find_or_create_ldap_user end + @user ||= find_by_uid_and_provider + if auto_link_saml_user? @user ||= find_by_email end |