我根据以下内容创建了自己的身份验证:http ://symfony.com/doc/2.0/cookbook/security/custom_authentication_provider.html ,效果很好。
但是现在我需要有两个身份验证提供程序。AuthenticationProviderManager 支持这一点,但我不知道如何将第二个身份验证提供程序添加到我的安全工厂。
我的代码:
安全.yml
firewalls:
wsse_secured:
pattern: /api/.*
wsse: true
WsseFactory.php
class WsseFactory implements SecurityFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
$providerId = 'security.authentication.provider.wsse.'.$id;
$container
->setDefinition(
$providerId,
new DefinitionDecorator(
'wsse.security.authentication.provider'
)
)
->replaceArgument(
0,
new Reference($userProvider)
);
$listenerId = 'security.authentication.listener.wsse.'.$id;
$container->setDefinition(
$listenerId,
new DefinitionDecorator(
'wsse.security.authentication.listener'
)
);
return array($providerId, $listenerId, $defaultEntryPoint);
}
public function getPosition()
{
return 'pre_auth';
}
public function getKey()
{
return 'wsse';
}
public function addConfiguration(NodeDefinition $node)
{
}
}
服务.yml:
wsse.security.authentication.provider:
class: LD\BinaryBackendBundle\Security\Authentication\Provider\WsseProvider
arguments: ['', %kernel.cache_dir%/security/nonces]
wsse.security.authentication.listener:
class: LD\BinaryBackendBundle\Security\Firewall\WsseListener
arguments: [@security.context, @security.authentication.manager, @logger]
如您所见,我有一个身份验证提供程序注册。如何添加第二个?