8000 bug #34759 [SecurityBundle] Fix switch_user provider configuration ha… · symfony/symfony@e1f7b78 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1f7b78

Browse files
author
Robin Chalas
committed
bug #34759 [SecurityBundle] Fix switch_user provider configuration handling (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [SecurityBundle] Fix switch_user provider configuration handling | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - The default provider here can be null if there are multiple configured providers configured + the firewall doesn't define its provider at the root level + it is anonymous, ie: ```yaml providers: my_provider: # ... monitor_provider: # ... firewalls: main: switch_user: provider: my_provider anonymous: true # ... ``` Commits ------- 417169b [SecurityBundle] Fix switch_user provider configuration handling
2 parents 120f32c + 417169b commit e1f7b78

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ private function createExceptionListener(ContainerBuilder $container, array $con
681681
return $exceptionListenerId;
682682
}
683683

684-
private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, string $defaultProvider, bool $stateless): string
684+
private function createSwitchUserListener(ContainerBuilder $container, string $id, array $config, ?string $defaultProvider, bool $stateless): string
685685
{
686686
$userProvider = isset($config['provider']) ? $this->getUserProviderId($config['provider']) : $defaultProvider;
687687

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,30 @@ public function sessionConfigurationProvider()
390390
];
391391
}
392392

393+
public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProviderConfigured()
394+
{
395+
$container = $this->getRawContainer();
396+
$container->loadFromExtension('security', [
397+
'providers' => [
398+
'first' => ['id' => 'foo'],
399+
'second' => ['id' => 'bar'],
400+
],
401+
402+
'firewalls' => [
403+
'foobar' => [
404+
'switch_user' => [
405+
'provider' => 'second',
406+
],
407+
'anonymous' => true,
408+
],
409+
],
410+
]);
411+
412+
$container->compile();
413+
414+
$this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1));
415+
}
416+
393417
protected function getRawContainer()
394418
{
395419
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0