ServiceCircularReferenceException in CheckCircularReferencesPass.php

1.3k views Asked by At

I am working on wsse authentication in symfony2. T followed their steps perfectly, then I was trying it on a helloWorld function:

public function HelloWorldAction()
{
    return new Response("Hello World");
}

it's route: http://localhost/Symfony/web/app_dev.php/api/helloworld

but I am getting this error:

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".

I have double checked my services.yml file for any mistakes and I have been searching the web for 4h to get an answer but I am still stuck.

This the services.yml of the bundle:

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 }

and that is my wsse 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();
    }
}
1

There are 1 answers

1
Bang On

Try to inject the wsse.security.authentication.provider by setter.

In your WsseProvider write a setUserProvider and remove injection by constructor.

In your WsseFactory :

$container
        ->setDefinition($providerId,
          new DefinitionDecorator('wsse.security.authentication.provider'))
        ->replaceArgument(0, $config['lifetime'])
        ->addMethodCall('setUserProvider', array(new Reference($userProvider)));