diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 115ad5cf504e0..5dd3889e8eb15 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -62,7 +62,10 @@ public function loadUserByUsername($username) } if (null === $user) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e->setUsername($username); + + throw $e; } return $user; @@ -92,7 +95,10 @@ public function refreshUser(UserInterface $user) $refreshedUser = $repository->find($id); if (null === $refreshedUser) { - throw new UsernameNotFoundException('User with id '.json_encode($id).' not found.'); + $e = new UsernameNotFoundException('User with id '.json_encode($id).' not found.'); + $e->setUsername(json_encode($id)); + + throw $e; } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php index 5b50def554a5d..fe12ea90f1469 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php @@ -34,7 +34,10 @@ public function loadUserByUsername($username) $user = $this->getUser($username); if (null === $user) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e->setUsername($username); + + throw $e; } return $user; diff --git a/src/Symfony/Component/Ldap/Security/LdapUserProvider.php b/src/Symfony/Component/Ldap/Security/LdapUserProvider.php index cf7e9b39f2bec..bbdbc570bc730 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUserProvider.php +++ b/src/Symfony/Component/Ldap/Security/LdapUserProvider.php @@ -73,18 +73,27 @@ public function loadUserByUsername($username) $query = str_replace('{username}', $username, $this->defaultSearch); $search = $this->ldap->query($this->baseDn, $query); } catch (ConnectionException $e) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e); + $e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e); + $e->setUsername($username); + + throw $e; } $entries = $search->execute(); $count = \count($entries); if (!$count) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e = new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + $e->setUsername($username); + + throw $e; } if ($count > 1) { - throw new UsernameNotFoundException('More than one user found.'); + $e = new UsernameNotFoundException('More than one user found.'); + $e->setUsername($username); + + throw $e; } $entry = $entries[0]; diff --git a/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php b/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php index a34c2db76cb4d..3467a32cef50a 100644 --- a/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php @@ -105,7 +105,10 @@ private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator $user = $guardAuthenticator->getUser($token->getCredentials(), $this->userProvider); if (null === $user) { - throw new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator))); + $e = new UsernameNotFoundException(sprintf('Null returned from "%s::getUser()".', \get_class($guardAuthenticator))); + $e->setUsername($token->getUsername()); + + throw $e; } if (!$user instanceof UserInterface) {