Commit 1a168279 authored by Patricio Cano's avatar Patricio Cano

Prepare SAML for group retrieval

parent 67136007
module Gitlab
module Saml
class AuthHash < Gitlab::OAuth::AuthHash
def groups
get_raw(Gitlab::Saml::Config.groups)
end
private
def get_raw(key)
auth_hash.extra[:raw_info][key]
end
end
end
end
# Load a specific server configuration
module Gitlab
module Saml
class Config
class << self
def options
Gitlab.config.omniauth.providers.find { |provider| provider.name == 'saml' }
end
def groups
options['groups_attribute']
end
def external_groups
options['external_groups']
end
end
end
end
end
...@@ -7,6 +7,11 @@ module Gitlab ...@@ -7,6 +7,11 @@ module Gitlab
module Saml module Saml
class User < Gitlab::OAuth::User class User < Gitlab::OAuth::User
def initialize(auth_hash)
super
update_user_attributes
end
def save def save
super('SAML') super('SAML')
end end
...@@ -18,7 +23,7 @@ module Gitlab ...@@ -18,7 +23,7 @@ module Gitlab
@user ||= find_or_create_ldap_user @user ||= find_or_create_ldap_user
end end
if auto_link_saml_enabled? if auto_link_saml_user?
@user ||= find_by_email @user ||= find_by_email
end end
...@@ -37,11 +42,45 @@ module Gitlab ...@@ -37,11 +42,45 @@ module Gitlab
end end
end end
def changed?
gl_user.changed? || gl_user.identities.any?(&:changed?)
end
protected protected
def auto_link_saml_enabled? def build_new_user
user = super
if external_users_enabled?
unless (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
user.external = true
end
end
user
end
def auto_link_saml_user?
Gitlab.config.omniauth.auto_link_saml_user Gitlab.config.omniauth.auto_link_saml_user
end end
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
def update_user_attributes
if persisted?
if external_users_enabled?
if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
gl_user.external = false
else
gl_user.external = true
end
end
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment