Skip to content

Commit 79151d6

Browse files
xabbuhfabpot
authored andcommitted
migrate session after remember me authentication
1 parent 06ffb22 commit 79151d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Firewall/RememberMeListener.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
2121
use Symfony\Component\Security\Http\SecurityEvents;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23+
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
2324

2425
/**
2526
* RememberMeListener implements authentication capabilities via a cookie.
@@ -33,6 +34,7 @@ class RememberMeListener implements ListenerInterface
3334
private $authenticationManager;
3435
private $logger;
3536
private $dispatcher;
37+
private $sessionStrategy;
3638

3739
/**
3840
* Constructor.
@@ -50,6 +52,7 @@ public function __construct(SecurityContextInterface $securityContext, RememberM
5052
$this->authenticationManager = $authenticationManager;
5153
$this->logger = $logger;
5254
$this->dispatcher = $dispatcher;
55+
$this->sessionStrategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
5356
}
5457

5558
/**
@@ -70,6 +73,11 @@ public function handle(GetResponseEvent $event)
7073

7174
try {
7275
$token = $this->authenticationManager->authenticate($token);
76+
77+
if ($request->hasSession() && $request->getSession()->isStarted()) {
78+
$this->sessionStrategy->onAuthentication($request, $token);
79+
}
80+
7381
$this->securityContext->setToken($token);
7482

7583
if (null !== $this->dispatcher) {

0 commit comments

Comments
 (0)