[Security] Introduced UsernameNotFoundException#get/setUsername
This commit is contained in:
parent
39da27a06d
commit
50d5724c23
@ -37,4 +37,5 @@ CHANGELOG
|
||||
* [BC BREAK] The constructor of `AuthenticationException` and all child
|
||||
classes now matches the constructor of `\Exception`. The extra information
|
||||
getters and setters are removed. There are now dedicated getters/setters for
|
||||
token (`AuthenticationException') and user (`AccountStatusException`).
|
||||
token (`AuthenticationException'), user (`AccountStatusException`) and
|
||||
username (`UsernameNotFoundException`).
|
||||
|
@ -88,6 +88,7 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider
|
||||
|
||||
return $user;
|
||||
} catch (UsernameNotFoundException $notFound) {
|
||||
$notFound->setUsername($username);
|
||||
throw $notFound;
|
||||
} catch (\Exception $repositoryProblem) {
|
||||
$ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
|
||||
|
@ -71,6 +71,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
|
||||
if ($this->hideUserNotFoundExceptions) {
|
||||
throw new BadCredentialsException('Bad credentials', 0, $notFound);
|
||||
}
|
||||
$notFound->setUsername($username);
|
||||
|
||||
throw $notFound;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace Symfony\Component\Security\Core\Exception;
|
||||
*/
|
||||
class UsernameNotFoundException extends AuthenticationException
|
||||
{
|
||||
private $username;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -26,4 +28,24 @@ class UsernameNotFoundException extends AuthenticationException
|
||||
{
|
||||
return 'security.exception.username_not_found_exception';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the username.
|
||||
*
|
||||
* @param string $username
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,9 @@ class ChainUserProvider implements UserProviderInterface
|
||||
}
|
||||
}
|
||||
|
||||
throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $username));
|
||||
$ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $username));
|
||||
$ex->setUsername($username);
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +68,9 @@ class ChainUserProvider implements UserProviderInterface
|
||||
}
|
||||
|
||||
if ($supportedUserFound) {
|
||||
throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
|
||||
$ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
|
||||
$ex->setUsername($user->getUsername());
|
||||
throw $ex;
|
||||
} else {
|
||||
throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user)));
|
||||
}
|
||||
|
@ -68,7 +68,10 @@ class InMemoryUserProvider implements UserProviderInterface
|
||||
public function loadUserByUsername($username)
|
||||
{
|
||||
if (!isset($this->users[strtolower($username)])) {
|
||||
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
|
||||
$ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
|
||||
$ex->setUsername($username);
|
||||
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
$user = $this->users[strtolower($username)];
|
||||
|
Reference in New Issue
Block a user