Skip to content

Commit d551ee8

Browse files
Merge branch '6.4' into 7.1
* 6.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 a4af934 + cc13b60 commit d551ee8

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));
@@ -212,6 +212,8 @@ private function attemptExitUser(Request $request): TokenInterface
212212
$original = $switchEvent->getToken();
213213
}
214214

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

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;
@@ -206,7 +207,10 @@ public function testSwitchUserAlreadySwitched()
206207

207208
$targetsUser = $this->callback(fn ($user) => 'kuba' === $user->getUserIdentifier());
208209
$this->accessDecisionManager->expects($this->once())
209-
->method('decide')->with($originalToken, ['ROLE_ALLOWED_TO_SWITCH'], $targetsUser)
210+
->method('decide')->with(self::callback(function (TokenInterface $token) use ($originalToken, $tokenStorage) {
211+
// the token storage should also contain the original token for voters depending on it
212+
return $token === $originalToken && $tokenStorage->getToken() === $originalToken;
213+
}), ['ROLE_ALLOWED_TO_SWITCH'], $targetsUser)
210214
->willReturn(true);
211215

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

0 commit comments

Comments
 (0)