diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 81c4a8ee6f46f..f454b9318c183 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -313,8 +313,8 @@ private function createFirewalls(array $config, ContainerBuilder $container): vo $authenticators[$name] = null; } else { $firewallAuthenticatorRefs = []; - foreach ($firewallAuthenticators as $authenticatorId) { - $firewallAuthenticatorRefs[$authenticatorId] = new Reference($authenticatorId); + foreach ($firewallAuthenticators as $originalAuthenticatorId => $managerAuthenticatorId) { + $firewallAuthenticatorRefs[$originalAuthenticatorId] = new Reference($originalAuthenticatorId); } $authenticators[$name] = ServiceLocatorTagPass::register($container, $firewallAuthenticatorRefs); } @@ -501,7 +501,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $ $configuredEntryPoint = $defaultEntryPoint; // authenticator manager - $authenticators = array_map(fn ($id) => new Reference($id), $firewallAuthenticationProviders); + $authenticators = array_map(fn ($id) => new Reference($id), $firewallAuthenticationProviders, []); $container ->setDefinition($managerId = 'security.authenticator.manager.'.$id, new ChildDefinition('security.authenticator.manager')) ->replaceArgument(0, $authenticators) @@ -625,11 +625,11 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri $authenticators = $factory->createAuthenticator($container, $id, $firewall[$key], $userProvider); if (\is_array($authenticators)) { foreach ($authenticators as $authenticator) { - $authenticationProviders[] = $authenticator; + $authenticationProviders[$authenticator] = $authenticator; $entryPoints[] = $authenticator; } } else { - $authenticationProviders[] = $authenticators; + $authenticationProviders[$authenticators] = $authenticators; $entryPoints[$key] = $authenticators; } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index c4ae38e65b2da..d0f3549ab8f09 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -924,6 +924,10 @@ public function testAuthenticatorsDecoration() $this->assertSame('debug.'.TestAuthenticator::class, (string) reset($managerAuthenticators), 'AuthenticatorManager must be injected traceable authenticators in debug mode.'); $this->assertTrue($container->hasDefinition(TestAuthenticator::class), 'Original authenticator must still exist in the container so it can be used outside of the AuthenticatorManager’s context.'); + + $securityHelperAuthenticatorLocator = $container->getDefinition($container->getDefinition('security.helper')->getArgument(1)['main']); + $this->assertArrayHasKey(TestAuthenticator::class, $authenticatorMap = $securityHelperAuthenticatorLocator->getArgument(0), 'When programmatically authenticating a user, authenticators’ name must be their original ID.'); + $this->assertSame(TestAuthenticator::class, (string) $authenticatorMap[TestAuthenticator::class]->getValues()[0], 'When programmatically authenticating a user, original authenticators must be used.'); } protected function getRawContainer()