From 170895e91bdbe2c21983f195271d42e2fcfb3d62 Mon Sep 17 00:00:00 2001 From: Christian Scheb Date: Mon, 2 Sep 2019 20:36:37 +0200 Subject: [PATCH] Use TwoFactorTokenInterface to keep it compatible with custom token implementations --- .../Provider/AuthenticationProviderDecorator.php | 2 +- .../Provider/TwoFactorAuthenticationProvider.php | 2 +- Security/Http/Firewall/TwoFactorListener.php | 2 +- .../Provider/TwoFactorProviderPreparationListener.php | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Security/Authentication/Provider/AuthenticationProviderDecorator.php b/Security/Authentication/Provider/AuthenticationProviderDecorator.php index 0e4d2d58..fc66d6c8 100644 --- a/Security/Authentication/Provider/AuthenticationProviderDecorator.php +++ b/Security/Authentication/Provider/AuthenticationProviderDecorator.php @@ -72,7 +72,7 @@ public function authenticate(TokenInterface $token) return $token; } - // AnonymousToken and TwoFactorToken can be ignored + // AnonymousToken and TwoFactorTokenInterface can be ignored // in case of Guard, it can return null due to having multiple guard authenticators if ($token instanceof AnonymousToken || $token instanceof TwoFactorTokenInterface || null === $token) { return $token; diff --git a/Security/Authentication/Provider/TwoFactorAuthenticationProvider.php b/Security/Authentication/Provider/TwoFactorAuthenticationProvider.php index df99c308..cc87d01e 100644 --- a/Security/Authentication/Provider/TwoFactorAuthenticationProvider.php +++ b/Security/Authentication/Provider/TwoFactorAuthenticationProvider.php @@ -73,7 +73,7 @@ public function authenticate(TokenInterface $token) throw new AuthenticationException('The token is not supported by this authentication provider.'); } - // Keep unauthenticated TwoFactorToken with no credentials given + // Keep unauthenticated TwoFactorTokenInterface with no credentials given if (null === $token->getCredentials()) { return $token; } diff --git a/Security/Http/Firewall/TwoFactorListener.php b/Security/Http/Firewall/TwoFactorListener.php index c4188125..4082ffa9 100644 --- a/Security/Http/Firewall/TwoFactorListener.php +++ b/Security/Http/Firewall/TwoFactorListener.php @@ -229,7 +229,7 @@ private function onSuccess(Request $request, TokenInterface $token): Response $this->tokenStorage->setToken($token); $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token); - // When it's still a TwoFactorToken, keep showing the auth form + // When it's still a TwoFactorTokenInterface, keep showing the auth form if ($token instanceof TwoFactorTokenInterface) { $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::REQUIRE, $request, $token); diff --git a/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php b/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php index 20cacb37..9a1f2647 100644 --- a/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php +++ b/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php @@ -5,7 +5,7 @@ namespace Scheb\TwoFactorBundle\Security\TwoFactor\Provider; use Psr\Log\LoggerInterface; -use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorToken; +use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface; use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorAuthenticationEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -24,7 +24,7 @@ class TwoFactorProviderPreparationListener private $preparationRecorder; /** - * @var TwoFactorToken|null + * @var TwoFactorTokenInterface|null */ private $twoFactorToken; @@ -69,7 +69,7 @@ public function onLogin(AuthenticationEvent $event): void { $token = $event->getAuthenticationToken(); if ($this->prepareOnLogin && $this->supports($token)) { - // After login, when the token is a TwoFactorToken, execute preparation + // After login, when the token is a TwoFactorTokenInterface, execute preparation $this->twoFactorToken = $token; } } @@ -97,7 +97,7 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void if (!$event->isMasterRequest()) { return; } - if (!($this->twoFactorToken instanceof TwoFactorToken)) { + if (!($this->twoFactorToken instanceof TwoFactorTokenInterface)) { return; } @@ -122,6 +122,6 @@ public function onKernelFinishRequest(FinishRequestEvent $event): void private function supports(TokenInterface $token): bool { - return $token instanceof TwoFactorToken && $token->getProviderKey() === $this->firewallName; + return $token instanceof TwoFactorTokenInterface && $token->getProviderKey() === $this->firewallName; } }