Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdae16c

Browse files
committed
[Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken
If you configure a firewall with switch user with `role: IS_AUTHENTICATED_ANONYMOUSLY` it's impossible to exit the impersonation because the next line `$this->provider->refreshUser($original->getUser())` will fail. It fails because `RefreshUser`expects an instance of `UserInterface` and here it's a string.Therefore, it does not make sense to refresh an Anonymous Token, right ?
1 parent1314365 commitcdae16c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

‎src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\HttpFoundation\RedirectResponse;
2323
useSymfony\Component\HttpFoundation\Request;
2424
useSymfony\Component\Security\Core\Role\SwitchUserRole;
25+
useSymfony\Component\Security\Core\Authentication\Token\AnonymousToken;
2526
useSymfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
2627
useSymfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
2728
useSymfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -162,7 +163,7 @@ private function attemptExitUser(Request $request)
162163
thrownewAuthenticationCredentialsNotFoundException('Could not find original Token object.');
163164
}
164165

165-
if (null !==$this->dispatcher) {
166+
if (null !==$this->dispatcher && !$originalinstanceof AnonymousToken) {
166167
$user =$this->provider->refreshUser($original->getUser());
167168
$switchEvent =newSwitchUserEvent($request,$user);
168169
$this->dispatcher->dispatch(SecurityEvents::SWITCH_USER,$switchEvent);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp