UserInterface.php 2.4 KB

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