vendor/symfony/security/Core/Authentication/Token/AnonymousToken.php line 22

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\Role\Role;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14.  * AnonymousToken represents an anonymous token.
  15.  *
  16.  * @author Fabien Potencier <fabien@symfony.com>
  17.  */
  18. class AnonymousToken extends AbstractToken
  19. {
  20.     private $secret;
  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.      * @param string|\Stringable|UserInterface $user
  24.      * @param (Role|string)[]                  $roles
  25.      */
  26.     public function __construct($secret$user, array $roles = [])
  27.     {
  28.         parent::__construct($roles);
  29.         $this->secret $secret;
  30.         $this->setUser($user);
  31.         $this->setAuthenticated(true);
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function getCredentials()
  37.     {
  38.         return '';
  39.     }
  40.     /**
  41.      * Returns the secret.
  42.      *
  43.      * @return string
  44.      */
  45.     public function getSecret()
  46.     {
  47.         return $this->secret;
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function serialize()
  53.     {
  54.         $serialized = [$this->secretparent::serialize(true)];
  55.         return $this->doSerialize($serialized, \func_num_args() ? func_get_arg(0) : null);
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function unserialize($serialized)
  61.     {
  62.         list($this->secret$parentStr) = \is_array($serialized) ? $serialized unserialize($serialized);
  63.         parent::unserialize($parentStr);
  64.     }
  65. }