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

warden.rb « initializers « config - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c06cedf473d7691a6add1f4f0479faf5bc50b5db (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
51
52
Rails.application.configure do |config|
  Warden::Manager.after_set_user(scope: :user) do |user, auth, opts|
    Gitlab::Auth::UniqueIpsLimiter.limit_user!(user)

    activity = Gitlab::Auth::Activity.new(opts)

    case opts[:event]
    when :authentication
      activity.user_authenticated!
    when :set_user
      activity.user_authenticated!
      activity.user_session_override!
    when :fetch # rubocop:disable Lint/EmptyWhen
      # We ignore session fetch events
    else
      activity.user_session_override!
    end
  end

  Warden::Manager.after_authentication(scope: :user) do |user, auth, opts|
    ActiveSession.cleanup(user)
  end

  Warden::Manager.after_set_user(scope: :user, only: :fetch) do |user, auth, opts|
    ActiveSession.set(user, auth.request)
  end

  Warden::Manager.before_failure(scope: :user) do |env, opts|
    Gitlab::Auth::Activity.new(opts).user_authentication_failed!
  end

  Warden::Manager.before_logout(scope: :user) do |user, auth, opts|
    ActiveSession.destroy(user || auth.user, auth.request.session.id)

    activity = Gitlab::Auth::Activity.new(opts)
    tracker = Gitlab::Auth::BlockedUserTracker.new(user, auth)

    ##
    # It is possible that `before_logout` event is going to be triggered
    # multiple times during the request lifecycle. We want to increment
    # metrics and write logs only once in that case.
    #
    next if (auth.env['warden.auth.trackers'] ||= {}).push(activity).many?

    if user.blocked?
      activity.user_blocked!
      tracker.log_activity!
    end

    activity.user_session_destroyed!
  end
end