vendor/scheb/2fa-bundle/Security/Authentication/AuthenticationTrustResolver.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Scheb\TwoFactorBundle\Security\Authentication;
  4. use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
  5. use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
  6. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  7. /**
  8.  * @final
  9.  */
  10. class AuthenticationTrustResolver implements AuthenticationTrustResolverInterface
  11. {
  12.     /**
  13.      * @var AuthenticationTrustResolverInterface
  14.      */
  15.     private $decoratedTrustResolver;
  16.     public function __construct(AuthenticationTrustResolverInterface $decoratedTrustResolver)
  17.     {
  18.         $this->decoratedTrustResolver $decoratedTrustResolver;
  19.     }
  20.     // Compatibility for Symfony <= 5.4
  21.     public function isAnonymous(TokenInterface $token null): bool
  22.     {
  23.         return $this->decoratedTrustResolver->isAnonymous($token);
  24.     }
  25.     public function isRememberMe(TokenInterface $token null): bool
  26.     {
  27.         return $this->decoratedTrustResolver->isRememberMe($token);
  28.     }
  29.     public function isFullFledged(TokenInterface $token null): bool
  30.     {
  31.         return !$this->isTwoFactorToken($token) && $this->decoratedTrustResolver->isFullFledged($token);
  32.     }
  33.     // Compatibility for Symfony >= 5.4
  34.     public function isAuthenticated(TokenInterface $token null): bool
  35.     {
  36.         // When isAuthenticated method is implemented
  37.         if (method_exists($this->decoratedTrustResolver'isAuthenticated')) {
  38.             return $this->decoratedTrustResolver->isAuthenticated($token);
  39.         }
  40.         // Fallback when it's not implemented
  41.         return !$this->decoratedTrustResolver->isAnonymous($token);
  42.     }
  43.     private function isTwoFactorToken(?TokenInterface $token): bool
  44.     {
  45.         return $token instanceof TwoFactorTokenInterface;
  46.     }
  47. }