File tree 2 files changed +8
-2
lines changed
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)
109
109
}
110
110
111
111
if (self ::EXIT_VALUE === $ username ) {
112
- $ this ->tokenStorage -> setToken ( $ this -> attemptExitUser ($ request) );
112
+ $ this ->attemptExitUser ($ request );
113
113
} else {
114
114
try {
115
115
$ this ->tokenStorage ->setToken ($ this ->attemptSwitchUser ($ request , $ username ));
@@ -221,6 +221,8 @@ private function attemptExitUser(Request $request): TokenInterface
221
221
$ original = $ switchEvent ->getToken ();
222
222
}
223
223
224
+ $ this ->tokenStorage ->setToken ($ original );
225
+
224
226
return $ original ;
225
227
}
226
228
Original file line number Diff line number Diff line change 18
18
use Symfony \Component \HttpKernel \HttpKernelInterface ;
19
19
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorage ;
20
20
use Symfony \Component \Security \Core \Authentication \Token \SwitchUserToken ;
21
+ use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
21
22
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
22
23
use Symfony \Component \Security \Core \Authorization \AccessDecisionManagerInterface ;
23
24
use Symfony \Component \Security \Core \Exception \AccessDeniedException ;
@@ -228,7 +229,10 @@ public function testSwitchUserAlreadySwitched()
228
229
229
230
$ targetsUser = $ this ->callback (function ($ user ) { return 'kuba ' === $ user ->getUserIdentifier (); });
230
231
$ 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 )
232
236
->willReturn (true );
233
237
234
238
$ this ->userChecker ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments