diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2011-11-07 22:32:45 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2011-11-07 22:43:16 +0100 |
commit | 7756322a47567b001e84c884af89a93a748cc858 (patch) | |
tree | 9f39188bbb4f1971608c7327ae247acd4f47850c | |
parent | 0e3d865d981156aa97d2f121d22ed7595a9849ed (diff) | |
download | symfony-security-7756322a47567b001e84c884af89a93a748cc858.zip symfony-security-7756322a47567b001e84c884af89a93a748cc858.tar.gz symfony-security-7756322a47567b001e84c884af89a93a748cc858.tar.bz2 |
[Security] made exceptions thrown by the user checker and the checkAuthentication() method use the hideUserNotFoundExceptions flag
-rw-r--r-- | Core/Authentication/Provider/UserAuthenticationProvider.php | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/Core/Authentication/Provider/UserAuthenticationProvider.php b/Core/Authentication/Provider/UserAuthenticationProvider.php index ce78df6..f0463ea 100644 --- a/Core/Authentication/Provider/UserAuthenticationProvider.php +++ b/Core/Authentication/Provider/UserAuthenticationProvider.php @@ -65,26 +65,34 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter try { $user = $this->retrieveUser($username, $token); - - if (!$user instanceof UserInterface) { - throw new AuthenticationServiceException('retrieveUser() must return a UserInterface.'); + } catch (UsernameNotFoundException $notFound) { + if ($this->hideUserNotFoundExceptions) { + throw new BadCredentialsException('Bad credentials', 0, $notFound); } + throw $notFound; + } + + if (!$user instanceof UserInterface) { + throw new AuthenticationServiceException('retrieveUser() must return a UserInterface.'); + } + + try { $this->userChecker->checkPreAuth($user); $this->checkAuthentication($user, $token); $this->userChecker->checkPostAuth($user); - - $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles()); - $authenticatedToken->setAttributes($token->getAttributes()); - - return $authenticatedToken; - } catch (UsernameNotFoundException $notFound) { + } catch (BadCredentialsException $e) { if ($this->hideUserNotFoundExceptions) { - throw new BadCredentialsException('Bad credentials', 0, $notFound); + throw new BadCredentialsException('Bad credentials', 0, $e); } - throw $notFound; + throw $e; } + + $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles()); + $authenticatedToken->setAttributes($token->getAttributes()); + + return $authenticatedToken; } /** |