Skip to content

class Athena::Security::Authentication::AuthenticatorManager
inherits Reference #

Authenticates the requests of a firewall via its authenticators.

Each authenticator supporting the request creates an ASEC::Authenticator::Passport, which is checked by the listeners of the ASEC::Events::CheckPassport event. Once every badge of the passport is resolved, the authenticator creates the token of the user, which is set on the token storage. The first authenticator returning a response, e.g. a redirect after logging in, ends the authentication.

The events are dispatched via the provided event dispatcher, which is typically specific to the firewall, so that its listeners only handle its authentications, e.g. ASEC::Listeners::UserProvider with its user provider.

dispatcher = AED::EventDispatcher.new
dispatcher.listener ASEC::Listeners::UserProvider.new user_provider
dispatcher.listener ASEC::Listeners::CheckCredentials.new password_hasher_factory

authenticator_manager = ASEC::Authentication::AuthenticatorManager.new(
  [APITokenAuthenticator.new] of ASEC::Authenticator::Interface,
  token_storage,
  dispatcher,
  "main",
)

Constructors#

.new(authenticators : Array(ASEC::Authenticator::Interface), token_storage : ASEC::Authentication::Token::Storage::Interface, event_dispatcher : AED::EventDispatcherInterface, firewall_name : String, expose_security_errors : ASEC::Authentication::ExposeSecurityLevel = :none)#

Creates a manager authenticating requests via the provided authenticators on the firewall with the provided firewall_name.

The token of the authenticated user is set on the provided token_storage, and the events are dispatched via the provided event_dispatcher. The expose_security_errors determine which authentication errors are passed to the authenticators, which may show them to users.

View source

Methods#

#authenticate_request(request : AHTTP::Request) : AHTTP::Response | Nil#

Authenticates the provided request via the authenticators supporting it, as determined by #supports?.

Returns the response to send, or nil to let the request continue.

View source

#supports?(request : AHTTP::Request) : Bool | Nil#

Returns true if any authenticator supports the provided request, false if none does, or nil if they all support authenticating it lazily.

The authenticators supporting the request are stored on it for #authenticate_request.

View source