summaryrefslogtreecommitdiffstats
path: root/Authentication/Provider
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2010-10-31 15:41:15 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2010-10-31 15:41:15 +0100
commitaed2d8c79b2f0a8ff4834eea340109455a304d9f (patch)
treed2b58db34e95c877c8f9e99e7dbfe2bf9cb12553 /Authentication/Provider
parent0ac635c153de6ce16d2a869c205c52ed0546a223 (diff)
downloadsymfony-security-aed2d8c79b2f0a8ff4834eea340109455a304d9f.zip
symfony-security-aed2d8c79b2f0a8ff4834eea340109455a304d9f.tar.gz
symfony-security-aed2d8c79b2f0a8ff4834eea340109455a304d9f.tar.bz2
[Security] added unit tests to some authenticated providers (code coverage is more than 96% for the Security component now)
Diffstat (limited to 'Authentication/Provider')
-rw-r--r--Authentication/Provider/DaoAuthenticationProvider.php8
-rw-r--r--Authentication/Provider/UserAuthenticationProvider.php16
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
*/