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

47 lines
1020 B
Ruby
Raw Normal View History

# Class to parse and transform the info provided by omniauth
#
module Gitlab
module LDAP
class AuthHash < Gitlab::OAuth::AuthHash
2017-09-17 21:07:29 -04:00
def uid
@uid ||= Gitlab::LDAP::Person.normalize_dn(super)
2017-09-17 21:07:29 -04:00
end
def username
super.tap do |username|
username.downcase! if ldap_config.lowercase_usernames
end
end
private
def get_info(key)
2015-09-23 10:37:59 -04:00
attributes = ldap_config.attributes[key.to_s]
2015-09-16 03:14:04 -04:00
return super unless attributes
2015-09-16 03:14:04 -04:00
attributes = Array(attributes)
value = nil
attributes.each do |attribute|
value = get_raw(attribute)
2015-09-23 10:37:59 -04:00
value = value.first if value
2015-09-16 03:14:04 -04:00
break if value.present?
end
return super unless value
Gitlab::Utils.force_utf8(value)
value
end
def get_raw(key)
2017-01-05 17:01:04 -05:00
auth_hash.extra[:raw_info][key] if auth_hash.extra
end
2015-09-09 06:40:31 -04:00
def ldap_config
@ldap_config ||= Gitlab::LDAP::Config.new(self.provider)
end
end
end
end