Welcome to mirror list, hosted at ThFree Co, Russian Federation.

auth_hash.rb « ldap « auth « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5435355f136827cce6771925d704918b1828b75a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

# Class to parse and transform the info provided by omniauth
#
module Gitlab
  module Auth
    module Ldap
      class AuthHash < Gitlab::Auth::OAuth::AuthHash
        def uid
          @uid ||= Gitlab::Auth::Ldap::Person.normalize_dn(super)
        end

        def username
          super.tap do |username|
            username.downcase! if ldap_config.lowercase_usernames
          end
        end

        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

          return super unless value

          Gitlab::Utils.force_utf8(value)
          value
        end

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

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