2013-09-02 16:35:40 -04:00
|
|
|
# LDAP extension for User model
|
|
|
|
#
|
|
|
|
# * Find or create user from omniauth.auth data
|
|
|
|
# * Links LDAP account with existing user
|
2013-09-03 17:06:13 -04:00
|
|
|
# * Auth LDAP user with login and password
|
2013-09-02 16:35:40 -04:00
|
|
|
#
|
|
|
|
module Gitlab
|
|
|
|
module LDAP
|
2013-09-03 17:06:13 -04:00
|
|
|
class User < Gitlab::OAuth::User
|
2013-09-02 16:35:40 -04:00
|
|
|
class << self
|
2014-10-13 11:24:05 -04:00
|
|
|
def find_by_uid_and_provider(uid, provider)
|
2014-01-30 07:11:19 -05:00
|
|
|
# LDAP distinguished name is case-insensitive
|
2017-06-21 09:48:12 -04:00
|
|
|
identity = ::Identity
|
|
|
|
.where(provider: provider)
|
|
|
|
.iwhere(extern_uid: uid).last
|
2014-11-25 11:15:30 -05:00
|
|
|
identity && identity.user
|
2013-09-02 16:35:40 -04:00
|
|
|
end
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
2013-09-02 16:35:40 -04:00
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
def save
|
|
|
|
super('LDAP')
|
|
|
|
end
|
|
|
|
|
2014-10-10 06:03:32 -04:00
|
|
|
# instance methods
|
2017-09-25 13:07:45 -04:00
|
|
|
def find_user
|
|
|
|
find_by_uid_and_provider || find_by_email || build_new_user
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
2014-09-08 08:53:59 -04:00
|
|
|
|
2014-10-10 06:03:32 -04:00
|
|
|
def find_by_uid_and_provider
|
2016-01-19 10:25:38 -05:00
|
|
|
self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider)
|
2014-10-10 06:03:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def changed?
|
2015-01-29 16:28:41 -05:00
|
|
|
gl_user.changed? || gl_user.identities.any?(&:changed?)
|
2013-09-02 16:35:40 -04:00
|
|
|
end
|
2014-09-03 11:33:03 -04:00
|
|
|
|
2015-04-14 11:09:05 -04:00
|
|
|
def block_after_signup?
|
|
|
|
ldap_config.block_auto_created_users
|
2014-09-03 11:33:03 -04:00
|
|
|
end
|
2014-10-13 11:24:05 -04:00
|
|
|
|
2017-08-29 04:57:41 -04:00
|
|
|
def sync_profile_from_provider?
|
2017-06-06 11:39:54 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-10-13 11:24:05 -04:00
|
|
|
def allowed?
|
|
|
|
Gitlab::LDAP::Access.allowed?(gl_user)
|
|
|
|
end
|
2015-04-14 11:09:05 -04:00
|
|
|
|
2015-09-09 06:40:31 -04:00
|
|
|
def ldap_config
|
|
|
|
Gitlab::LDAP::Config.new(auth_hash.provider)
|
2015-04-14 11:09:05 -04:00
|
|
|
end
|
2015-09-08 05:58:48 -04:00
|
|
|
|
|
|
|
def auth_hash=(auth_hash)
|
2015-09-09 06:40:31 -04:00
|
|
|
@auth_hash = Gitlab::LDAP::AuthHash.new(auth_hash)
|
2015-09-08 05:58:48 -04:00
|
|
|
end
|
2013-09-02 16:35:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|