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 $providerKey;
  21.     /**
  22.      * @param string|\Stringable|UserInterface $user
  23.      * @param mixed                            $credentials
  24.      * @param string[]                         $roles
  25.      */
  26.     public function __construct($user$credentialsstring $providerKey, array $roles = [])
  27.     {
  28.         parent::__construct($roles);
  29.         if (empty($providerKey)) {
  30.             throw new \InvalidArgumentException('$providerKey must not be empty.');
  31.         }
  32.         $this->setUser($user);
  33.         $this->credentials $credentials;
  34.         $this->providerKey $providerKey;
  35.         if ($roles) {
  36.             $this->setAuthenticated(true);
  37.         }
  38.     }
  39.     /**
  40.      * Returns the provider key.
  41.      *
  42.      * @return string The provider key
  43.      */
  44.     public function getProviderKey()
  45.     {
  46.         return $this->providerKey;
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function getCredentials()
  52.     {
  53.         return $this->credentials;
  54.     }
  55.     /**
  56.      * {@inheritdoc}
  57.      */
  58.     public function eraseCredentials()
  59.     {
  60.         parent::eraseCredentials();
  61.         $this->credentials null;
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function __serialize(): array
  67.     {
  68.         return [$this->credentials$this->providerKeyparent::__serialize()];
  69.     }
  70.     /**
  71.      * {@inheritdoc}
  72.      */
  73.     public function __unserialize(array $data): void
  74.     {
  75.         [$this->credentials$this->providerKey$parentData] = $data;
  76.         $parentData = \is_array($parentData) ? $parentData unserialize($parentData);
  77.         parent::__unserialize($parentData);
  78.     }
  79. }