vendor/symfony/security-core/Authentication/Token/PreAuthenticatedToken.php line 21

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\Core\Authentication\Token;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. /**
  13.  * PreAuthenticatedToken implements a pre-authenticated token.
  14.  *
  15.  * @author Fabien Potencier <fabien@symfony.com>
  16.  */
  17. class PreAuthenticatedToken extends AbstractToken
  18. {
  19.     private $credentials;
  20.     private $firewallName;
  21.     /**
  22.      * @param UserInterface $user
  23.      * @param string        $firewallName
  24.      * @param string[]      $roles
  25.      */
  26.     public function __construct($user/* string */ $firewallName/* array */ $roles = [])
  27.     {
  28.         if (\is_string($roles)) {
  29.             trigger_deprecation('symfony/security-core''5.4''Argument $credentials of "%s()" is deprecated.'__METHOD__);
  30.             $credentials $firewallName;
  31.             $firewallName $roles;
  32.             $roles \func_num_args() > func_get_arg(3) : [];
  33.         }
  34.         parent::__construct($roles);
  35.         if ('' === $firewallName) {
  36.             throw new \InvalidArgumentException('$firewallName must not be empty.');
  37.         }
  38.         $this->setUser($user);
  39.         $this->credentials $credentials ?? null;
  40.         $this->firewallName $firewallName;
  41.         if ($roles) {
  42.             $this->setAuthenticated(truefalse);
  43.         }
  44.     }
  45.     /**
  46.      * Returns the provider key.
  47.      *
  48.      * @return string The provider key
  49.      *
  50.      * @deprecated since Symfony 5.2, use getFirewallName() instead
  51.      */
  52.     public function getProviderKey()
  53.     {
  54.         if (!== \func_num_args() || true !== func_get_arg(0)) {
  55.             trigger_deprecation('symfony/security-core''5.2''Method "%s()" is deprecated, use "getFirewallName()" instead.'__METHOD__);
  56.         }
  57.         return $this->firewallName;
  58.     }
  59.     public function getFirewallName(): string
  60.     {
  61.         return $this->getProviderKey(true);
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function getCredentials()
  67.     {
  68.         trigger_deprecation('symfony/security-core''5.4''Method "%s()" is deprecated.'__METHOD__);
  69.         return $this->credentials;
  70.     }
  71.     /**
  72.      * {@inheritdoc}
  73.      */
  74.     public function eraseCredentials()
  75.     {
  76.         parent::eraseCredentials();
  77.         $this->credentials null;
  78.     }
  79.     /**
  80.      * {@inheritdoc}
  81.      */
  82.     public function __serialize(): array
  83.     {
  84.         return [$this->credentials$this->firewallNameparent::__serialize()];
  85.     }
  86.     /**
  87.      * {@inheritdoc}
  88.      */
  89.     public function __unserialize(array $data): void
  90.     {
  91.         [$this->credentials$this->firewallName$parentData] = $data;
  92.         $parentData \is_array($parentData) ? $parentData unserialize($parentData);
  93.         parent::__unserialize($parentData);
  94.     }
  95. }