diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 115ad5cf50..5dd3889e8e 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -62,7 +62,10 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter } 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 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter $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 5b50def554..fe12ea90f1 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 @@ class ArrayUserProvider implements UserProviderInterface $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 cf7e9b39f2..bbdbc570bc 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUserProvider.php +++ b/src/Symfony/Component/Ldap/Security/LdapUserProvider.php @@ -73,18 +73,27 @@ class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterfa $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 a34c2db76c..3467a32cef 100644 --- a/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php @@ -105,7 +105,10 @@ class GuardAuthenticationProvider implements AuthenticationProviderInterface $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) {