debian-mirror-gitlab/lib/gitlab/auth/ldap/user.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
# 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-04-08 14:13:33 +05:30
module Ldap
2018-03-27 19:54:05 +05:30
class User < Gitlab::Auth::OAuth::User
2018-10-15 14:42:47 +05:30
extend ::Gitlab::Utils::Override
2018-03-27 19:54:05 +05:30
# instance methods
def find_user
find_by_uid_and_provider || find_by_email || build_new_user
end
2018-10-15 14:42:47 +05:30
override :should_save?
def should_save?
2018-03-27 19:54:05 +05:30
gl_user.changed? || gl_user.identities.any?(&:changed?)
end
def block_after_signup?
ldap_config.block_auto_created_users
end
def allowed?
2020-04-08 14:13:33 +05:30
Gitlab::Auth::Ldap::Access.allowed?(gl_user)
2018-03-27 19:54:05 +05:30
end
2018-10-15 14:42:47 +05:30
def valid_sign_in?
2022-08-13 15:12:31 +05:30
# The order is important here: we need to ensure the
# associated GitLab user entry is valid and persisted in the
# database. Otherwise, the LDAP access check will fail since
# the user doesn't have an associated LDAP identity.
super && allowed?
2018-10-15 14:42:47 +05:30
end
2018-03-27 19:54:05 +05:30
def ldap_config
2020-04-08 14:13:33 +05:30
Gitlab::Auth::Ldap::Config.new(auth_hash.provider)
2018-03-27 19:54:05 +05:30
end
def auth_hash=(auth_hash)
2020-04-08 14:13:33 +05:30
@auth_hash = Gitlab::Auth::Ldap::AuthHash.new(auth_hash)
2018-03-27 19:54:05 +05:30
end
2022-05-07 20:08:51 +05:30
def protocol_name
'LDAP'
end
2018-03-27 19:54:05 +05:30
end
end
end
end
2020-05-24 23:13:21 +05:30
2021-06-08 01:23:25 +05:30
Gitlab::Auth::Ldap::User.prepend_mod_with('Gitlab::Auth::Ldap::User')