File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public function authenticate(RequestEvent $event)
109109 }
110110
111111 if (self ::EXIT_VALUE === $ username ) {
112- $ this ->tokenStorage -> setToken ( $ this -> attemptExitUser ($ request) );
112+ $ this ->attemptExitUser ($ request );
113113 } else {
114114 try {
115115 $ this ->tokenStorage ->setToken ($ this ->attemptSwitchUser ($ request , $ username ));
@@ -221,6 +221,8 @@ private function attemptExitUser(Request $request): TokenInterface
221221 $ original = $ switchEvent ->getToken ();
222222 }
223223
224+ $ this ->tokenStorage ->setToken ($ original );
225+
224226 return $ original ;
225227 }
226228
Original file line number Diff line number Diff line change 1818use Symfony \Component \HttpKernel \HttpKernelInterface ;
1919use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
2020use Symfony \Component \Security \Core \Authentication \Token \SwitchUserToken ;
21+ use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
2122use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
2223use Symfony \Component \Security \Core \Authorization \AccessDecisionManagerInterface ;
2324use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
@@ -228,7 +229,10 @@ public function testSwitchUserAlreadySwitched()
228229
229230 $ targetsUser = $ this ->callback (function ($ user ) { return 'kuba ' === $ user ->getUserIdentifier (); });
230231 $ this ->accessDecisionManager ->expects ($ this ->once ())
231- ->method ('decide ' )->with ($ originalToken , ['ROLE_ALLOWED_TO_SWITCH ' ], $ targetsUser )
232+ ->method ('decide ' )->with (self ::callback (function (TokenInterface $ token ) use ($ originalToken , $ tokenStorage ) {
233+ // the token storage should also contain the original token for voters depending on it
234+ return $ token === $ originalToken && $ tokenStorage ->getToken () === $ originalToken ;
235+ }), ['ROLE_ALLOWED_TO_SWITCH ' ], $ targetsUser )
232236 ->willReturn (true );
233237
234238 $ this ->userChecker ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments