summaryrefslogtreecommitdiff
path: root/lib/gitlab/ldap/auth_hash.rb
blob: dc8a8fd41dda5186d2986cda061a762136791635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Class to parse and transform the info provided by omniauth
#
module Gitlab
  module LDAP
    class AuthHash < Gitlab::OAuth::AuthHash
      private

      def get_info(key)
        raw_key = ldap_config.attributes[key]
        return super unless raw_key

        value =
          case raw_key
          when String
            get_raw(raw_key)
          when Array
            raw_key.inject(nil) { |value, key| value || get_raw(key).presence }
          else
            nil
          end
        
        return super unless value

        Gitlab::Utils.force_utf8(value)
        value
      end

      def get_raw(key)
        auth_hash.extra[:raw_info][key]
      end

      def ldap_config
        @ldap_config ||= Gitlab::LDAP::Config.new(self.provider)
      end
    end
  end
end