vendor/symfony/security-http/Authenticator/AbstractAuthenticator.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Http\Authenticator;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. use Symfony\Component\Security\Core\Exception\LogicException;
  13. use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
  14. use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
  15. use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
  16. use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
  17. /**
  18.  * An optional base class that creates the necessary tokens for you.
  19.  *
  20.  * @author Ryan Weaver <ryan@symfonycasts.com>
  21.  */
  22. abstract class AbstractAuthenticator implements AuthenticatorInterface
  23. {
  24.     /**
  25.      * Shortcut to create a PostAuthenticationToken for you, if you don't really
  26.      * care about which authenticated token you're using.
  27.      */
  28.     public function createToken(Passport $passportstring $firewallName): TokenInterface
  29.     {
  30.         if (self::class !== (new \ReflectionMethod($this'createAuthenticatedToken'))->getDeclaringClass()->getName() && self::class === (new \ReflectionMethod($this'createToken'))->getDeclaringClass()->getName()) {
  31.             return $this->createAuthenticatedToken($passport$firewallName);
  32.         }
  33.         return new PostAuthenticationToken($passport->getUser(), $firewallName$passport->getUser()->getRoles());
  34.     }
  35.     /**
  36.      * @deprecated since Symfony 5.4, use {@link createToken()} instead
  37.      */
  38.     public function createAuthenticatedToken(PassportInterface $passportstring $firewallName): TokenInterface
  39.     {
  40.         // @deprecated since Symfony 5.4
  41.         if (!$passport instanceof UserPassportInterface) {
  42.             throw new LogicException(sprintf('Passport does not contain a user, overwrite "createToken()" in "%s" to create a custom authentication token.', static::class));
  43.         }
  44.         trigger_deprecation('symfony/security-http''5.4''Method "%s()" is deprecated, use "%s::createToken()" instead.'__METHOD____CLASS__);
  45.         return new PostAuthenticationToken($passport->getUser(), $firewallName$passport->getUser()->getRoles());
  46.     }
  47. }