我正在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: OBCarsTest2BundleSecurityAuthenticationProviderWsseProvider
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: OBCarsTest2BundleSecurityFirewallWsseListener
arguments: ["@security.token_storage", "@security.authentication.manager"]
security.authentication.factory.wsse:
class: OBCarsTest2BundleDependencyInjectionSecurityFactoryWsseFactory
tags:
- { name: security.listener.factory }
那是我的wsse工厂:
<?php
namespace OBCarsTest2BundleDependencyInjectionSecurityFactory;
use SymfonyComponentDependencyInjectionContainerBuilder;
use SymfonyComponentDependencyInjectionContainerInterface;
use SymfonyComponentDependencyInjectionReference;
use SymfonyComponentDependencyInjectionDefinitionDecorator;
use SymfonyComponentConfigDefinitionBuilderNodeDefinition;
use SymfonyBundleSecurityBundleDependencyInjectionSecurityFactorySecurityFactoryInterface;
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();
}
}
尝试通过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)));