summaryrefslogtreecommitdiff
path: root/app/controllers/ldap/omniauth_callbacks_controller.rb
blob: 9a5a45939e0bd89ec38662774ad74ce51376274c (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
# frozen_string_literal: true

class Ldap::OmniauthCallbacksController < OmniauthCallbacksController
  extend ::Gitlab::Utils::Override

  def self.define_providers!
    return unless Gitlab::Auth::LDAP::Config.enabled?

    Gitlab::Auth::LDAP::Config.available_servers.each do |server|
      alias_method server['provider_name'], :ldap
    end
  end

  # We only find ourselves here
  # if the authentication to LDAP was successful.
  def ldap
    sign_in_user_flow(Gitlab::Auth::LDAP::User)
  end

  define_providers!

  override :set_remember_me
  def set_remember_me(user)
    user.remember_me = params[:remember_me] if user.persisted?
  end

  override :fail_login
  def fail_login(user)
    flash[:alert] = _('Access denied for your LDAP account.')

    redirect_to new_user_session_path
  end
end