Skip to content

Commit 3843cde

Browse files
committed
[DoctrineBridge] Throw AuthenticationException if the user entity cannot be fetched at all
1 parent a29ee7c commit 3843cde

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

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

1414
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
1515
use Doctrine\Persistence\ManagerRegistry;
16+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1617
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1718
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1819
use Symfony\Component\Security\Core\User\UserInterface;
@@ -51,14 +52,19 @@ public function __construct($registry, $classOrAlias, $property = null, $manager
5152
public function loadUserByUsername($username)
5253
{
5354
$repository = $this->getRepository();
54-
if (null !== $this->property) {
55-
$user = $repository->findOneBy([$this->property => $username]);
56-
} else {
57-
if (!$repository instanceof UserLoaderInterface) {
58-
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, \get_class($repository)));
59-
}
6055

61-
$user = $repository->loadUserByUsername($username);
56+
try {
57+
if (null !== $this->property) {
58+
$user = $repository->findOneBy([$this->property => $username]);
59+
} else {
60+
if (!$repository instanceof UserLoaderInterface) {
61+
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, \get_class($repository)));
62+
}
63+
64+
$user = $repository->loadUserByUsername($username);
65+
}
66+
} catch (\Exception $e) {
67+
throw new AuthenticationException('The user entity could not be fetched.', 0, $e);
6268
}
6369

6470
if (null === $user) {

0 commit comments

Comments
 (0)