Class: Gitlab::Auth::Activity

Inherits:
Object
  • Object
show all
Extended by:
Utils::StrongMemoize
Defined in:
lib/gitlab/auth/activity.rb

Overview

Metrics and logging for user authentication activity.

Constant Summary collapse

COUNTERS =
{
  user_authenticated: 'Counter of successful authentication events',
  user_unauthenticated: 'Counter of authentication failures',
  user_not_found: 'Counter of failed log-ins when user is unknown',
  user_password_invalid: 'Counter of failed log-ins with invalid password',
  user_session_override: 'Counter of manual log-ins and sessions overrides',
  user_session_destroyed: 'Counter of user sessions being destroyed',
  user_two_factor_authenticated: 'Counter of two factor authentications',
  user_sessionless_authentication: 'Counter of sessionless authentications',
  user_blocked: 'Counter of sign in attempts when user is blocked'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

clear_memoization, strong_memoize, strong_memoized?

Constructor Details

#initialize(opts) ⇒ Activity

Returns a new instance of Activity.


23
24
25
# File 'lib/gitlab/auth/activity.rb', line 23

def initialize(opts)
  @opts = opts
end

Class Method Details

.each_counterObject


64
65
66
67
68
# File 'lib/gitlab/auth/activity.rb', line 64

def self.each_counter
  COUNTERS.each_pair do |metric, description|
    yield "#{metric}_counter", metric, description
  end
end

Instance Method Details

#user_authenticated!Object


38
39
40
41
42
43
44
45
# File 'lib/gitlab/auth/activity.rb', line 38

def user_authenticated!
  self.class.user_authenticated_counter_increment!

  case @opts[:message]
  when :two_factor_authenticated
    self.class.user_two_factor_authenticated_counter_increment!
  end
end

#user_authentication_failed!Object


27
28
29
30
31
32
33
34
35
36
# File 'lib/gitlab/auth/activity.rb', line 27

def user_authentication_failed!
  self.class.user_unauthenticated_counter_increment!

  case @opts[:message]
  when :not_found_in_database
    self.class.user_not_found_counter_increment!
  when :invalid
    self.class.user_password_invalid_counter_increment!
  end
end

#user_blocked!Object


56
57
58
# File 'lib/gitlab/auth/activity.rb', line 56

def user_blocked!
  self.class.user_blocked_counter_increment!
end

#user_session_destroyed!Object


60
61
62
# File 'lib/gitlab/auth/activity.rb', line 60

def user_session_destroyed!
  self.class.user_session_destroyed_counter_increment!
end

#user_session_override!Object


47
48
49
50
51
52
53
54
# File 'lib/gitlab/auth/activity.rb', line 47

def user_session_override!
  self.class.user_session_override_counter_increment!

  case @opts[:message]
  when :sessionless_sign_in
    self.class.user_sessionless_authentication_counter_increment!
  end
end