Skip to content

Commit cc13b60

Browse files
Merge branch '5.4' into 6.4
* 5.4: fix detecting anonymous exception classes on Windows and PHP 7 skip tests requiring the intl extension if it's not installed [RateLimiter] Fix DateInterval normalization [Security] Store original token in token storage when implicitly exiting impersonation [Cache] Fix clear() when using Predis
2 parents f5aa8f5 + 7152f0e commit cc13b60

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Firewall/SwitchUserListener.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function authenticate(RequestEvent $event): void
111111
}
112112

113113
if (self::EXIT_VALUE === $username) {
114-
$this->tokenStorage->setToken($this->attemptExitUser($request));
114+
$this->attemptExitUser($request);
115115
} else {
116116
try {
117117
$this->tokenStorage->setToken($this->attemptSwitchUser($request, $username));
@@ -213,6 +213,8 @@ private function attemptExitUser(Request $request): TokenInterface
213213
$original = $switchEvent->getToken();
214214
}
215215

216+
$this->tokenStorage->setToken($original);
217+
216218
return $original;
217219
}
218220

Tests/Firewall/SwitchUserListenerTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
2020
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
2121
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
22+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2223
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2324
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2425
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -198,7 +199,10 @@ public function testSwitchUserAlreadySwitched()
198199

199200
$targetsUser = $this->callback(fn ($user) => 'kuba' === $user->getUserIdentifier());
200201
$this->accessDecisionManager->expects($this->once())
201-
->method('decide')->with($originalToken, ['ROLE_ALLOWED_TO_SWITCH'], $targetsUser)
202+
->method('decide')->with(self::callback(function (TokenInterface $token) use ($originalToken, $tokenStorage) {
203+
// the token storage should also contain the original token for voters depending on it
204+
return $token === $originalToken && $tokenStorage->getToken() === $originalToken;
205+
}), ['ROLE_ALLOWED_TO_SWITCH'], $targetsUser)
202206
->willReturn(true);
203207

204208
$this->userChecker->expects($this->once())

0 commit comments

Comments
 (0)