2014-11-21 61 views
1

我想使用2个simple_preauth Authenticators,其中一个应该是备用。在Symfony中使用几个相同类型的Authenticators

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

而且supportsToken()被用于这一目的实现的: http://symfony.com/doc/current/cookbook/security/api_key_authentication.html#supportstoken

我缺少的东西,或有什么推荐的方法2个simple_preauth验证器添加到当使用不同类型的几个验证器的工作原理第二个是第一个后备的防火墙?或者仅当我将其中一个实现为自定义身份验证器(http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html)时才有可能?

回答

1

您没有错过任何东西 - 您可以为每个防火墙定义一个唯一的1 simple_preauth身份验证器。

但是你有认证者的后备选择:如果认证者执行AuthenticationFailureInterface那么在AuthenticationException将被称为其onAuthenticationFailure方法。

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

你也可以自由地尝试几种认证方式为authenticator::createToken()。请不要忘记将它们区分为authenticator::authenticateToken()和​​3210(如果是stateless: false)。

您可以使用自定义身份验证提供程序来扩展simple_preauth行为,但这是最复杂的方式。它可以是几个自定义身份验证提供程序,其中密钥和服务已满足SimplePreAuthenticationFactory。或者它可以是真正的多个simple_preauth为其监听器和提供者实现链模式。例如

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

最简单的方法是将两者整合到一个验证器中,谢谢! – ak2 2014-11-25 15:57:36

相关问题