Skip to content

Commit dd89ea6

Browse files
Merge branch '7.1' into 7.2
* 7.1: 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 re-add missing profiler shortcuts on profiler homepage Fix support for \SplTempFileObject in BinaryFileResponse [Security] Store original token in token storage when implicitly exiting impersonation [Cache] Fix clear() when using Predis
2 parents aa7d9d8 + d551ee8 commit dd89ea6

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
@@ -97,7 +97,7 @@ public function authenticate(RequestEvent $event): void
9797
}
9898

9999
if (self::EXIT_VALUE === $username) {
100-
$this->tokenStorage->setToken($this->attemptExitUser($request));
100+
$this->attemptExitUser($request);
101101
} else {
102102
try {
103103
$this->tokenStorage->setToken($this->attemptSwitchUser($request, $username));
@@ -198,6 +198,8 @@ private function attemptExitUser(Request $request): TokenInterface
198198
$original = $switchEvent->getToken();
199199
}
200200

201+
$this->tokenStorage->setToken($original);
202+
201203
return $original;
202204
}
203205

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)