Module: TCellAgent::DeviseInstrumentation::TCellFailureAppRespond

Defined in:
lib/tcell_agent/rails/auth/devise.rb

Instance Method Summary collapse

Instance Method Details

#_get_tcell_passwordObject



55
56
57
58
59
60
61
62
# File 'lib/tcell_agent/rails/auth/devise.rb', line 55

def _get_tcell_password
  tcell_password = nil
  TCellAgent::Instrumentation.safe_block('Devise Get TCell Password') do
    user_params = request.POST.fetch('user', {})
    tcell_password = user_params['password']
  end
  tcell_password
end

#_get_tcell_usernameObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tcell_agent/rails/auth/devise.rb', line 39

def _get_tcell_username
  tcell_username = nil
  TCellAgent::Instrumentation.safe_block('Devise Get TCell Username') do
    keys = scope_class.authentication_keys.dup
    user_params = request.POST.fetch('user', {})
    keys.each do |key|
      next_usename = user_params.fetch(key, nil)
      if next_usename
        tcell_username ||= ''
        tcell_username += next_usename
      end
    end
  end
  tcell_username
end

#respondObject



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
# File 'lib/tcell_agent/rails/auth/devise.rb', line 7

def respond
  TCellAgent::Instrumentation.safe_block('Devise Failure App Respond') do
    if TCellAgent.configuration.should_intercept_requests?
      tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
      if tcell_data
        # in the case of http auth, user_id is set in
        # Devise::Strategies::Authenticatable.valid_for_http_auth?
        user_id = tcell_data.user_id
        user_id ||= _get_tcell_username

        # in the case of http auth, password is set in
        # Devise::Strategies::Authenticatable.valid_for_http_auth?
        password = tcell_data.password
        password ||= _get_tcell_password

        user_valid = warden_message != :not_found_in_database if defined?(warden_message)

         = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
        .(
          user_id,
          password,
          request.env,
          user_valid,
          tcell_data
        )
      end
    end
  end

  super if defined?(super)
end