Symfony3 Docs WSSE fail "Cannot replace arguments if not already configured"

Thereafter

http://symfony.com/doc/current/security/custom_authentication_provider.html

Results in

Service "security.authentication.provider.wsse.wsse_secured": the arguments cannot be replaced if they are not already configured.

I can not find anything about this error. This uses the WSSE DSS code and it fails.

This repo shows that it is not working https://github.com/jakenoble/wsse_test

I want it to work eventually with the FOS User Bundle. But I can not get it to work with the basic installation of Symfony3, so the question of installing the FOS User Bundle at the moment is out of the question.

Dug up a little ...

The element index_0has an arg element Symfony\Component\DependencyInjection\ChildDefinitionfor the class; Symfony\Component\DependencyInjection\ChildDefinitionthe arg object for the element index_0has an identifier fos_user.user_provider.username_email.

Then the replace call tries to get the arguments fos_user.user_provider.username_email, but they aren't there. Then an error occurs.

Any ideas?

+4
source share
5 answers

It seems that at the moment the definition of the provider has no ready-made arguments, possibly related to the processing order of "CompilerPass", now you can solve this problem with these small settings:

change this line to WsseFactory.php:

->replaceArgument(0, new Reference($userProvider))

by:

->setArgument(0, new Reference($userProvider))

and add this alias in services.ymlto complete the auto-incrementing arguments of the new provider:

Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface: '@security.authentication.manager'
+4
source

TL; DR services.yml WsseFactory

    $container
        ->setDefinition($providerId, new ChildDefinition(WsseProvider::class))
        ->setArgument('$userProvider', new Reference($userProvider))
    ;

. , . AuthenticationManagerInterface. . - , @yceruto @gintko.

, . , , , - , .

, replaceArgument, Symfony , . PassConfig:

$this->optimizationPasses = array(array(
        new ExtensionCompilerPass(),
        new ResolveDefinitionTemplatesPass(),
        ...
        $autowirePass = new AutowirePass(false),
        ...
    ));

. security.authentication.provider.wsse.wsse_secured, WsseFactory. ResolveDefinitionTemplatesPass Cannot replace arguments, :

    foreach ($definition->getArguments() as $k => $v) {
        if (is_numeric($k)) {
            $def->addArgument($v);
        } elseif (0 === strpos($k, 'index_')) {
            $def->replaceArgument((int) substr($k, strlen('index_')), $v);
        } else {
            $def->setArgument($k, $v);
        }
    }

, Definition::replaceArgument index_0. 0 services.xml, . AutowirePass , , $cachePool.

, , :

->setArgument(0, new Reference($userProvider)); //proposed by @yceruto
->replaceArgument('$userProvider', new Reference($userProvider)); //proposed by @gintko
->setArgument('$userProvider', new Reference($userProvider)); // by me

Definition::addArgument Definition::setArgument . : - setArgument(0, ... ; - ->setArgument('$userProvider' , ->replaceArgument('$userProvider' - . !

, .

PS. .

:

AppBundle\Security\Authentication\Provider\WsseProvider:
    arguments:
        0: ''
        $cachePool: '@cache.app'
    public: false

Symfony\Component\Security\Core\User\UserProviderInterface, .

    $container
        ->setDefinition($providerId, new ChildDefinition(WsseProvider::class))
    //    ->replaceArgument(0, new Reference($userProvider))
    ;
    $container
        ->setAlias('Symfony\Component\Security\Core\User\UserProviderInterface',$userProvider)
    ;
+3

EDIT: ( - )

, FOSUserBundle, . PR.

, . (. , - PR , , , PR, ).

, :

  • src/AppBundle/Entity/User.php
  • DB php bin/console doctrine:schema:update --force
  • Security, Entity - use AppBundle\Entity\User;
  • . .
  • ()
  • , Custom Query to Load the User

Entity, FOSUserBundle.

0

EDIT:

, , ChildDefinition:100 , $name, , , .

WsseFactory.php

->replaceArgument(0, new Reference($userProvider));

:

->replaceArgument('$userProvider', new Reference($userProvider));

, , autwire $authenticationManager WsseListener. , services.yml:

Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface: '@security.authentication.manager'

, autowire, , .

:

services.yml:

app.security.wsse_provider:
    class: AppBundle\Security\Authentication\Provider\WsseProvider
        arguments:
            - ''
            - '@cache.app'
        public: false

app.security.wsse_listener:
    class: AppBundle\Security\Firewall\WsseListener
    arguments: ['@security.token_storage', '@security.authentication.manager']
    public: false

WsseFactory.php, :

new ChildDefinition(WsseFactory::class);
new ChildDefinition(WsseListener::class);

:

new ChildDefinition('app.security.wsse_provider');
new ChildDefinition('app.security.wsse_listener');

a >

0
source

The problem seems to be that my configuration in services.yml appeared before new materials for automatic wiring.

Thus, a simple movement under the automatic wiring corrects it.

0
source

Source: https://habr.com/ru/post/1686224/


All Articles