debian-mirror-gitlab/lib/gitlab/saml/user.rb

51 lines
1.2 KiB
Ruby
Raw Normal View History

2016-04-02 18:10:28 +05:30
# SAML extension for User model
#
# * Find GitLab user based on SAML uid and provider
# * Create new user from SAML data
#
module Gitlab
module Saml
class User < Gitlab::OAuth::User
def save
super('SAML')
end
2018-03-17 18:26:18 +05:30
def find_user
user = find_by_uid_and_provider
2018-03-17 18:26:18 +05:30
user ||= find_by_email if auto_link_saml_user?
user ||= find_or_build_ldap_user if auto_link_ldap_user?
user ||= build_new_user if signup_enabled?
2016-04-02 18:10:28 +05:30
2018-03-17 18:26:18 +05:30
if external_users_enabled? && user
2016-06-02 11:05:42 +05:30
# Check if there is overlap between the user's groups and the external groups
# setting then set user as external or internal.
2018-03-17 18:26:18 +05:30
user.external = !(auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
2016-06-02 11:05:42 +05:30
end
2018-03-17 18:26:18 +05:30
user
2016-04-02 18:10:28 +05:30
end
2016-06-02 11:05:42 +05:30
def changed?
return true unless gl_user
2018-03-17 18:26:18 +05:30
2016-06-02 11:05:42 +05:30
gl_user.changed? || gl_user.identities.any?(&:changed?)
end
2016-04-02 18:10:28 +05:30
protected
2016-06-02 11:05:42 +05:30
def auto_link_saml_user?
2016-04-02 18:10:28 +05:30
Gitlab.config.omniauth.auto_link_saml_user
end
2016-06-02 11:05:42 +05:30
def external_users_enabled?
!Gitlab::Saml::Config.external_groups.nil?
end
def auth_hash=(auth_hash)
@auth_hash = Gitlab::Saml::AuthHash.new(auth_hash)
end
2016-04-02 18:10:28 +05:30
end
end
end