gitlab-org--gitlab-foss/lib/gitlab/ldap/user.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

# 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
def find_by_uid_and_provider(uid, provider)
identity = ::Identity.with_extern_uid(provider, uid).take
identity && identity.user
end
2014-10-10 06:03:32 -04:00
end
def save
super('LDAP')
end
2014-10-10 06:03:32 -04:00
# instance methods
def find_user
find_by_uid_and_provider || find_by_email || build_new_user
2014-10-10 06:03:32 -04:00
end
2014-10-10 06:03:32 -04:00
def find_by_uid_and_provider
self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider)
2014-10-10 06:03:32 -04:00
end
def changed?
gl_user.changed? || gl_user.identities.any?(&:changed?)
end
def block_after_signup?
ldap_config.block_auto_created_users
end
def allowed?
Gitlab::LDAP::Access.allowed?(gl_user)
end
2015-09-09 06:40:31 -04:00
def ldap_config
Gitlab::LDAP::Config.new(auth_hash.provider)
end
def auth_hash=(auth_hash)
2015-09-09 06:40:31 -04:00
@auth_hash = Gitlab::LDAP::AuthHash.new(auth_hash)
end
end
end
end