2015-09-25 12:07:36 +05:30
|
|
|
# Class to parse and transform the info provided by omniauth
|
|
|
|
#
|
|
|
|
module Gitlab
|
|
|
|
module LDAP
|
|
|
|
class AuthHash < Gitlab::OAuth::AuthHash
|
2018-03-17 18:26:18 +05:30
|
|
|
def uid
|
|
|
|
@uid ||= Gitlab::LDAP::Person.normalize_dn(super)
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
super.tap do |username|
|
|
|
|
username.downcase! if ldap_config.lowercase_usernames
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def get_info(key)
|
|
|
|
attributes = ldap_config.attributes[key.to_s]
|
|
|
|
return super unless attributes
|
|
|
|
|
|
|
|
attributes = Array(attributes)
|
|
|
|
|
|
|
|
value = nil
|
|
|
|
attributes.each do |attribute|
|
|
|
|
value = get_raw(attribute)
|
|
|
|
value = value.first if value
|
|
|
|
break if value.present?
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
return super unless value
|
|
|
|
|
|
|
|
Gitlab::Utils.force_utf8(value)
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_raw(key)
|
2017-08-17 22:00:37 +05:30
|
|
|
auth_hash.extra[:raw_info][key] if auth_hash.extra
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def ldap_config
|
|
|
|
@ldap_config ||= Gitlab::LDAP::Config.new(self.provider)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|