diff options
Diffstat (limited to 'Core/Authentication/AuthenticationProviderManager.php')
-rw-r--r-- | Core/Authentication/AuthenticationProviderManager.php | 19 |
1 files changed, 19 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; |