diff options
Diffstat (limited to 'Authentication/Provider')
-rw-r--r-- | Authentication/Provider/DaoAuthenticationProvider.php | 23 | ||||
-rw-r--r-- | Authentication/Provider/UserAuthenticationProvider.php | 23 |
2 files changed, 19 insertions, 27 deletions
diff --git a/Authentication/Provider/DaoAuthenticationProvider.php b/Authentication/Provider/DaoAuthenticationProvider.php index 34880b2..4f93440 100644 --- a/Authentication/Provider/DaoAuthenticationProvider.php +++ b/Authentication/Provider/DaoAuthenticationProvider.php @@ -78,28 +78,21 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider { $user = $token->getUser(); if ($user instanceof AccountInterface) { - return array($user, $token->getUserProviderName()); + return $user; } - $result = null; try { - $result = $this->userProvider->loadUserByUsername($username); + $user = $this->userProvider->loadUserByUsername($username); + + if (!$user instanceof AccountInterface) { + throw new AuthenticationServiceException('The user provider must return an AccountInterface object.'); + } + + return $user; } catch (UsernameNotFoundException $notFound) { throw $notFound; } catch (\Exception $repositoryProblem) { throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem); } - - if (!is_array($result) || 2 !== count($result)) { - throw new AuthenticationServiceException('User provider did not return an array, or array had invalid format.'); - } - if (!$result[0] instanceof AccountInterface) { - throw new AuthenticationServiceException('The user provider must return an AccountInterface object.'); - } - if (empty($result[1])) { - throw new AuthenticationServiceException('The user provider must return a non-empty user provider name.'); - } - - return $result; } } diff --git a/Authentication/Provider/UserAuthenticationProvider.php b/Authentication/Provider/UserAuthenticationProvider.php index f621e42..b5e2dbb 100644 --- a/Authentication/Provider/UserAuthenticationProvider.php +++ b/Authentication/Provider/UserAuthenticationProvider.php @@ -54,7 +54,17 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter $username = null === $token->getUser() ? 'NONE_PROVIDED' : (string) $token; try { - $result = $this->retrieveUser($username, $token); + $user = $this->retrieveUser($username, $token); + + if (!$user instanceof AccountInterface) { + throw new AuthenticationServiceException('retrieveUser() must return an AccountInterface.'); + } + + $this->accountChecker->checkPreAuth($user); + $this->checkAuthentication($user, $token); + $this->accountChecker->checkPostAuth($user); + + return new UsernamePasswordToken($user, $token->getCredentials(), $user->getRoles()); } catch (UsernameNotFoundException $notFound) { if ($this->hideUserNotFoundExceptions) { throw new BadCredentialsException('Bad credentials', 0, $notFound); @@ -62,17 +72,6 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter throw $notFound; } - - if (!is_array($result) || 2 !== count($result)) { - throw new AuthenticationServiceException('retrieveUser() did not return an array, or array had invalid format.'); - } - list($user, $userProviderName) = $result; - - $this->accountChecker->checkPreAuth($user); - $this->checkAuthentication($user, $token); - $this->accountChecker->checkPostAuth($user); - - return new UsernamePasswordToken($user, $token->getCredentials(), $userProviderName, $user->getRoles()); } /** |