vendor/symfony/security-core/Authentication/Token/SwitchUserToken.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.  * Token representing a user who temporarily impersonates another one.
  14.  *
  15.  * @author Christian Flothmann <[email protected]>
  16.  */
  17. class SwitchUserToken extends UsernamePasswordToken
  18. {
  19.     private $originalToken;
  20.     private ?string $originatedFromUri null;
  21.     /**
  22.      * @param $user              The username (like a nickname, email address, etc.), or a UserInterface instance or an object implementing a __toString method
  23.      * @param $originatedFromUri The URI where was the user at the switch
  24.      *
  25.      * @throws \InvalidArgumentException
  26.      */
  27.     public function __construct(UserInterface $userstring $firewallName, array $rolesTokenInterface $originalTokenstring $originatedFromUri null)
  28.     {
  29.         parent::__construct($user$firewallName$roles);
  30.         $this->originalToken $originalToken;
  31.         $this->originatedFromUri $originatedFromUri;
  32.     }
  33.     public function getOriginalToken(): TokenInterface
  34.     {
  35.         return $this->originalToken;
  36.     }
  37.     public function getOriginatedFromUri(): ?string
  38.     {
  39.         return $this->originatedFromUri;
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function __serialize(): array
  45.     {
  46.         return [$this->originalToken$this->originatedFromUriparent::__serialize()];
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function __unserialize(array $data): void
  52.     {
  53.         if (\count($data)) {
  54.             // Support for tokens serialized with version 5.1 or lower of symfony/security-core.
  55.             [$this->originalToken$parentData] = $data;
  56.         } else {
  57.             [$this->originalToken$this->originatedFromUri$parentData] = $data;
  58.         }
  59.         $parentData \is_array($parentData) ? $parentData unserialize($parentData);
  60.         parent::__unserialize($parentData);
  61.     }
  62. }