diff options
-rw-r--r-- | Core/Authentication/AuthenticationProviderManager.php | 19 | ||||
-rw-r--r-- | Core/AuthenticationEvents.php | 19 | ||||
-rw-r--r-- | Core/Event/AuthenticationEvent.php | 35 | ||||
-rw-r--r-- | Core/Event/AuthenticationFailureEvent.php | 37 |
4 files changed, 110 insertions, 0 deletions
diff --git a/Core/Authentication/AuthenticationProviderManager.php b/Core/Authentication/AuthenticationProviderManager.php index a82b9fb..7ca46c0 100644 --- a/Core/Authentication/AuthenticationProviderManager.php +++ b/Core/Authentication/AuthenticationProviderManager.php @@ -11,6 +11,10 @@ namespace Symfony\Component\Security\Core\Authentication; +use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent; +use Symfony\Component\Security\Core\Event\AuthenticationEvent; +use Symfony\Component\Security\Core\AuthenticationEvents; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Security\Core\Exception\AccountStatusException; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\ProviderNotFoundException; @@ -22,11 +26,13 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; * instances to authenticate a Token. * * @author Fabien Potencier <fabien@symfony.com> + * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ class AuthenticationProviderManager implements AuthenticationManagerInterface { private $providers; private $eraseCredentials; + private $eventDispatcher; /** * Constructor. @@ -44,6 +50,11 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface $this->eraseCredentials = (Boolean) $eraseCredentials; } + public function setEventDispatcher(EventDispatcherInterface $dispatcher) + { + $this->eventDispatcher = $dispatcher; + } + /** * {@inheritdoc} */ @@ -77,6 +88,10 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface $result->eraseCredentials(); } + if (null !== $this->eventDispatcher) { + $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($result)); + } + return $result; } @@ -84,6 +99,10 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface $lastException = new ProviderNotFoundException(sprintf('No Authentication Provider found for token of class "%s".', get_class($token))); } + if (null !== $this->eventDispatcher) { + $this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException)); + } + $lastException->setExtraInformation($token); throw $lastException; diff --git a/Core/AuthenticationEvents.php b/Core/AuthenticationEvents.php new file mode 100644 index 0000000..1e0e6ff --- /dev/null +++ b/Core/AuthenticationEvents.php @@ -0,0 +1,19 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Core; + +final class AuthenticationEvents +{ + const AUTHENTICATION_SUCCESS = 'security.authentication.success'; + + const AUTHENTICATION_FAILURE = 'security.authentication.failure'; +} diff --git a/Core/Event/AuthenticationEvent.php b/Core/Event/AuthenticationEvent.php new file mode 100644 index 0000000..4c32b21 --- /dev/null +++ b/Core/Event/AuthenticationEvent.php @@ -0,0 +1,35 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Core\Event; + +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\EventDispatcher\Event; + +/** + * This is a general purpose authentication event. + * + * @author Johannes M. Schmitt <schmittjoh@gmail.com> + */ +class AuthenticationEvent extends Event +{ + private $authenticationToken; + + public function __construct(TokenInterface $token) + { + $this->authenticationToken = $token; + } + + public function getAuthenticationToken() + { + return $this->authenticationToken; + } +}
\ No newline at end of file diff --git a/Core/Event/AuthenticationFailureEvent.php b/Core/Event/AuthenticationFailureEvent.php new file mode 100644 index 0000000..6518b69 --- /dev/null +++ b/Core/Event/AuthenticationFailureEvent.php @@ -0,0 +1,37 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Core\Event; + +use Symfony\Component\Security\Core\Exception\AuthenticationException; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + +/** + * This event is dispatched on authentication failure. + * + * @author Johannes M. Schmitt <schmittjoh@gmail.com> + */ +class AuthenticationFailureEvent extends AuthenticationEvent +{ + private $authenticationException; + + public function __construct(TokenInterface $token, AuthenticationException $ex) + { + parent::__construct($token); + + $this->authenticationException = $ex; + } + + public function getAuthenticationException() + { + return $this->authenticationException; + } +}
\ No newline at end of file |