2018-10-11 16:12:21 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-23 07:10:39 -05:00
|
|
|
# LDAP extension for User model
|
|
|
|
#
|
|
|
|
# * Find or create user from omniauth.auth data
|
|
|
|
# * Links LDAP account with existing user
|
|
|
|
# * Auth LDAP user with login and password
|
|
|
|
#
|
|
|
|
module Gitlab
|
|
|
|
module Auth
|
2020-03-12 11:09:39 -04:00
|
|
|
module Ldap
|
2018-02-23 07:10:39 -05:00
|
|
|
class User < Gitlab::Auth::OAuth::User
|
2018-04-18 10:03:27 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
2018-02-23 07:10:39 -05:00
|
|
|
def save
|
|
|
|
super('LDAP')
|
|
|
|
end
|
|
|
|
|
|
|
|
# instance methods
|
|
|
|
def find_user
|
|
|
|
find_by_uid_and_provider || find_by_email || build_new_user
|
|
|
|
end
|
|
|
|
|
2018-04-23 11:20:33 -04:00
|
|
|
override :should_save?
|
|
|
|
def should_save?
|
2018-02-23 07:10:39 -05:00
|
|
|
gl_user.changed? || gl_user.identities.any?(&:changed?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def block_after_signup?
|
|
|
|
ldap_config.block_auto_created_users
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed?
|
2020-03-12 11:09:39 -04:00
|
|
|
Gitlab::Auth::Ldap::Access.allowed?(gl_user)
|
2018-02-23 07:10:39 -05:00
|
|
|
end
|
|
|
|
|
2018-04-18 10:03:27 -04:00
|
|
|
def valid_sign_in?
|
2018-04-23 11:03:01 -04:00
|
|
|
allowed? && super
|
2018-04-18 10:03:27 -04:00
|
|
|
end
|
|
|
|
|
2018-02-23 07:10:39 -05:00
|
|
|
def ldap_config
|
2020-03-12 11:09:39 -04:00
|
|
|
Gitlab::Auth::Ldap::Config.new(auth_hash.provider)
|
2018-02-23 07:10:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def auth_hash=(auth_hash)
|
2020-03-12 11:09:39 -04:00
|
|
|
@auth_hash = Gitlab::Auth::Ldap::AuthHash.new(auth_hash)
|
2018-02-23 07:10:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 08:09:44 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Gitlab::Auth::Ldap::User.prepend_mod_with('Gitlab::Auth::Ldap::User')
|