Module: CASino::AuthenticationProcessor

Extended by:
ActiveSupport::Concern
Included in:
AuthTokenValidationService, SessionsController
Defined in:
app/processors/casino/authentication_processor.rb

Instance Method Summary collapse

Instance Method Details

#authenticatorsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/processors/casino/authentication_processor.rb', line 30

def authenticators
  @authenticators ||= {}.tap do |authenticators|
    CASino.config[:authenticators].each do |name, auth|
      next unless auth.is_a?(Hash)

      authenticator = if auth[:class]
                        auth[:class].constantize
                      else
                        load_authenticator(auth[:authenticator])
                      end

      authenticators[name] = authenticator.new(auth[:options])
    end
  end
end

#load_user_data(authenticator_name, username) ⇒ Object



23
24
25
26
27
28
# File 'app/processors/casino/authentication_processor.rb', line 23

def load_user_data(authenticator_name, username)
  authenticator = authenticators[authenticator_name]
  return nil if authenticator.nil?
  return nil unless authenticator.respond_to?(:load_user_data)
  authenticator.load_user_data(username)
end

#validate_login_credentials(username, password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/processors/casino/authentication_processor.rb', line 6

def (username, password)
  authentication_result = nil
  authenticators.each do |authenticator_name, authenticator|
    begin
      data = authenticator.validate(username, password)
    rescue CASino::Authenticator::AuthenticatorError => e
      Rails.logger.error "Authenticator '#{authenticator_name}' (#{authenticator.class}) raised an error: #{e}"
    end
    if data
      authentication_result = { authenticator: authenticator_name, user_data: data }
      Rails.logger.info("Credentials for username '#{data[:username]}' successfully validated using authenticator '#{authenticator_name}' (#{authenticator.class})")
      break
    end
  end
  authentication_result
end