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

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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.  * Authentication Token for "Remember-Me".
  14.  *
  15.  * @author Johannes M. Schmitt <[email protected]>
  16.  */
  17. class RememberMeToken extends AbstractToken
  18. {
  19.     private $secret;
  20.     private $firewallName;
  21.     /**
  22.      * @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
  23.      *
  24.      * @throws \InvalidArgumentException
  25.      */
  26.     public function __construct(UserInterface $userstring $firewallNamestring $secret)
  27.     {
  28.         parent::__construct($user->getRoles());
  29.         if (empty($secret)) {
  30.             throw new \InvalidArgumentException('$secret must not be empty.');
  31.         }
  32.         if ('' === $firewallName) {
  33.             throw new \InvalidArgumentException('$firewallName must not be empty.');
  34.         }
  35.         $this->firewallName $firewallName;
  36.         $this->secret $secret;
  37.         $this->setUser($user);
  38.         parent::setAuthenticated(truefalse);
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function setAuthenticated(bool $authenticated)
  44.     {
  45.         if ($authenticated) {
  46.             throw new \LogicException('You cannot set this token to authenticated after creation.');
  47.         }
  48.         parent::setAuthenticated(falsefalse);
  49.     }
  50.     /**
  51.      * Returns the provider secret.
  52.      *
  53.      * @return string The provider secret
  54.      *
  55.      * @deprecated since Symfony 5.2, use getFirewallName() instead
  56.      */
  57.     public function getProviderKey()
  58.     {
  59.         if (!== \func_num_args() || true !== func_get_arg(0)) {
  60.             trigger_deprecation('symfony/security-core''5.2''Method "%s()" is deprecated, use "getFirewallName()" instead.'__METHOD__);
  61.         }
  62.         return $this->firewallName;
  63.     }
  64.     public function getFirewallName(): string
  65.     {
  66.         return $this->getProviderKey(true);
  67.     }
  68.     /**
  69.      * @return string
  70.      */
  71.     public function getSecret()
  72.     {
  73.         return $this->secret;
  74.     }
  75.     /**
  76.      * {@inheritdoc}
  77.      */
  78.     public function getCredentials()
  79.     {
  80.         trigger_deprecation('symfony/security-core''5.4''Method "%s()" is deprecated.'__METHOD__);
  81.         return '';
  82.     }
  83.     /**
  84.      * {@inheritdoc}
  85.      */
  86.     public function __serialize(): array
  87.     {
  88.         return [$this->secret$this->firewallNameparent::__serialize()];
  89.     }
  90.     /**
  91.      * {@inheritdoc}
  92.      */
  93.     public function __unserialize(array $data): void
  94.     {
  95.         [$this->secret$this->firewallName$parentData] = $data;
  96.         $parentData \is_array($parentData) ? $parentData unserialize($parentData);
  97.         parent::__unserialize($parentData);
  98.     }
  99. }