From 694c47ce9626568efee496accf6ff5a564cbc83e Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:15:05 +0200 Subject: [PATCH 01/17] [Security] Change signature of `AuthenticationException` to match `\Exception` --- .../Security/Core/Exception/AuthenticationException.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index 074dad094b74e..fbe10ebaa8480 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -15,18 +15,12 @@ * AuthenticationException is the base class for all authentication exceptions. * * @author Fabien Potencier + * @author Alexander */ class AuthenticationException extends \RuntimeException implements \Serializable { private $extraInformation; - public function __construct($message, $extraInformation = null, $code = 0, \Exception $previous = null) - { - parent::__construct($message, $code, $previous); - - $this->extraInformation = $extraInformation; - } - public function getExtraInformation() { return $this->extraInformation; From ed6eed4c36cf5339c4661b2c4531dddacfa14f1b Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:16:07 +0200 Subject: [PATCH 02/17] [Security] Add `getMessageKey` and `getMessageData` to auth exceptions --- ...enticationCredentialsNotFoundException.php | 8 ++++++++ .../Exception/AuthenticationException.php | 20 +++++++++++++++++++ .../AuthenticationServiceException.php | 8 ++++++++ .../Exception/BadCredentialsException.php | 8 ++++++-- .../Core/Exception/CookieTheftException.php | 8 ++++++++ .../InsufficientAuthenticationException.php | 8 ++++++++ .../Exception/InvalidCsrfTokenException.php | 8 ++++++++ .../Core/Exception/NonceExpiredException.php | 8 ++++++++ .../Exception/ProviderNotFoundException.php | 8 ++++++++ .../Exception/SessionUnavailableException.php | 8 ++++++++ .../Core/Exception/TokenNotFoundException.php | 8 ++++++++ .../Exception/UsernameNotFoundException.php | 8 ++++++++ 12 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php index 16686ade1096f..1bd8ffdaffe1b 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php @@ -16,7 +16,15 @@ * because no Token is available. * * @author Fabien Potencier + * @author Alexander */ class AuthenticationCredentialsNotFoundException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.authentication_credentials_not_found_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index fbe10ebaa8480..93e395bd9952d 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -52,4 +52,24 @@ public function unserialize($str) $this->line ) = unserialize($str); } + + /** + * Message key to be used by the translation component. + * + * @return string + */ + public function getMessageKey() + { + return 'security.exception.authentication_exception'; + } + + /** + * Message data to be used by the translation component. + * + * @return array + */ + public function getMessageData() + { + return array(); + } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php index 5b32d8110f10e..b002067c17f50 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php @@ -15,7 +15,15 @@ * AuthenticationServiceException is thrown when an authentication request could not be processed due to a system problem. * * @author Fabien Potencier + * @author Alexander */ class AuthenticationServiceException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.authentication_service_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php b/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php index 2eae5b811dc5d..3ac48006e0bb4 100644 --- a/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php +++ b/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php @@ -15,11 +15,15 @@ * BadCredentialsException is thrown when the user credentials are invalid. * * @author Fabien Potencier + * @author Alexander */ class BadCredentialsException extends AuthenticationException { - public function __construct($message, $code = 0, \Exception $previous = null) + /** + * {@inheritDoc} + */ + public function getMessageKey() { - parent::__construct($message, null, $code, $previous); + return 'security.exception.bad_credentials_exception'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php index 2ada78d73b0f3..badd7b101886e 100644 --- a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php +++ b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php @@ -16,7 +16,15 @@ * detects that a presented cookie has already been used by someone else. * * @author Johannes M. Schmitt + * @author Alexander */ class CookieTheftException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.cookie_theft_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php index bbf5517dce8df..d99c03fa9946a 100644 --- a/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php @@ -17,7 +17,15 @@ * This is the case when a user is anonymous and the resource to be displayed has an access role. * * @author Fabien Potencier + * @author Alexander */ class InsufficientAuthenticationException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.insufficient_authentication_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php b/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php index 4181bacc01a87..98a64d0b3a334 100644 --- a/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php +++ b/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php @@ -15,7 +15,15 @@ * This exception is thrown when the csrf token is invalid. * * @author Johannes M. Schmitt + * @author Alexander */ class InvalidCsrfTokenException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.invalid_csrf_token_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php b/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php index 6a6a7811e3c91..0e31713e91f6e 100644 --- a/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php @@ -18,7 +18,15 @@ * the digest nonce has expired. * * @author Fabien Potencier + * @author Alexander */ class NonceExpiredException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.nonce_expired_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php index e11c8aa161f61..aefe2ae109b54 100644 --- a/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php @@ -16,7 +16,15 @@ * supports an authentication Token. * * @author Fabien Potencier + * @author Alexander */ class ProviderNotFoundException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.provider_not_found_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php b/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php index 519164a323bd6..ff88c32bb19cb 100644 --- a/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php +++ b/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php @@ -21,7 +21,15 @@ * request. * * @author Johannes M. Schmitt + * @author Alexander */ class SessionUnavailableException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.session_unavailable_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php index 593f3ad2690e8..da06847b76015 100644 --- a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php @@ -14,7 +14,15 @@ * TokenNotFoundException is thrown if a Token cannot be found. * * @author Johannes M. Schmitt + * @author Alexander */ class TokenNotFoundException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.token_not_found_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php index 38533e7ff3182..2dc553403a958 100644 --- a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php @@ -15,7 +15,15 @@ * UsernameNotFoundException is thrown if a User cannot be found by its username. * * @author Fabien Potencier + * @author Alexander */ class UsernameNotFoundException extends AuthenticationException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.username_not_found_exception'; + } } From 963a1d7b81b4c083d031b629a8bfb933fdf6eea8 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:23:53 +0200 Subject: [PATCH 03/17] [Security] Add initial translations for the exceptions --- .../Resources/translations/exceptions.en.xlf | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf diff --git a/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf b/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf new file mode 100644 index 0000000000000..a14ec4b3140ee --- /dev/null +++ b/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf @@ -0,0 +1,55 @@ + + + + + + security.exception.authentication_exception + An authentication exception occured. + + + security.exception.authentication_credentials_not_found_exception + Authentication credentials could not be found. + + + security.exception.authentication_service_exception + Authentication request could not be processed due to a system problem. + + + security.exception.bad_credentials_exception + Invalid credentials. + + + security.exception.cookie_theft_exception + Cookie has already been used by someone else. + + + security.exception.insufficient_authentication_exception + Not priviliged to request the resource. + + + security.exception.invalid_csrf_token_exception + Invalid CSRF token. + + + security.exception.nonce_expired_exception + Digest nonce has expired. + + + security.exception.provider_not_found_exception + No authentication provider found to support the authentication token. + + + security.exception.session_unavailable_exception + No session available. + + + security.exception.token_not_found_exception + No token could be found. + + + security.exception.username_not_found_exception + Username could not be found. + + + + From 42cced4c970fa9e08fc19f20ac2129b0cb1025ff Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:26:13 +0200 Subject: [PATCH 04/17] [Security] Fix AuthenticationException constructor calls --- .../Security/Http/RememberMe/TokenBasedRememberMeServices.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php index bd828f265cc2b..5a66fe4539945 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php @@ -43,7 +43,7 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request) $user = $this->getUserProvider($class)->loadUserByUsername($username); } catch (\Exception $ex) { if (!$ex instanceof AuthenticationException) { - $ex = new AuthenticationException($ex->getMessage(), null, $ex->getCode(), $ex); + $ex = new AuthenticationException($ex->getMessage(), $ex->getCode(), $ex); } throw $ex; From 79430b8238af398c6f53263c267c7e5fc8401cf7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:31:22 +0200 Subject: [PATCH 05/17] [Security] Fix AuthenticationServiceException constructor calls --- .../Authentication/Provider/DaoAuthenticationProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php index f22045f03dead..cbfc39c86ddbc 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -90,7 +90,9 @@ protected function retrieveUser($username, UsernamePasswordToken $token) } catch (UsernameNotFoundException $notFound) { throw $notFound; } catch (\Exception $repositoryProblem) { - throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem); + $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem); + $ex->setExtraInformation($token); + throw $ex; } } } From 1147977212c0b68612ed97569fae9faec6766d3d Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:37:14 +0200 Subject: [PATCH 06/17] [Security] Fix InsufficientAuthenticationException constructor calls --- .../Component/Security/Http/Firewall/ExceptionListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index f134f9c819de5..489e4c4f773f9 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -106,7 +106,9 @@ public function onKernelException(GetResponseForExceptionEvent $event) } try { - $response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception)); + $insufficientAuthenticationException = new InsufficientAuthenticationException('Full authentication is required to access this resource.', 0, $exception); + $insufficientAuthenticationException->setExtraInformation($token); + $response = $this->startAuthentication($request, $insufficientAuthenticationException); } catch (\Exception $e) { $event->setException($e); From 50e2cfc1f5a7c79bd5e9239eba2c52787cd0841f Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:41:08 +0200 Subject: [PATCH 07/17] [Security] Add custom `getMessageKey` AccountStatusException childs --- .../Security/Core/Exception/AccountExpiredException.php | 8 ++++++++ .../Core/Exception/CredentialsExpiredException.php | 8 ++++++++ .../Security/Core/Exception/DisabledException.php | 8 ++++++++ .../Component/Security/Core/Exception/LockedException.php | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php b/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php index f899b1b76baeb..5a3bd50f528c3 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php @@ -15,7 +15,15 @@ * AccountExpiredException is thrown when the user account has expired. * * @author Fabien Potencier + * @author Alexander */ class AccountExpiredException extends AccountStatusException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.account_expired_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php b/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php index a4d42c842f739..03f96c3bf431b 100644 --- a/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php @@ -15,7 +15,15 @@ * CredentialsExpiredException is thrown when the user account credentials have expired. * * @author Fabien Potencier + * @author Alexander */ class CredentialsExpiredException extends AccountStatusException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.credentials_expired_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/DisabledException.php b/src/Symfony/Component/Security/Core/Exception/DisabledException.php index fd26221502ecf..feb0609701b82 100644 --- a/src/Symfony/Component/Security/Core/Exception/DisabledException.php +++ b/src/Symfony/Component/Security/Core/Exception/DisabledException.php @@ -15,7 +15,15 @@ * DisabledException is thrown when the user account is disabled. * * @author Fabien Potencier + * @author Alexander */ class DisabledException extends AccountStatusException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.disabled_exception'; + } } diff --git a/src/Symfony/Component/Security/Core/Exception/LockedException.php b/src/Symfony/Component/Security/Core/Exception/LockedException.php index 6fa0b778f7fd0..f185a02791c74 100644 --- a/src/Symfony/Component/Security/Core/Exception/LockedException.php +++ b/src/Symfony/Component/Security/Core/Exception/LockedException.php @@ -15,7 +15,15 @@ * LockedException is thrown if the user account is locked. * * @author Fabien Potencier + * @author Alexander */ class LockedException extends AccountStatusException { + /** + * {@inheritDoc} + */ + public function getMessageKey() + { + return 'security.exception.locked_exception'; + } } From 0038fbb8b6a649abce98e47085eca7de631952ff Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:44:07 +0200 Subject: [PATCH 08/17] [Security] Add initial translations for AccountStatusException childs --- .../Resources/translations/exceptions.en.xlf | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf b/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf index a14ec4b3140ee..7a3fac6313803 100644 --- a/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf +++ b/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf @@ -50,6 +50,22 @@ security.exception.username_not_found_exception Username could not be found. + + security.exception.account_expired_exception + Account has expired. + + + security.exception.credentials_expired_exception + Credentials have expired. + + + security.exception.credentials_expired_exception + Account is disabled. + + + security.exception.credentials_expired_exception + Account is locked. + From d7129b9a7e8b85b22e2559afe3bc5c6550494605 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:47:39 +0200 Subject: [PATCH 09/17] [Security] Fix exception constructors called in `UserChecker` --- .../Component/Security/Core/User/UserChecker.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Security/Core/User/UserChecker.php b/src/Symfony/Component/Security/Core/User/UserChecker.php index 93897a1010a41..955cb19bbdde2 100644 --- a/src/Symfony/Component/Security/Core/User/UserChecker.php +++ b/src/Symfony/Component/Security/Core/User/UserChecker.php @@ -33,7 +33,9 @@ public function checkPreAuth(UserInterface $user) } if (!$user->isCredentialsNonExpired()) { - throw new CredentialsExpiredException('User credentials have expired.', $user); + $ex = new CredentialsExpiredException('User credentials have expired.'); + $ex->setExtraInformation($user); + throw $ex; } } @@ -47,15 +49,21 @@ public function checkPostAuth(UserInterface $user) } if (!$user->isAccountNonLocked()) { - throw new LockedException('User account is locked.', $user); + $ex = new LockedException('User account is locked.'); + $ex->setExtraInformation($user); + throw $ex; } if (!$user->isEnabled()) { - throw new DisabledException('User account is disabled.', $user); + throw new DisabledException('User account is disabled.'); + $ex->setExtraInformation($user); + throw $ex; } if (!$user->isAccountNonExpired()) { - throw new AccountExpiredException('User account has expired.', $user); + $ex = new AccountExpiredException('User account has expired.'); + $ex->setExtraInformation($user); + throw $ex; } } } From d6c57cff6f1a1acc679eab8ba7ec8c5be3df2c47 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 15:56:45 +0200 Subject: [PATCH 10/17] [FrameworkBundle] Register security exception translations --- .../DependencyInjection/FrameworkExtension.php | 5 +++++ .../Tests/DependencyInjection/FrameworkExtensionTest.php | 5 +++++ src/Symfony/Bundle/FrameworkBundle/composer.json | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 1ec5e9e2aebe1..92cc1cef08cd7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -527,6 +527,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder $dirs[] = dirname($r->getFilename()).'/Resources/translations'; } + if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) { + $r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException'); + + $dirs[] = dirname($r->getFilename()).'/../../Resources/translations'; + } $overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations'; foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { $reflection = new \ReflectionClass($class); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 3203f37bcaf8a..d60406f871986 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -205,6 +205,11 @@ public function testTranslator() $files, '->registerTranslatorConfiguration() finds Form translation resources' ); + $this->assertContains( + 'Symfony/Component/Security/Resources/translations/exceptions.en.xlf', + $files, + '->registerTranslatorConfiguration() finds Security translation resources' + ); $calls = $container->getDefinition('translator.default')->getMethodCalls(); $this->assertEquals('fr', $calls[0][1][0]); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 3f2ad2f0c13be..12bc33d882443 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -29,7 +29,8 @@ "doctrine/common": ">=2.2,<2.4-dev" }, "require-dev": { - "symfony/finder": "2.2.*" + "symfony/finder": "2.2.*", + "symfony/security": "2.2.*" }, "suggest": { "symfony/console": "2.2.*", From 837ae151029322cf50b840ab0a878f81850f7fbd Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 16:00:04 +0200 Subject: [PATCH 11/17] [Security] Add note about changed constructor to changelog --- src/Symfony/Component/Security/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index 1305b28335316..9fb4c1d579a02 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -34,3 +34,6 @@ CHANGELOG `AbstractAuthenticationListener` has changed. * [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. From 39da27a06d02e44ed02d91830e0ed9b75b507e01 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 17:26:18 +0200 Subject: [PATCH 12/17] [Security] Removed `get/setExtraInformation`, added `get/set(Token|User)` --- src/Symfony/Component/Security/CHANGELOG.md | 5 ++-- .../AuthenticationProviderManager.php | 4 ++-- .../Provider/DaoAuthenticationProvider.php | 2 +- .../Core/Exception/AccountStatusException.php | 24 +++++++++++++++++++ .../Exception/AuthenticationException.php | 22 +++++++++++++---- .../Security/Core/User/UserChecker.php | 8 +++---- .../Http/Firewall/ExceptionListener.php | 2 +- .../AuthenticationProviderManagerTest.php | 6 ++--- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index 9fb4c1d579a02..d897fc3a52d9b 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/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/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php index b0414f0fffd66..8b7474bec4e24 100644 --- a/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php +++ b/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php @@ -77,7 +77,7 @@ public function authenticate(TokenInterface $token) break; } } catch (AccountStatusException $e) { - $e->setExtraInformation($token); + $e->setToken($token); throw $e; } catch (AuthenticationException $e) { @@ -105,7 +105,7 @@ public function authenticate(TokenInterface $token) $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException)); } - $lastException->setExtraInformation($token); + $lastException->setToken($token); throw $lastException; } diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php index cbfc39c86ddbc..8647382d6a607 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -91,7 +91,7 @@ protected function retrieveUser($username, UsernamePasswordToken $token) throw $notFound; } catch (\Exception $repositoryProblem) { $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem); - $ex->setExtraInformation($token); + $ex->setToken($token); throw $ex; } } diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php index 958f584f4ead9..5a166731d2778 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php +++ b/src/Symfony/Component/Security/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 + * @author Alexander */ 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/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index 93e395bd9952d..d67d41e95ee46 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/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 @@ */ 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/src/Symfony/Component/Security/Core/User/UserChecker.php b/src/Symfony/Component/Security/Core/User/UserChecker.php index 955cb19bbdde2..414bc315ebef2 100644 --- a/src/Symfony/Component/Security/Core/User/UserChecker.php +++ b/src/Symfony/Component/Security/Core/User/UserChecker.php @@ -34,7 +34,7 @@ public function checkPreAuth(UserInterface $user) if (!$user->isCredentialsNonExpired()) { $ex = new CredentialsExpiredException('User credentials have expired.'); - $ex->setExtraInformation($user); + $ex->setUser($user); throw $ex; } } @@ -50,19 +50,19 @@ public function checkPostAuth(UserInterface $user) 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/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php index 489e4c4f773f9..99389ef5a51a2 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php @@ -107,7 +107,7 @@ public function onKernelException(GetResponseForExceptionEvent $event) 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/src/Symfony/Component/Security/Tests/Core/Authentication/AuthenticationProviderManagerTest.php b/src/Symfony/Component/Security/Tests/Core/Authentication/AuthenticationProviderManagerTest.php index c57967bfa4f8a..12eb568a29be9 100644 --- a/src/Symfony/Component/Security/Tests/Core/Authentication/AuthenticationProviderManagerTest.php +++ b/src/Symfony/Component/Security/Tests/Core/Authentication/AuthenticationProviderManagerTest.php @@ -37,7 +37,7 @@ public function testAuthenticateWhenNoProviderSupportsToken() $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 @@ public function testAuthenticateWhenProviderReturnsAccountStatusException() $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 @@ public function testAuthenticateWhenProviderReturnsAuthenticationException() $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()); } } From 50d5724c238bd08e3a43ce0a076c4288e25e6a3b Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 17:38:53 +0200 Subject: [PATCH 13/17] [Security] Introduced `UsernameNotFoundException#get/setUsername` --- src/Symfony/Component/Security/CHANGELOG.md | 3 ++- .../Provider/DaoAuthenticationProvider.php | 1 + .../Provider/UserAuthenticationProvider.php | 1 + .../Exception/UsernameNotFoundException.php | 22 +++++++++++++++++++ .../Security/Core/User/ChainUserProvider.php | 8 +++++-- .../Core/User/InMemoryUserProvider.php | 5 ++++- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Security/CHANGELOG.md b/src/Symfony/Component/Security/CHANGELOG.md index d897fc3a52d9b..83914b16bcfe6 100644 --- a/src/Symfony/Component/Security/CHANGELOG.md +++ b/src/Symfony/Component/Security/CHANGELOG.md @@ -37,4 +37,5 @@ CHANGELOG * [BC BREAK] The constructor of `AuthenticationException` and all child 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`). + token (`AuthenticationException'), user (`AccountStatusException`) and + username (`UsernameNotFoundException`). diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php index 8647382d6a607..a9a22056d6e64 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -88,6 +88,7 @@ protected function retrieveUser($username, UsernamePasswordToken $token) return $user; } catch (UsernameNotFoundException $notFound) { + $notFound->setUsername($username); throw $notFound; } catch (\Exception $repositoryProblem) { $ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem); diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php index ed8f4995e1fff..626f50b8b59f9 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php @@ -71,6 +71,7 @@ public function authenticate(TokenInterface $token) if ($this->hideUserNotFoundExceptions) { throw new BadCredentialsException('Bad credentials', 0, $notFound); } + $notFound->setUsername($username); throw $notFound; } diff --git a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php index 2dc553403a958..421fada497c69 100644 --- a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php @@ -19,6 +19,8 @@ */ class UsernameNotFoundException extends AuthenticationException { + private $username; + /** * {@inheritDoc} */ @@ -26,4 +28,24 @@ public function getMessageKey() { return 'security.exception.username_not_found_exception'; } + + /** + * Get the username. + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set the username. + * + * @param string $username + */ + public function setUsername($username) + { + $this->username = $username; + } } diff --git a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php index 376ba1c724046..3ff1ea9372383 100644 --- a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php @@ -44,7 +44,9 @@ public function loadUserByUsername($username) } } - throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $username)); + $ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $username)); + $ex->setUsername($username); + throw $ex; } /** @@ -66,7 +68,9 @@ public function refreshUser(UserInterface $user) } if ($supportedUserFound) { - throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername())); + $ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername())); + $ex->setUsername($user->getUsername()); + throw $ex; } else { throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user))); } diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php index bd748044879af..e87f80c10af09 100644 --- a/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php @@ -68,7 +68,10 @@ public function createUser(UserInterface $user) public function loadUserByUsername($username) { if (!isset($this->users[strtolower($username)])) { - throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); + $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); + $ex->setUsername($username); + + throw $ex; } $user = $this->users[strtolower($username)]; From 2d7a7ba139a8a758dadb019f6f2f27eb59589041 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 15 Jul 2012 17:46:50 +0200 Subject: [PATCH 14/17] [Security] Fix `AuthenticationException` serialization --- .../Core/Exception/AccountStatusException.php | 23 +++++++++++++++++++ .../Exception/AuthenticationException.php | 4 ++-- .../Exception/UsernameNotFoundException.php | 23 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php index 5a166731d2778..d89d553a53323 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php @@ -43,4 +43,27 @@ public function setUser(UserInterface $user) { $this->user = $user; } + + /** + * {@inheritDoc} + */ + public function serialize() + { + return serialize(array( + $this->user, + parent::serialize(), + )); + } + + /** + * {@inheritDoc} + */ + public function unserialize($str) + { + list( + $this->user, + $parentData + ) = unserialize($str); + parent::unserialize($parentData); + } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index d67d41e95ee46..7958ff78c144d 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -46,7 +46,7 @@ public function setToken(TokenInterface $token) public function serialize() { return serialize(array( - $this->extraInformation, + $this->token, $this->code, $this->message, $this->file, @@ -57,7 +57,7 @@ public function serialize() public function unserialize($str) { list( - $this->extraInformation, + $this->token, $this->code, $this->message, $this->file, diff --git a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php index 421fada497c69..9a9989f096ac8 100644 --- a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php @@ -48,4 +48,27 @@ public function setUsername($username) { $this->username = $username; } + + /** + * {@inheritDoc} + */ + public function serialize() + { + return serialize(array( + $this->username, + parent::serialize(), + )); + } + + /** + * {@inheritDoc} + */ + public function unserialize($str) + { + list( + $this->username, + $parentData + ) = unserialize($str); + parent::unserialize($parentData); + } } From aa7476967a99903be91ece62cdba383ebef26011 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 7 Jan 2013 20:34:14 +0100 Subject: [PATCH 15/17] [Security] Fix CS + unreachable code --- .../Security/Core/Exception/AccountStatusException.php | 6 ++---- .../Security/Core/Exception/UsernameNotFoundException.php | 6 ++---- src/Symfony/Component/Security/Core/User/UserChecker.php | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php index d89d553a53323..7819e4dd09f5a 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php @@ -60,10 +60,8 @@ public function serialize() */ public function unserialize($str) { - list( - $this->user, - $parentData - ) = unserialize($str); + list($this->user, $parentData) = unserialize($str); + parent::unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php index 9a9989f096ac8..0299f839ac7fe 100644 --- a/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/UsernameNotFoundException.php @@ -65,10 +65,8 @@ public function serialize() */ public function unserialize($str) { - list( - $this->username, - $parentData - ) = unserialize($str); + list($this->username, $parentData) = unserialize($str); + parent::unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Core/User/UserChecker.php b/src/Symfony/Component/Security/Core/User/UserChecker.php index 414bc315ebef2..8dde3a6670383 100644 --- a/src/Symfony/Component/Security/Core/User/UserChecker.php +++ b/src/Symfony/Component/Security/Core/User/UserChecker.php @@ -55,7 +55,7 @@ public function checkPostAuth(UserInterface $user) } if (!$user->isEnabled()) { - throw new DisabledException('User account is disabled.'); + $ex = new DisabledException('User account is disabled.'); $ex->setUser($user); throw $ex; } From 324703a9ff6c54e8bde784e0c54410ad957e61bc Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 7 Jan 2013 20:55:10 +0100 Subject: [PATCH 16/17] [Security] Switch to English messages as message keys --- .../Security/Core/Exception/AccountExpiredException.php | 2 +- .../Exception/AuthenticationCredentialsNotFoundException.php | 2 +- .../Security/Core/Exception/AuthenticationException.php | 2 +- .../Core/Exception/AuthenticationServiceException.php | 2 +- .../Security/Core/Exception/BadCredentialsException.php | 2 +- .../Security/Core/Exception/CookieTheftException.php | 2 +- .../Security/Core/Exception/CredentialsExpiredException.php | 2 +- .../Component/Security/Core/Exception/DisabledException.php | 2 +- .../Core/Exception/InsufficientAuthenticationException.php | 2 +- .../Security/Core/Exception/InvalidCsrfTokenException.php | 2 +- .../Component/Security/Core/Exception/LockedException.php | 2 +- .../Security/Core/Exception/NonceExpiredException.php | 2 +- .../Security/Core/Exception/ProviderNotFoundException.php | 2 +- .../Security/Core/Exception/SessionUnavailableException.php | 2 +- .../Security/Core/Exception/TokenNotFoundException.php | 5 +++-- .../Security/Core/Exception/UsernameNotFoundException.php | 2 +- 16 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php b/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php index 5a3bd50f528c3..a5618ce6219ba 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountExpiredException.php @@ -24,6 +24,6 @@ class AccountExpiredException extends AccountStatusException */ public function getMessageKey() { - return 'security.exception.account_expired_exception'; + return 'Account has expired.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php index 1bd8ffdaffe1b..633b2bee9269c 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationCredentialsNotFoundException.php @@ -25,6 +25,6 @@ class AuthenticationCredentialsNotFoundException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.authentication_credentials_not_found_exception'; + return 'Authentication credentials could not be found.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php index 7958ff78c144d..2b897c251302c 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationException.php @@ -72,7 +72,7 @@ public function unserialize($str) */ public function getMessageKey() { - return 'security.exception.authentication_exception'; + return 'An authentication exception occurred.'; } /** diff --git a/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php b/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php index b002067c17f50..758a4f024501e 100644 --- a/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php +++ b/src/Symfony/Component/Security/Core/Exception/AuthenticationServiceException.php @@ -24,6 +24,6 @@ class AuthenticationServiceException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.authentication_service_exception'; + return 'Authentication request could not be processed due to a system problem.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php b/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php index 3ac48006e0bb4..5deecca9b301e 100644 --- a/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php +++ b/src/Symfony/Component/Security/Core/Exception/BadCredentialsException.php @@ -24,6 +24,6 @@ class BadCredentialsException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.bad_credentials_exception'; + return 'Invalid credentials.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php index badd7b101886e..8d9e1549448e1 100644 --- a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php +++ b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php @@ -25,6 +25,6 @@ class CookieTheftException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.cookie_theft_exception'; + return 'Cookie has already been used by someone else.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php b/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php index 03f96c3bf431b..b9bf2d158aef5 100644 --- a/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/CredentialsExpiredException.php @@ -24,6 +24,6 @@ class CredentialsExpiredException extends AccountStatusException */ public function getMessageKey() { - return 'security.exception.credentials_expired_exception'; + return 'Credentials have expired.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/DisabledException.php b/src/Symfony/Component/Security/Core/Exception/DisabledException.php index feb0609701b82..5571ab14a9c7f 100644 --- a/src/Symfony/Component/Security/Core/Exception/DisabledException.php +++ b/src/Symfony/Component/Security/Core/Exception/DisabledException.php @@ -24,6 +24,6 @@ class DisabledException extends AccountStatusException */ public function getMessageKey() { - return 'security.exception.disabled_exception'; + return 'Account is disabled.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php b/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php index d99c03fa9946a..74fc2b9b64206 100644 --- a/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php +++ b/src/Symfony/Component/Security/Core/Exception/InsufficientAuthenticationException.php @@ -26,6 +26,6 @@ class InsufficientAuthenticationException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.insufficient_authentication_exception'; + return 'Not privileged to request the resource.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php b/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php index 98a64d0b3a334..ce0e1f410eb88 100644 --- a/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php +++ b/src/Symfony/Component/Security/Core/Exception/InvalidCsrfTokenException.php @@ -24,6 +24,6 @@ class InvalidCsrfTokenException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.invalid_csrf_token_exception'; + return 'Invalid CSRF token.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/LockedException.php b/src/Symfony/Component/Security/Core/Exception/LockedException.php index f185a02791c74..6532f70a5357c 100644 --- a/src/Symfony/Component/Security/Core/Exception/LockedException.php +++ b/src/Symfony/Component/Security/Core/Exception/LockedException.php @@ -24,6 +24,6 @@ class LockedException extends AccountStatusException */ public function getMessageKey() { - return 'security.exception.locked_exception'; + return 'Account is locked.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php b/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php index 0e31713e91f6e..da6fba82b70d2 100644 --- a/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php +++ b/src/Symfony/Component/Security/Core/Exception/NonceExpiredException.php @@ -27,6 +27,6 @@ class NonceExpiredException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.nonce_expired_exception'; + return 'Digest nonce has expired.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php index aefe2ae109b54..ea2b1fdf1f3a4 100644 --- a/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/ProviderNotFoundException.php @@ -25,6 +25,6 @@ class ProviderNotFoundException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.provider_not_found_exception'; + return 'No authentication provider found to support the authentication token.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php b/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php index ff88c32bb19cb..4b47b189efc2a 100644 --- a/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php +++ b/src/Symfony/Component/Security/Core/Exception/SessionUnavailableException.php @@ -30,6 +30,6 @@ class SessionUnavailableException extends AuthenticationException */ public function getMessageKey() { - return 'security.exception.session_unavailable_exception'; + return 'No session available, it either timed out or cookies are not enabled.'; } } diff --git a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php index da06847b76015..fb85abf0cf595 100644 --- a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php @@ -1,5 +1,4 @@ Date: Mon, 7 Jan 2013 20:57:06 +0100 Subject: [PATCH 17/17] [Security] Move translations file to 'security' domain --- .../FrameworkExtensionTest.php | 2 +- .../{exceptions.en.xlf => security.en.xlf} | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) rename src/Symfony/Component/Security/Resources/translations/{exceptions.en.xlf => security.en.xlf} (57%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index d60406f871986..129ae0aa4d680 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -206,7 +206,7 @@ public function testTranslator() '->registerTranslatorConfiguration() finds Form translation resources' ); $this->assertContains( - 'Symfony/Component/Security/Resources/translations/exceptions.en.xlf', + 'Symfony/Component/Security/Resources/translations/security.en.xlf', $files, '->registerTranslatorConfiguration() finds Security translation resources' ); diff --git a/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf b/src/Symfony/Component/Security/Resources/translations/security.en.xlf similarity index 57% rename from src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf rename to src/Symfony/Component/Security/Resources/translations/security.en.xlf index 7a3fac6313803..3640698ce9fb3 100644 --- a/src/Symfony/Component/Security/Resources/translations/exceptions.en.xlf +++ b/src/Symfony/Component/Security/Resources/translations/security.en.xlf @@ -3,67 +3,67 @@ - security.exception.authentication_exception - An authentication exception occured. + An authentication exception occurred. + An authentication exception occurred. - security.exception.authentication_credentials_not_found_exception + Authentication credentials could not be found. Authentication credentials could not be found. - security.exception.authentication_service_exception + Authentication request could not be processed due to a system problem. Authentication request could not be processed due to a system problem. - security.exception.bad_credentials_exception + Invalid credentials. Invalid credentials. - security.exception.cookie_theft_exception + Cookie has already been used by someone else. Cookie has already been used by someone else. - security.exception.insufficient_authentication_exception - Not priviliged to request the resource. + Not privileged to request the resource. + Not privileged to request the resource. - security.exception.invalid_csrf_token_exception + Invalid CSRF token. Invalid CSRF token. - security.exception.nonce_expired_exception + Digest nonce has expired. Digest nonce has expired. - security.exception.provider_not_found_exception + No authentication provider found to support the authentication token. No authentication provider found to support the authentication token. - security.exception.session_unavailable_exception - No session available. + No session available, it either timed out or cookies are not enabled. + No session available, it either timed out or cookies are not enabled. - security.exception.token_not_found_exception + No token could be found. No token could be found. - security.exception.username_not_found_exception + Username could not be found. Username could not be found. - security.exception.account_expired_exception + Account has expired. Account has expired. - security.exception.credentials_expired_exception + Credentials have expired. Credentials have expired. - security.exception.credentials_expired_exception + Account is disabled. Account is disabled. - security.exception.credentials_expired_exception + Account is locked. Account is locked.