UserInterface.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\User;
  11. /**
  12. * Represents the interface that all user classes must implement.
  13. *
  14. * This interface is useful because the authentication layer can deal with
  15. * the object through its lifecycle, using the object to get the encoded
  16. * password (for checking against a submitted password), assigning roles
  17. * and so on.
  18. *
  19. * Regardless of how your users are loaded or where they come from (a database,
  20. * configuration, web service, etc.), you will have a class that implements
  21. * this interface. Objects that implement this interface are created and
  22. * loaded by different objects that implement UserProviderInterface.
  23. *
  24. * @see UserProviderInterface
  25. *
  26. * @author Fabien Potencier <fabien@symfony.com>
  27. */
  28. interface UserInterface
  29. {
  30. /**
  31. * Returns the roles granted to the user.
  32. *
  33. * public function getRoles()
  34. * {
  35. * return ['ROLE_USER'];
  36. * }
  37. *
  38. * Alternatively, the roles might be stored on a ``roles`` property,
  39. * and populated in any number of different ways when the user object
  40. * is created.
  41. *
  42. * @return string[] The user roles
  43. */
  44. public function getRoles();
  45. /**
  46. * Returns the password used to authenticate the user.
  47. *
  48. * This should be the encoded password. On authentication, a plain-text
  49. * password will be salted, encoded, and then compared to this value.
  50. *
  51. * @return string|null The encoded password if any
  52. */
  53. public function getPassword();
  54. /**
  55. * Returns the salt that was originally used to encode the password.
  56. *
  57. * This can return null if the password was not encoded using a salt.
  58. *
  59. * @return string|null The salt
  60. */
  61. public function getSalt();
  62. /**
  63. * Returns the username used to authenticate the user.
  64. *
  65. * @return string The username
  66. */
  67. public function getUsername();
  68. /**
  69. * Removes sensitive data from the user.
  70. *
  71. * This is important if, at any given point, sensitive information like
  72. * the plain-text password is stored on this object.
  73. */
  74. public function eraseCredentials();
  75. }