TokenInterface.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * TokenInterface is the interface for the user authentication information.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  17. */
  18. interface TokenInterface extends \Serializable
  19. {
  20. /**
  21. * Returns a string representation of the Token.
  22. *
  23. * This is only to be used for debugging purposes.
  24. *
  25. * @return string
  26. */
  27. public function __toString();
  28. /**
  29. * Returns the user roles.
  30. *
  31. * @return string[] The associated roles
  32. */
  33. public function getRoleNames(): array;
  34. /**
  35. * Returns the user credentials.
  36. *
  37. * @return mixed The user credentials
  38. */
  39. public function getCredentials();
  40. /**
  41. * Returns a user representation.
  42. *
  43. * @return string|\Stringable|UserInterface
  44. *
  45. * @see AbstractToken::setUser()
  46. */
  47. public function getUser();
  48. /**
  49. * Sets the user in the token.
  50. *
  51. * The user can be a UserInterface instance, or an object implementing
  52. * a __toString method or the username as a regular string.
  53. *
  54. * @param string|\Stringable|UserInterface $user
  55. *
  56. * @throws \InvalidArgumentException
  57. */
  58. public function setUser($user);
  59. /**
  60. * Returns the username.
  61. *
  62. * @return string
  63. */
  64. public function getUsername();
  65. /**
  66. * Returns whether the user is authenticated or not.
  67. *
  68. * @return bool true if the token has been authenticated, false otherwise
  69. */
  70. public function isAuthenticated();
  71. /**
  72. * Sets the authenticated flag.
  73. */
  74. public function setAuthenticated(bool $isAuthenticated);
  75. /**
  76. * Removes sensitive information from the token.
  77. */
  78. public function eraseCredentials();
  79. /**
  80. * Returns the token attributes.
  81. *
  82. * @return array The token attributes
  83. */
  84. public function getAttributes();
  85. /**
  86. * Sets the token attributes.
  87. *
  88. * @param array $attributes The token attributes
  89. */
  90. public function setAttributes(array $attributes);
  91. /**
  92. * Returns true if the attribute exists.
  93. *
  94. * @return bool true if the attribute exists, false otherwise
  95. */
  96. public function hasAttribute(string $name);
  97. /**
  98. * Returns an attribute value.
  99. *
  100. * @return mixed The attribute value
  101. *
  102. * @throws \InvalidArgumentException When attribute doesn't exist for this token
  103. */
  104. public function getAttribute(string $name);
  105. /**
  106. * Sets an attribute.
  107. *
  108. * @param mixed $value The attribute value
  109. */
  110. public function setAttribute(string $name, $value);
  111. /**
  112. * Returns all the necessary state of the object for serialization purposes.
  113. */
  114. public function __serialize(): array;
  115. /**
  116. * Restores the object state from an array given by __serialize().
  117. */
  118. public function __unserialize(array $data): void;
  119. }