Skip to content

Commit a0ec71e

Browse files
Merge branch '5.4' into 6.0
* 5.4: cs fix bug #45452 [Security] Fix UserNotFoundException is not thrown (damienfa)
2 parents 2615931 + 1bc534e commit a0ec71e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Authenticator/Passport/Badge/UserBadge.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1515
use Symfony\Component\Security\Core\Exception\AuthenticationServiceException;
16+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1617
use Symfony\Component\Security\Core\User\UserInterface;
1718
use Symfony\Component\Security\Http\EventListener\UserProviderListener;
1819

@@ -60,20 +61,29 @@ public function getUserIdentifier(): string
6061
*/
6162
public function getUser(): UserInterface
6263
{
63-
if (!isset($this->user)) {
64-
if (null === $this->userLoader) {
65-
throw new \LogicException(sprintf('No user loader is configured, did you forget to register the "%s" listener?', UserProviderListener::class));
66-
}
64+
if (null !== $this->user) {
65+
return $this->user;
66+
}
67+
68+
if (null === $this->userLoader) {
69+
throw new \LogicException(sprintf('No user loader is configured, did you forget to register the "%s" listener?', UserProviderListener::class));
70+
}
6771

68-
$user = ($this->userLoader)($this->userIdentifier);
69-
if (!$user instanceof UserInterface) {
70-
throw new AuthenticationServiceException(sprintf('The user provider must return a UserInterface object, "%s" given.', get_debug_type($this->user)));
71-
}
72+
$user = ($this->userLoader)($this->userIdentifier);
73+
74+
// No user has been found via the $this->userLoader callback
75+
if (null === $user) {
76+
$exception = new UserNotFoundException();
77+
$exception->setUserIdentifier($this->userIdentifier);
78+
79+
throw $exception;
80+
}
7281

73-
$this->user = $user;
82+
if (!$user instanceof UserInterface) {
83+
throw new AuthenticationServiceException(sprintf('The user provider must return a UserInterface object, "%s" given.', get_debug_type($user)));
7484
}
7585

76-
return $this->user;
86+
return $this->user = $user;
7787
}
7888

7989
public function getUserLoader(): ?callable

0 commit comments

Comments
 (0)