-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fix for issue 1798 #2528
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
Fix for issue 1798 #2528
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 |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface; | ||
use Symfony\Component\Security\Core\SecurityContextInterface; | ||
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; | ||
use Symfony\Component\Security\Core\Exception\AccountStatusException; | ||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException; | ||
|
@@ -158,6 +160,12 @@ private function startAuthentication(Request $request, AuthenticationException $ | |
|
||
$this->setTargetPath($request); | ||
|
||
if ($authException instanceof AccountStatusException && ($token = $this->context->getToken()) instanceof UsernamePasswordToken) { | ||
// remove the security token to prevent infinite redirect loops | ||
$this->context->setToken(null); | ||
$request->getSession()->remove('_security_' . $token->getProviderKey()); | ||
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. The session is not always enabled. That should be checked first. 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. I believe the issue can only occur if the session is enabled, else the AccountStatusException would not be thrown. Should we still check for it? |
||
} | ||
|
||
return $this->authenticationEntryPoint->start($request, $authException); | ||
} | ||
|
||
|
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.
Why restricting this behavior to
UsernamePasswordToken
tokens?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.
That's because the issue should only occur if the firewall tries to reload the user and this can only be done if there is a username.
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.
@snc all token contain a user and all listeners reload the user (a listener not doing it would be an issue if an admin locked the user for instance, and thus it would be a detached Doctrine entity causing many WTF).
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.
@stof I rechecked why I used
UsernamePasswordToken
, it is the parent class which contains theproviderKey
which is needed to get the name of the session variable.