vendor/symfony/security-core/Authentication/Token/AnonymousToken.php line 32

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. * AnonymousToken represents an anonymous token.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. *
  17. * @deprecated since 5.4, anonymous is now represented by the absence of a token
  18. */
  19. class AnonymousToken extends AbstractToken
  20. {
  21. private $secret;
  22. /**
  23. * @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
  24. * @param string|\Stringable|UserInterface $user
  25. * @param string[] $roles
  26. */
  27. public function __construct(string $secret, $user, array $roles = [])
  28. {
  29. trigger_deprecation('symfony/security-core', '5.4', 'The "%s" class is deprecated.', __CLASS__);
  30. parent::__construct($roles);
  31. $this->secret = $secret;
  32. $this->setUser($user);
  33. // @deprecated since Symfony 5.4
  34. $this->setAuthenticated(true, false);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getCredentials()
  40. {
  41. return '';
  42. }
  43. /**
  44. * Returns the secret.
  45. *
  46. * @return string
  47. */
  48. public function getSecret()
  49. {
  50. return $this->secret;
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function __serialize(): array
  56. {
  57. return [$this->secret, parent::__serialize()];
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function __unserialize(array $data): void
  63. {
  64. [$this->secret, $parentData] = $data;
  65. $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
  66. parent::__unserialize($parentData);
  67. }
  68. }