我创建了自定义身份验证。但由于我不知道的原因,有两个活动的身份验证侦听器。因此身份验证提供程序管理器被称为 Twice。
FirstyAuthListener
被调用,它运行 muAuthenticationProviderManager
返回正确的 Token。然后UsernamePasswordFormAuthenticationListener
被称为AuthenticationProviderManager
再次运行。它返回“错误凭据”。
我怎样才能“禁用” UsernamePasswordFormAuthenticationListener
?所以只有我的自定义监听器被调用?
安全:
providers:
api:
id: api_user_provider
firewalls:
secured_area:
pattern: ^/
user: true
form_login:
login_path: /login
check_path: /check_login
logout: ~
服务:
api_user_provider:
class: Ad\FrontendBundle\Security\User\UserProvider
arguments: ["@service_container"]
user.security.authentication.provider:
class: Ad\FrontendBundle\Security\Authentication\Provider\AuthProvider
arguments: ['', %kernel.cache_dir%/security/nonces]
user.security.authentication.listener:
class: Ad\FrontendBundle\Security\Firewall\AuthListener
arguments: ["@security.context", "@security.authentication.manager"]
工厂
class ApiFactory implements SecurityFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
$providerId = 'security.authentication.provider.user.'.$id;
$container
->setDefinition($providerId, new DefinitionDecorator('user.security.authentication.provider'))
->replaceArgument(0, new Reference($userProvider))
;
$listenerId = 'security.authentication.listener.user.'.$id;
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('user.security.authentication.listener'))
;
return array($providerId, $listenerId, $defaultEntryPoint);
}
public function getPosition()
{
return 'pre_auth';
}
public function getKey()
{
return 'user';
}
public function addConfiguration(NodeDefinition $node)
{}
}
class AdFrontendBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$extension = $container->getExtension('security');
$extension->addSecurityListenerFactory(new ApiFactory());
}
}