diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-06-06 18:47:49 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-06-06 18:47:49 -0500 |
commit | 7038440e342a521807b1e5ffb6d47d4c0b13048d (patch) | |
tree | b22cdf0ac390d0ccec2ddee46ad351d62175a993 /lib/gitlab/saml | |
parent | 740a6ecba07a056fca481622b4fa89939c225987 (diff) | |
download | gitlab-ce-7038440e342a521807b1e5ffb6d47d4c0b13048d.tar.gz |
Adjust the SAML control flow to allow LDAP identities to be added to an existing SAML user.
Diffstat (limited to 'lib/gitlab/saml')
-rw-r--r-- | lib/gitlab/saml/user.rb | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/gitlab/saml/user.rb b/lib/gitlab/saml/user.rb index dba4bbfc899..6f7d4825ae5 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 @@ -62,6 +62,30 @@ module Gitlab !Gitlab::Saml::Config.external_groups.nil? end + def find_or_create_ldap_user + return unless ldap_person + + # If a corresponding person exists with same uid in a LDAP server, + # 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 SAML identity to existing account. + user.identities.build(extern_uid: auth_hash.uid, provider: auth_hash.provider) + else + # No account found using LDAP in Gitlab yet: check if there is a SAML account with + # the passed uid and provider + user = find_by_uid_and_provider + if user.nil? + # No SAML account found, build a new user. + user = build_new_user + end + # Correct account is present, add the LDAP Identity to the user. + user.identities.new(provider: ldap_person.provider, extern_uid: ldap_person.dn) + end + + user + end + def auth_hash=(auth_hash) @auth_hash = Gitlab::Saml::AuthHash.new(auth_hash) end |