diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 1fe8a5c53a5ab..08ec051695b57 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -12,7 +12,9 @@ namespace Symfony\Bridge\Doctrine\Security\User; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry; +use Doctrine\DBAL\Exception\DriverException; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\UserInterface; @@ -51,14 +53,19 @@ public function __construct($registry, $classOrAlias, $property = null, $manager public function loadUserByUsername($username) { $repository = $this->getRepository(); - if (null !== $this->property) { - $user = $repository->findOneBy([$this->property => $username]); - } else { - if (!$repository instanceof UserLoaderInterface) { - 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))); - } - $user = $repository->loadUserByUsername($username); + try { + if (null !== $this->property) { + $user = $repository->findOneBy([$this->property => $username]); + } else { + if (!$repository instanceof UserLoaderInterface) { + 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))); + } + + $user = $repository->loadUserByUsername($username); + } + } catch (DriverException $e) { + throw new AuthenticationException('The user entity could not be fetched.', 0, $e); } if (null === $user) {