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

authentication.rb « crowd « auth « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f3e980034e4fe82eaba1b0b8843084b7184a271 (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
# frozen_string_literal: true

module Gitlab
  module Auth
    module Crowd
      class Authentication < Gitlab::Auth::OAuth::Authentication
        def login(login, password)
          return unless Gitlab::Auth::OAuth::Provider.enabled?(@provider)
          return unless login.present? && password.present?

          user_info = user_info_from_authentication(login, password)
          return unless user_info&.key?(:user)

          Gitlab::Auth::OAuth::User.find_by_uid_and_provider(user_info[:user], provider)
        end

        private

        def config
          gitlab_crowd_config = Gitlab::Auth::OAuth::Provider.config_for(@provider)
          raise "OmniAuth Crowd is not configured." unless gitlab_crowd_config && gitlab_crowd_config[:args]

          OmniAuth::Strategies::Crowd::Configuration.new(
            gitlab_crowd_config[:args].symbolize_keys)
        end

        def user_info_from_authentication(login, password)
          validator = OmniAuth::Strategies::Crowd::CrowdValidator.new(
            config, login, password, RequestContext.instance.client_ip, nil)
          validator&.user_info&.symbolize_keys
        end
      end
    end
  end
end