-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Avoid migration on stateless firewalls #27452
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | ||
use Symfony\Component\Security\Http\SecurityEvents; | ||
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface; | ||
|
||
/** | ||
* A utility class that does much of the *work* during the guard authentication process. | ||
|
@@ -32,8 +33,8 @@ | |
class GuardAuthenticatorHandler | ||
{ | ||
private $tokenStorage; | ||
|
||
private $dispatcher; | ||
private $sessionStrategy; | ||
|
||
public function __construct(TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher = null) | ||
{ | ||
|
@@ -46,7 +47,7 @@ public function __construct(TokenStorageInterface $tokenStorage, EventDispatcher | |
*/ | ||
public function authenticateWithToken(TokenInterface $token, Request $request) | ||
{ | ||
$this->migrateSession($request); | ||
$this->migrateSession($request, $token); | ||
$this->tokenStorage->setToken($token); | ||
|
||
if (null !== $this->dispatcher) { | ||
|
@@ -129,15 +130,22 @@ public function handleAuthenticationFailure(AuthenticationException $authenticat | |
)); | ||
} | ||
|
||
private function migrateSession(Request $request) | ||
/** | ||
* Call this method if your authentication token is stored to a session. | ||
* | ||
* @final since version 2.8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "since version 2.8" should be removed. I don't think we are doing that anywhere else. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do when we want to hint that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see 5c2b2bb |
||
*/ | ||
public function setSessionAuthenticationStrategy(SessionAuthenticationStrategyInterface $sessionStrategy) | ||
{ | ||
$this->sessionStrategy = $sessionStrategy; | ||
} | ||
|
||
private function migrateSession(Request $request, TokenInterface $token) | ||
{ | ||
if (!$request->hasSession() || !$request->hasPreviousSession()) { | ||
if (!$this->sessionStrategy || !$request->hasSession() || !$request->hasPreviousSession()) { | ||
return; | ||
} | ||
|
||
// Destroying the old session is broken in php 5.4.0 - 5.4.10 | ||
// See https://bugs.php.net/63379 | ||
$destroy = \PHP_VERSION_ID < 50400 || \PHP_VERSION_ID >= 50411; | ||
$request->getSession()->migrate($destroy); | ||
$this->sessionStrategy->onAuthentication($request, $token); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bumped both versions - pretty sure that's correct :)