Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9befb6

Browse files
committed
Remove only the security token instead of the session cookie.
1 parent 348bccb commit f9befb6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
1616
use Symfony\Component\Security\Core\SecurityContextInterface;
1717
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
18+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1819
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
1920
use Symfony\Component\Security\Core\Exception\AccountStatusException;
2021
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -159,15 +160,13 @@ private function startAuthentication(Request $request, AuthenticationException $
159160

160161
$this->setTargetPath($request);
161162

162-
$response = $this->authenticationEntryPoint->start($request, $authException);
163-
164-
if ($authException instanceof AccountStatusException && $response instanceof Response) {
165-
// clear the session cookie to prevent infinite redirect loops
166-
$cookieParams = session_get_cookie_params();
167-
$response->headers->clearCookie(session_name(), $cookieParams['path'], $cookieParams['domain']);
163+
if ($authException instanceof AccountStatusException && ($token = $this->context->getToken()) instanceof UsernamePasswordToken) {
164+
// remove the security token to prevent infinite redirect loops
165+
$this->context->setToken(null);
166+
$request->getSession()->remove('_security_' . $token->getProviderKey());
168167
}
169168

170-
return $response;
169+
return $this->authenticationEntryPoint->start($request, $authException);
171170
}
172171

173172
protected function setTargetPath(Request $request)

0 commit comments

Comments
 (0)