我正在symfony2中进行wsse身份验证。 T完美地跟着他们的步骤,然后我在helloWorld函数上尝试它:
public function HelloWorldAction()
{
return new Response("Hello World");
}
它的路线: http://localhost/Symfony/web/app_dev.php/api/helloworld
但是我收到了这个错误:
ServiceCircularReferenceException in CheckCircularReferencesPass.php line 69:
Circular reference detected for service "security.authentication.manager", path: "security.authentication.manager -> security.authentication.provider.wsse.wsse_secured -> security.authentication.manager".
我已经仔细检查了我的services.yml文件是否有任何错误,我一直在网上搜索4小时以获得答案,但我仍然卡住了。
这个包的services.yml:
services:
wsse.security.authentication.provider:
class: OBCarsTest2Bundle\Security\Authentication\Provider\WsseProvider
arguments: ["", "%kernel.cache_dir%/security/nonces"]
parent: security.authentication.listener.abstract #this key is defined in security_listeners.xml
abstract: true
wsse.security.authentication.listener:
class: OBCarsTest2Bundle\Security\Firewall\WsseListener
arguments: ["@security.token_storage", "@security.authentication.manager"]
security.authentication.factory.wsse:
class: OBCarsTest2Bundle\DependencyInjection\Security\Factory\WsseFactory
tags:
- { name: security.listener.factory }
那是我的工厂:
<?php
namespace OBCarsTest2Bundle\DependencyInjection\Security\Factory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
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))
->replaceArgument(2, $config['lifetime']);
$listenerId = 'security.authentication.listener.wsse.'.$id;
$listener = $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)
{
$node
->children()
->scalarNode('lifetime')->defaultValue(300)
->end();
}
}
答案 0 :(得分:1)
尝试通过setter注入wsse.security.authentication.provider。
在你的WsseProvider中编写一个setUserProvider并按构造函数删除注入。
在你的WsseFactory中:
$container
->setDefinition($providerId,
new DefinitionDecorator('wsse.security.authentication.provider'))
->replaceArgument(0, $config['lifetime'])
->addMethodCall('setUserProvider', array(new Reference($userProvider)));