vendor/symfony/security-guard/Token/PostAuthenticationGuardToken.php line 29

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\Guard\Token;
  11. use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. trigger_deprecation('symfony/security-guard', '5.3', 'The "%s" class is deprecated, use the new authenticator system instead.', PostAuthenticationGuardToken::class);
  14. /**
  15. * Used as an "authenticated" token, though it could be set to not-authenticated later.
  16. *
  17. * If you're using Guard authentication, you *must* use a class that implements
  18. * GuardTokenInterface as your authenticated token (like this class).
  19. *
  20. * @author Ryan Weaver <ryan@knpuniversity.com>
  21. *
  22. * @deprecated since Symfony 5.3, use the new authenticator system instead
  23. */
  24. class PostAuthenticationGuardToken extends AbstractToken implements GuardTokenInterface
  25. {
  26. private $providerKey;
  27. /**
  28. * @param string $providerKey The provider (firewall) key
  29. * @param string[] $roles An array of roles
  30. *
  31. * @throws \InvalidArgumentException
  32. */
  33. public function __construct(UserInterface $user, string $providerKey, array $roles)
  34. {
  35. parent::__construct($roles);
  36. if (empty($providerKey)) {
  37. throw new \InvalidArgumentException('$providerKey (i.e. firewall key) must not be empty.');
  38. }
  39. $this->setUser($user);
  40. $this->providerKey = $providerKey;
  41. // this token is meant to be used after authentication success, so it is always authenticated
  42. // you could set it as non authenticated later if you need to
  43. $this->setAuthenticated(true, false);
  44. }
  45. /**
  46. * This is meant to be only an authenticated token, where credentials
  47. * have already been used and are thus cleared.
  48. *
  49. * {@inheritdoc}
  50. */
  51. public function getCredentials()
  52. {
  53. return [];
  54. }
  55. /**
  56. * Returns the provider (firewall) key.
  57. *
  58. * @return string
  59. */
  60. public function getProviderKey()
  61. {
  62. return $this->providerKey;
  63. }
  64. public function getFirewallName(): string
  65. {
  66. return $this->getProviderKey();
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function __serialize(): array
  72. {
  73. return [$this->providerKey, parent::__serialize()];
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function __unserialize(array $data): void
  79. {
  80. [$this->providerKey, $parentData] = $data;
  81. $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
  82. parent::__unserialize($parentData);
  83. }
  84. }