Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit d004888

Browse files
committed
Merge branch '4.2'
* 4.2: (25 commits) Add missing ID_id validators translation fixed CS Added missing translations in validators.tr.xlf Update validators.es.xlf Update validators.hu.xlf [Validator] Add the missing translations for the Welsh (cy) locale [Validator] Add missing DE validator translations [Validator] Add the missing translations for the Dutch (nl) locale Add missing PL translation Add missing translations. Add missing translations for IT to Validator minor #30184 [Validator] Add the missing translations for the Russian (ru) locale (antonch1989) [Validator] Add the missing translations for the Arabic (ar) locale add_missing_translations_for_portuguese : [Validator] Add the missing translations for the Portuguese ("pt") locale [Validator] Add the missing translations for the French (fr) locale [Validator] Add some missing contents to the English translation use PropertyAccessorInterface instead of PropertyAccessor Fix KernelTestCase compatibility for PhpUnit 8 (bis) add xabbuh as code owner of the Form component [Validator] Added a missing translation ...
2 parents 2596524 + 361378c commit d004888

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Http/Firewall/SwitchUserListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public function handle(GetResponseEvent $event)
8383
return;
8484
}
8585

86+
if (null === $this->tokenStorage->getToken()) {
87+
throw new AuthenticationCredentialsNotFoundException('Could not find original Token object.');
88+
}
89+
8690
if (self::EXIT_VALUE === $username) {
8791
$this->tokenStorage->setToken($this->attemptExitUser($request));
8892
} else {
@@ -165,7 +169,7 @@ private function attemptSwitchUser(Request $request, $username)
165169
*/
166170
private function attemptExitUser(Request $request)
167171
{
168-
if (null === ($currentToken = $this->tokenStorage->getToken()) || false === $original = $this->getOriginalToken($currentToken)) {
172+
if (false === $original = $this->getOriginalToken($this->tokenStorage->getToken())) {
169173
throw new AuthenticationCredentialsNotFoundException('Could not find original Token object.');
170174
}
171175

Http/Tests/Firewall/SwitchUserListenerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ public function testSwitchUserWithReplacedToken()
267267
$this->assertSame($replacedToken, $this->tokenStorage->getToken());
268268
}
269269

270+
/**
271+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
272+
*/
273+
public function testSwitchtUserThrowsAuthenticationExceptionIfNoCurrentToken()
274+
{
275+
$this->tokenStorage->setToken(null);
276+
$this->request->query->set('_switch_user', 'username');
277+
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
278+
$listener->handle($this->event);
279+
}
280+
270281
public function testSwitchUserStateless()
271282
{
272283
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_FOO']);

0 commit comments

Comments
 (0)