vendor/symfony/security-http/Authenticator/Token/PostAuthenticationToken.php line 17

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\Http\Authenticator\Token;
  11. use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. class PostAuthenticationToken extends AbstractToken
  14. {
  15. private $firewallName;
  16. /**
  17. * @param string[] $roles An array of roles
  18. *
  19. * @throws \InvalidArgumentException
  20. */
  21. public function __construct(UserInterface $user, string $firewallName, array $roles)
  22. {
  23. parent::__construct($roles);
  24. if ('' === $firewallName) {
  25. throw new \InvalidArgumentException('$firewallName must not be empty.');
  26. }
  27. $this->setUser($user);
  28. $this->firewallName = $firewallName;
  29. // @deprecated since Symfony 5.4
  30. if (method_exists($this, 'setAuthenticated')) {
  31. // this token is meant to be used after authentication success, so it is always authenticated
  32. $this->setAuthenticated(true, false);
  33. }
  34. }
  35. /**
  36. * This is meant to be only a token, where credentials
  37. * have already been used and are thus cleared.
  38. *
  39. * {@inheritdoc}
  40. */
  41. public function getCredentials()
  42. {
  43. return [];
  44. }
  45. public function getFirewallName(): string
  46. {
  47. return $this->firewallName;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function __serialize(): array
  53. {
  54. return [$this->firewallName, parent::__serialize()];
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function __unserialize(array $data): void
  60. {
  61. [$this->firewallName, $parentData] = $data;
  62. parent::__unserialize($parentData);
  63. }
  64. }