class AuthenticationManager implements AuthenticationProviderInterface, AuthenticationProviderFilterInterface, AuthenticationProviderChallengeInterface (View source)

Manager for authentication.

On each request, let all authentication providers try to authenticate the user. The providers are iterated according to their priority and the first provider detecting credentials for its method wins. No further provider will get triggered.

If no provider sets an active user then the user remains anonymous.

Properties

protected AuthenticationCollectorInterface $authCollector

The authentication provider collector.

Methods

__construct(AuthenticationCollectorInterface $auth_collector)

Creates a new authentication manager instance.

bool
applies(Request $request)

Checks whether suitable authentication credentials are on the request.

authenticate(Request $request)

Authenticates the user.

bool
appliesToRoutedRequest(Request $request, bool $authenticated)

Checks whether the authentication method is allowed on a given route.

HttpExceptionInterface|null
challengeException(Request $request, Exception $previous)

Constructs an exception which is used to generate the challenge.

string|null
getProvider(Request $request)

Returns the id of the authentication provider for a request.

string|null
getChallenger(Request $request)

Returns the ID of the challenge provider for a request.

bool
applyFilter(Request $request, bool $authenticated, string $provider_id)

Checks whether a provider is allowed on the given request.

bool
defaultFilter(Request $request, string $provider_id)

Default implementation of the provider filter.

Details

__construct(AuthenticationCollectorInterface $auth_collector)

Creates a new authentication manager instance.

Parameters

AuthenticationCollectorInterface $auth_collector

The authentication provider collector.

bool applies(Request $request)

Checks whether suitable authentication credentials are on the request.

Parameters

Request $request

The request object.

Return Value

bool

TRUE if authentication credentials suitable for this provider are on the request, FALSE otherwise.

AccountInterface|null authenticate(Request $request)

Authenticates the user.

Parameters

Request $request

The request object.

Return Value

AccountInterface|null

AccountInterface - in case of a successful authentication. NULL - in case where authentication failed.

bool appliesToRoutedRequest(Request $request, bool $authenticated)

Checks whether the authentication method is allowed on a given route.

While authentication itself is run before routing, this method is called after routing, hence RouteMatch is available and can be used to inspect route options.

Parameters

Request $request

The request.

bool $authenticated

Whether or not the request is authenticated.

Return Value

bool

TRUE if an authentication method is allowed on the request, otherwise FALSE.

HttpExceptionInterface|null challengeException(Request $request, Exception $previous)

Constructs an exception which is used to generate the challenge.

Parameters

Request $request

The request.

Exception $previous

The previous exception.

Return Value

HttpExceptionInterface|null

An exception to be used in order to generate an authentication challenge.

protected string|null getProvider(Request $request)

Returns the id of the authentication provider for a request.

Parameters

Request $request

The incoming request.

Return Value

string|null

The id of the first authentication provider which applies to the request. If no application detects appropriate credentials, then NULL is returned.

protected string|null getChallenger(Request $request)

Returns the ID of the challenge provider for a request.

Parameters

Request $request

The incoming request.

Return Value

string|null

The ID of the first authentication provider which applies to the request. If no application detects appropriate credentials, then NULL is returned.

protected bool applyFilter(Request $request, bool $authenticated, string $provider_id)

Checks whether a provider is allowed on the given request.

If no filter is registered for the given provider id, the default filter is applied.

Parameters

Request $request

The incoming request.

bool $authenticated

Whether or not the request is authenticated.

string $provider_id

The id of the authentication provider to check access for.

Return Value

bool

TRUE if provider is allowed, FALSE otherwise.

protected bool defaultFilter(Request $request, string $provider_id)

Default implementation of the provider filter.

Checks whether a provider is allowed as per the _auth option on a route. If the option is not set or if the request did not match any route, only providers from the global provider set are allowed.

If no filter is registered for the given provider id, the default filter is applied.

Parameters

Request $request

The incoming request.

string $provider_id

The id of the authentication provider to check access for.

Return Value

bool

TRUE if provider is allowed, FALSE otherwise.