Skip to content

Commit

Permalink
[DoctrineBridge] Throw AuthenticationException if the user entity can…
Browse files Browse the repository at this point in the history
…not be fetched at all
  • Loading branch information
fancyweb committed Mar 26, 2020
1 parent a29ee7c commit a874f45
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a874f45

Please sign in to comment.