Skip to content

Commit b923e4c

Browse files
committed
Enabled remember me for the GuardManagerListener
1 parent 873b949 commit b923e4c

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,27 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
418418
// Determine default entry point
419419
$configuredEntryPoint = isset($firewall['entry_point']) ? $firewall['entry_point'] : null;
420420

421+
if ($this->guardAuthenticationManagerEnabled) {
422+
// guard authentication manager listener (must be before calling createAuthenticationListeners() to inject remember me services)
423+
$container
424+
->setDefinition('security.firewall.guard.'.$id, new ChildDefinition('security.firewall.guard'))
425+
->replaceArgument(2, new Reference('security.firewall.guard.'.$id.'.locator'))
426+
->replaceArgument(3, $id)
427+
->addTag('kernel.event_listener', ['event' => KernelEvents::REQUEST])
428+
->addTag('security.remember_me_aware', ['id' => $id, 'provider' => 'none'])
429+
;
430+
431+
$listeners[] = new Reference('security.firewall.guard.'.$id);
432+
}
433+
421434
// Authentication listeners
422435
$firewallAuthenticationProviders = [];
423436
list($authListeners, $defaultEntryPoint) = $this->createAuthenticationListeners($container, $id, $firewall, $firewallAuthenticationProviders, $defaultProvider, $providerIds, $configuredEntryPoint, $contextListenerId);
424437

425438
$authenticationProviders = array_merge($authenticationProviders, $firewallAuthenticationProviders);
426439

427440
if ($this->guardAuthenticationManagerEnabled) {
428-
// guard authentication manager listener
441+
// add authentication providers for this firewall to the GuardManagerListener (if guard is enabled)
429442
$container
430443
->setDefinition('security.firewall.guard.'.$id.'.locator', new ChildDefinition('security.firewall.guard.locator'))
431444
->setArguments([array_map(function ($id) {
@@ -434,13 +447,9 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
434447
->addTag('container.service_locator')
435448
;
436449
$container
437-
->setDefinition('security.firewall.guard.'.$id, new ChildDefinition('security.firewall.guard'))
450+
->getDefinition('security.firewall.guard.'.$id)
438451
->replaceArgument(2, new Reference('security.firewall.guard.'.$id.'.locator'))
439-
->replaceArgument(3, $id)
440-
->addTag('kernel.event_listener', ['event' => KernelEvents::REQUEST])
441452
;
442-
443-
$listeners[] = new Reference('security.firewall.guard.'.$id);
444453
}
445454

446455
$config->replaceArgument(7, $configuredEntryPoint ?: $defaultEntryPoint);

src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticatorListenerTrait.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ private function triggerRememberMe($guardAuthenticator, Request $request, TokenI
150150
throw new \UnexpectedValueException('Invalid guard authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
151151
}
152152

153-
// @todo implement remember me functionality
154-
if (!isset($this->rememberMeServices)) {
155-
return;
156-
}
157-
158153
if (null === $this->rememberMeServices) {
159154
if (null !== $this->logger) {
160155
$this->logger->debug('Remember me skipped: it is not configured for the firewall.', ['authenticator' => \get_class($guardAuthenticator)]);

src/Symfony/Component/Security/Http/Firewall/GuardManagerListener.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Security\Core\Authentication\Authenticator\AuthenticatorInterface;
1818
use Symfony\Component\Security\Guard\Firewall\GuardAuthenticatorListenerTrait;
1919
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
20+
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
2021

2122
/**
2223
* @author Wouter de Jong <[email protected]>
@@ -34,6 +35,7 @@ class GuardManagerListener
3435
private $guardAuthenticators;
3536
protected $providerKey;
3637
protected $logger;
38+
private $rememberMeServices;
3739

3840
/**
3941
* @param AuthenticatorInterface[] $guardAuthenticators
@@ -58,6 +60,11 @@ public function __invoke(RequestEvent $requestEvent)
5860
$this->executeGuardAuthenticators($guardAuthenticators, $requestEvent);
5961
}
6062

63+
public function setRememberMeServices(RememberMeServicesInterface $rememberMeServices)
64+
{
65+
$this->rememberMeServices = $rememberMeServices;
66+
}
67+
6168
protected function getGuardKey(string $key): string
6269
{
6370
// Guard authenticators in the GuardManagerListener are already indexed

0 commit comments

Comments
 (0)