|
13 | 13 |
|
14 | 14 | use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
|
15 | 15 | use Doctrine\Persistence\ManagerRegistry;
|
| 16 | +use Symfony\Component\Security\Core\Exception\AuthenticationException; |
16 | 17 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
17 | 18 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
18 | 19 | use Symfony\Component\Security\Core\User\UserInterface;
|
@@ -51,14 +52,19 @@ public function __construct($registry, $classOrAlias, $property = null, $manager
|
51 | 52 | public function loadUserByUsername($username)
|
52 | 53 | {
|
53 | 54 | $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 |
| - } |
60 | 55 |
|
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); |
62 | 68 | }
|
63 | 69 |
|
64 | 70 | if (null === $user) {
|
|
0 commit comments