2014-09-02 18:07:02 +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 LDAP
|
|
|
|
class User < Gitlab::OAuth::User
|
|
|
|
class << self
|
2015-04-26 12:48:37 +05:30
|
|
|
def find_by_uid_and_provider(uid, provider)
|
2018-03-17 18:26:18 +05:30
|
|
|
identity = ::Identity.with_extern_uid(provider, uid).take
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
identity && identity.user
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def save
|
|
|
|
super('LDAP')
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
# instance methods
|
2018-03-17 18:26:18 +05:30
|
|
|
def find_user
|
|
|
|
find_by_uid_and_provider || find_by_email || build_new_user
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def find_by_uid_and_provider
|
2016-01-29 22:53:50 +05:30
|
|
|
self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def changed?
|
|
|
|
gl_user.changed? || gl_user.identities.any?(&:changed?)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def block_after_signup?
|
|
|
|
ldap_config.block_auto_created_users
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def allowed?
|
|
|
|
Gitlab::LDAP::Access.allowed?(gl_user)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def ldap_config
|
|
|
|
Gitlab::LDAP::Config.new(auth_hash.provider)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
def auth_hash=(auth_hash)
|
|
|
|
@auth_hash = Gitlab::LDAP::AuthHash.new(auth_hash)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|