1
votes

I'd like to use 2 simple_preauth Authenticators, one should be a fallback. That works when using several Authenticators of different type:

http://symfony.com/blog/new-in-symfony-2-4-customize-the-security-features-with-ease#using-several-authenticators-in-a-firewall

Also supportsToken() is implemented for that purpose: http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#supportstoken

Am I missing something or what's the recommended way to add 2 simple_preauth Authenticators to a firewall where the 2nd is the fallback of the 1st? Or is it only possible if I implement one of them as custom Authenticator (http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html)?

1

1 Answers

1
votes

You did not miss something - you can define an only 1 simple_preauth authenticator per a firewall.

But you have the fallback option for the authenticator: if the authenticator implements AuthenticationFailureInterface then on AuthenticationException will be called its onAuthenticationFailure method.

http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#handling-authentication-failure https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php#L94

Also you are free to try several authentication ways into authenticator::createToken(). Just don't forget to differentiate them into authenticator::authenticateToken() and authenticateToken::refreshToken() (if stateless: false).

You are able to extend simple_preauth behavior with Custom Authentication Provider but this is most complicated way. It can be several Custom Authentication Providers with overrided SimplePreAuthenticationFactory key and services suffices. Or it can be truly multiple simple_preauth implements Chain pattern for its Listener and Provider. e.g.

class MultipleSimplePreAuthenticationListener implements ListenerInterface
{
    ...
    public function handle(GetResponseEvent $event)
    {
        foreach ($this->listeners as $listener) {
            $listener->handle($event)
        }
        ...