diff options
-rw-r--r-- | Authentication/Provider/DaoAuthenticationProvider.php | 8 | ||||
-rw-r--r-- | Authentication/Provider/UserAuthenticationProvider.php | 16 |
2 files changed, 9 insertions, 15 deletions
diff --git a/Authentication/Provider/DaoAuthenticationProvider.php b/Authentication/Provider/DaoAuthenticationProvider.php index a4fb4c7..9a9f857 100644 --- a/Authentication/Provider/DaoAuthenticationProvider.php +++ b/Authentication/Provider/DaoAuthenticationProvider.php @@ -55,12 +55,10 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider */ protected function checkAuthentication(AccountInterface $account, UsernamePasswordToken $token) { - if (null === $token->getCredentials()) { + if (!$presentedPassword = (string) $token->getCredentials()) { throw new BadCredentialsException('Bad credentials'); } - $presentedPassword = (string) $token->getCredentials(); - if (!$this->passwordEncoder->isPasswordValid($account->getPassword(), $presentedPassword, $account->getSalt())) { throw new BadCredentialsException('Bad credentials'); } @@ -80,8 +78,8 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem); } - if (null === $user) { - throw new AuthenticationServiceException('UserProvider returned null.'); + if (!$user instanceof AccountInterface) { + throw new AuthenticationServiceException('The user provider must return an AccountInterface object.'); } return $user; diff --git a/Authentication/Provider/UserAuthenticationProvider.php b/Authentication/Provider/UserAuthenticationProvider.php index 17acf2a..60c58c1 100644 --- a/Authentication/Provider/UserAuthenticationProvider.php +++ b/Authentication/Provider/UserAuthenticationProvider.php @@ -7,6 +7,7 @@ use Symfony\Component\Security\User\AccountCheckerInterface; use Symfony\Component\Security\Exception\UsernameNotFoundException; use Symfony\Component\Security\Exception\AuthenticationException; use Symfony\Component\Security\Exception\BadCredentialsException; +use Symfony\Component\Security\Exception\AuthenticationServiceException; use Symfony\Component\Security\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Authentication\Token\TokenInterface; @@ -62,17 +63,12 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter throw $notFound; } - if (null === $user) { - throw new \LogicException('The retrieveUser() methods returned null which should not be possible.'); - } - - try { - $this->accountChecker->checkPreAuth($user); - $this->checkAuthentication($user, $token); - } catch (AuthenticationException $e) { - throw $e; + if (!$user instanceof AccountInterface) { + throw new AuthenticationServiceException('The retrieveUser() methods must return an AccountInterface object.'); } + $this->accountChecker->checkPreAuth($user); + $this->checkAuthentication($user, $token); $this->accountChecker->checkPostAuth($user); return new UsernamePasswordToken($user, $token->getCredentials(), $user->getRoles()); @@ -92,7 +88,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter * @param string $username The username to retrieve * @param UsernamePasswordToken $token The Token * - * @return mixed The user + * @return AccountInterface The user * * @throws AuthenticationException if the credentials could not be validated */ |