Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecurityBundle] Fix the session listener registration under the new authentication manager #37126

Merged
merged 1 commit into from Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -168,14 +168,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->getDefinition('security.authentication.guard_handler')
->replaceArgument(2, $this->statelessFirewallKeys);

if ($this->authenticatorManagerEnabled) {
foreach ($this->statelessFirewallKeys as $statelessFirewallId) {
$container
->setDefinition('security.listener.session.'.$statelessFirewallId, new ChildDefinition('security.listener.session'))
->addTag('kernel.event_subscriber', ['dispatcher' => 'security.event_dispatcher.'.$statelessFirewallId]);
}
}

if ($config['encoders']) {
$this->createEncoders($config['encoders'], $container);
}
Expand Down Expand Up @@ -373,6 +365,12 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
$contextKey = $firewall['context'] ?? $id;
$listeners[] = new Reference($contextListenerId = $this->createContextListener($container, $contextKey));
$sessionStrategyId = 'security.authentication.session_strategy';

if ($this->authenticatorManagerEnabled) {
$container
->setDefinition('security.listener.session.'.$id, new ChildDefinition('security.listener.session'))
->addTag('kernel.event_subscriber', ['dispatcher' => $firewallEventDispatcherId]);
}
} else {
$this->statelessFirewallKeys[] = $id;
$sessionStrategyId = 'security.authentication.session_strategy_noop';
Expand Down
Expand Up @@ -63,7 +63,6 @@
class="Symfony\Component\Security\Http\EventListener\SessionStrategyListener"
abstract="true">
Copy link
Member

@wouterj wouterj Jun 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this abstract="true" must be kept (the service itself should not be used, only the ones created based on this in the SecurityExtension)

<argument type="service" id="security.authentication.session_strategy" />
<argument type="abstract">stateless firewall keys</argument>
</service>

<service id="security.listener.remember_me"
Expand Down
Expand Up @@ -559,6 +559,48 @@ public function provideConfigureCustomAuthenticatorData()
];
}

public function testCompilesWithoutSessionListenerWithStatelessFirewallWithAuthenticationManager()
{
$container = $this->getRawContainer();

$firewallId = 'stateless_firewall';
$container->loadFromExtension('security', [
'enable_authenticator_manager' => true,
'firewalls' => [
$firewallId => [
'pattern' => '/.*',
'stateless' => true,
'http_basic' => null,
],
],
]);

$container->compile();

$this->assertFalse($container->has('security.listener.session.'.$firewallId));
}

public function testCompilesWithSessionListenerWithStatefulllFirewallWithAuthenticationManager()
{
$container = $this->getRawContainer();

$firewallId = 'statefull_firewall';
$container->loadFromExtension('security', [
'enable_authenticator_manager' => true,
'firewalls' => [
$firewallId => [
'pattern' => '/.*',
'stateless' => false,
'http_basic' => null,
],
],
]);

$container->compile();

$this->assertTrue($container->has('security.listener.session.'.$firewallId));
}

protected function getRawContainer()
{
$container = new ContainerBuilder();
Expand Down