diff options
author | Alexander <iam.asm89@gmail.com> | 2012-07-15 17:26:18 +0200 |
---|---|---|
committer | Alexander <iam.asm89@gmail.com> | 2013-01-07 20:58:58 +0100 |
commit | 7f5659fa1622474a60de0578f0c7014b22746da2 (patch) | |
tree | 3fe8ddba859fe93176f1717fa4e05a080276e4b3 | |
parent | 236974f019efbe80e96388dc30f881add50599b6 (diff) | |
download | symfony-security-7f5659fa1622474a60de0578f0c7014b22746da2.zip symfony-security-7f5659fa1622474a60de0578f0c7014b22746da2.tar.gz symfony-security-7f5659fa1622474a60de0578f0c7014b22746da2.tar.bz2 |
[Security] Removed `get/setExtraInformation`, added `get/set(Token|User)`
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Core/Authentication/AuthenticationProviderManager.php | 4 | ||||
-rw-r--r-- | Core/Authentication/Provider/DaoAuthenticationProvider.php | 2 | ||||
-rw-r--r-- | Core/Exception/AccountStatusException.php | 24 | ||||
-rw-r--r-- | Core/Exception/AuthenticationException.php | 22 | ||||
-rw-r--r-- | Core/User/UserChecker.php | 8 | ||||
-rw-r--r-- | Http/Firewall/ExceptionListener.php | 2 | ||||
-rw-r--r-- | Tests/Core/Authentication/AuthenticationProviderManagerTest.php | 6 |
8 files changed, 55 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb4c1d..d897fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,5 +35,6 @@ CHANGELOG * [BC BREAK] moved the default logout success handling to a separate class. The order of arguments in the constructor of `LogoutListener` has changed. * [BC BREAK] The constructor of `AuthenticationException` and all child - classes now matches the constructor of `\Exception`. Extra information - should be passed via the `setExtraInformation` setter. + classes now matches the constructor of `\Exception`. The extra information + getters and setters are removed. There are now dedicated getters/setters for + token (`AuthenticationException') and user (`AccountStatusException`). diff --git a/Core/Authentication/AuthenticationProviderManager.php b/Core/Authentication/AuthenticationProviderManager.php index b0414f0..8b7474b 100644 --- a/Core/Authentication/AuthenticationProviderManager.php +++ b/Core/Authentication/AuthenticationProviderManager.php @@ -77,7 +77,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface break; } } catch (AccountStatusException $e) { - $e->setExtraInformation($token); + $e->setToken($token); throw $e; } catch (AuthenticationException $e) { @@ -105,7 +105,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException)); } - $lastException->setExtraInformation($token); + $lastException->setToken($token); throw $lastException; } diff --git a/Core/Authentication/Provider/DaoAuthenticationProvider.php b/Core/Authentication/Provider/DaoAuthenticationProvider.php index cbfc39c..8647382 100644 --- a/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -91,7 +91,7 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider throw $notFound; } catch (\Exception $repositoryProblem) { $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem); - $ex->setExtraInformation($token); + $ex->setToken($token); throw $ex; } } diff --git a/Core/Exception/AccountStatusException.php b/Core/Exception/AccountStatusException.php index 958f584..5a16673 100644 --- a/Core/Exception/AccountStatusException.php +++ b/Core/Exception/AccountStatusException.php @@ -11,12 +11,36 @@ namespace Symfony\Component\Security\Core\Exception; +use Symfony\Component\Security\Core\User\UserInterface; + /** * AccountStatusException is the base class for authentication exceptions * caused by the user account status. * * @author Fabien Potencier <fabien@symfony.com> + * @author Alexander <iam.asm89@gmail.com> */ abstract class AccountStatusException extends AuthenticationException { + private $user; + + /** + * Get the user. + * + * @return UserInterface + */ + public function getUser() + { + return $this->user; + } + + /** + * Set the user. + * + * @param UserInterface $user + */ + public function setUser(UserInterface $user) + { + $this->user = $user; + } } diff --git a/Core/Exception/AuthenticationException.php b/Core/Exception/AuthenticationException.php index 93e395b..d67d41e 100644 --- a/Core/Exception/AuthenticationException.php +++ b/Core/Exception/AuthenticationException.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Core\Exception; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + /** * AuthenticationException is the base class for all authentication exceptions. * @@ -19,16 +21,26 @@ namespace Symfony\Component\Security\Core\Exception; */ class AuthenticationException extends \RuntimeException implements \Serializable { - private $extraInformation; + private $token; - public function getExtraInformation() + /** + * Get the token. + * + * @return TokenInterface + */ + public function getToken() { - return $this->extraInformation; + return $this->token; } - public function setExtraInformation($extraInformation) + /** + * Set the token. + * + * @param TokenInterface $token + */ + public function setToken(TokenInterface $token) { - $this->extraInformation = $extraInformation; + $this->token = $token; } public function serialize() diff --git a/Core/User/UserChecker.php b/Core/User/UserChecker.php index 955cb19..414bc31 100644 --- a/Core/User/UserChecker.php +++ b/Core/User/UserChecker.php @@ -34,7 +34,7 @@ class UserChecker implements UserCheckerInterface if (!$user->isCredentialsNonExpired()) { $ex = new CredentialsExpiredException('User credentials have expired.'); - $ex->setExtraInformation($user); + $ex->setUser($user); throw $ex; } } @@ -50,19 +50,19 @@ class UserChecker implements UserCheckerInterface if (!$user->isAccountNonLocked()) { $ex = new LockedException('User account is locked.'); - $ex->setExtraInformation($user); + $ex->setUser($user); throw $ex; } if (!$user->isEnabled()) { throw new DisabledException('User account is disabled.'); - $ex->setExtraInformation($user); + $ex->setUser($user); throw $ex; } if (!$user->isAccountNonExpired()) { $ex = new AccountExpiredException('User account has expired.'); - $ex->setExtraInformation($user); + $ex->setUser($user); throw $ex; } } diff --git a/Http/Firewall/ExceptionListener.php b/Http/Firewall/ExceptionListener.php index 489e4c4..99389ef 100644 --- a/Http/Firewall/ExceptionListener.php +++ b/Http/Firewall/ExceptionListener.php @@ -107,7 +107,7 @@ class ExceptionListener try { $insufficientAuthenticationException = new InsufficientAuthenticationException('Full authentication is required to access this resource.', 0, $exception); - $insufficientAuthenticationException->setExtraInformation($token); + $insufficientAuthenticationException->setToken($token); $response = $this->startAuthentication($request, $insufficientAuthenticationException); } catch (\Exception $e) { $event->setException($e); diff --git a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php b/Tests/Core/Authentication/AuthenticationProviderManagerTest.php index c57967b..12eb568 100644 --- a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php +++ b/Tests/Core/Authentication/AuthenticationProviderManagerTest.php @@ -37,7 +37,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase $manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')); $this->fail(); } catch (ProviderNotFoundException $e) { - $this->assertSame($token, $e->getExtraInformation()); + $this->assertSame($token, $e->getToken()); } } @@ -51,7 +51,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase $manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')); $this->fail(); } catch (AccountStatusException $e) { - $this->assertSame($token, $e->getExtraInformation()); + $this->assertSame($token, $e->getToken()); } } @@ -65,7 +65,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase $manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')); $this->fail(); } catch (AuthenticationException $e) { - $this->assertSame($token, $e->getExtraInformation()); + $this->assertSame($token, $e->getToken()); } } |