summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--Core/Authentication/Provider/DaoAuthenticationProvider.php1
-rw-r--r--Core/Authentication/Provider/UserAuthenticationProvider.php1
-rw-r--r--Core/Exception/UsernameNotFoundException.php22
-rw-r--r--Core/User/ChainUserProvider.php8
-rw-r--r--Core/User/InMemoryUserProvider.php5
6 files changed, 36 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d897fc3..83914b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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`).
diff --git a/Core/Authentication/Provider/DaoAuthenticationProvider.php b/Core/Authentication/Provider/DaoAuthenticationProvider.php
index 8647382..a9a2205 100644
--- a/Core/Authentication/Provider/DaoAuthenticationProvider.php
+++ b/Core/Authentication/Provider/DaoAuthenticationProvider.php
@@ -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);
diff --git a/Core/Authentication/Provider/UserAuthenticationProvider.php b/Core/Authentication/Provider/UserAuthenticationProvider.php
index ed8f499..626f50b 100644
--- a/Core/Authentication/Provider/UserAuthenticationProvider.php
+++ b/Core/Authentication/Provider/UserAuthenticationProvider.php
@@ -71,6 +71,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
if ($this->hideUserNotFoundExceptions) {
throw new BadCredentialsException('Bad credentials', 0, $notFound);
}
+ $notFound->setUsername($username);
throw $notFound;
}
diff --git a/Core/Exception/UsernameNotFoundException.php b/Core/Exception/UsernameNotFoundException.php
index 2dc5534..421fada 100644
--- a/Core/Exception/UsernameNotFoundException.php
+++ b/Core/Exception/UsernameNotFoundException.php
@@ -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;
+ }
}
diff --git a/Core/User/ChainUserProvider.php b/Core/User/ChainUserProvider.php
index 376ba1c..3ff1ea9 100644
--- a/Core/User/ChainUserProvider.php
+++ b/Core/User/ChainUserProvider.php
@@ -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)));
}
diff --git a/Core/User/InMemoryUserProvider.php b/Core/User/InMemoryUserProvider.php
index bd74804..e87f80c 100644
--- a/Core/User/InMemoryUserProvider.php
+++ b/Core/User/InMemoryUserProvider.php
@@ -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)];