RememberMeServicesInterface.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Symfony\Component\Security\Http\RememberMe;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. /*
  7. * This file is part of the Symfony package.
  8. *
  9. * (c) Fabien Potencier <fabien@symfony.com>
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. /**
  15. * Interface that needs to be implemented by classes which provide remember-me
  16. * capabilities.
  17. *
  18. * We provide two implementations out-of-the-box:
  19. * - TokenBasedRememberMeServices (does not require a TokenProvider)
  20. * - PersistentTokenBasedRememberMeServices (requires a TokenProvider)
  21. *
  22. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  23. */
  24. interface RememberMeServicesInterface
  25. {
  26. /**
  27. * This attribute name can be used by the implementation if it needs to set
  28. * a cookie on the Request when there is no actual Response, yet.
  29. *
  30. * @var string
  31. */
  32. const COOKIE_ATTR_NAME = '_security_remember_me_cookie';
  33. /**
  34. * This method will be called whenever the SecurityContext does not contain
  35. * an TokenInterface object and the framework wishes to provide an implementation
  36. * with an opportunity to authenticate the request using remember-me capabilities.
  37. *
  38. * No attempt whatsoever is made to determine whether the browser has requested
  39. * remember-me services or presented a valid cookie. Any and all such determinations
  40. * are left to the implementation of this method.
  41. *
  42. * If a browser has presented an unauthorised cookie for whatever reason,
  43. * make sure to throw an AuthenticationException as this will consequentially
  44. * result in a call to loginFail() and therefore an invalidation of the cookie.
  45. *
  46. * @param Request $request
  47. *
  48. * @return TokenInterface
  49. */
  50. public function autoLogin(Request $request);
  51. /**
  52. * Called whenever an interactive authentication attempt was made, but the
  53. * credentials supplied by the user were missing or otherwise invalid.
  54. *
  55. * This method needs to take care of invalidating the cookie.
  56. *
  57. * @param Request $request
  58. */
  59. public function loginFail(Request $request);
  60. /**
  61. * Called whenever an interactive authentication attempt is successful
  62. * (e.g. a form login).
  63. *
  64. * An implementation may always set a remember-me cookie in the Response,
  65. * although this is not recommended.
  66. *
  67. * Instead, implementations should typically look for a request parameter
  68. * (such as a HTTP POST parameter) that indicates the browser has explicitly
  69. * requested for the authentication to be remembered.
  70. *
  71. * @param Request $request
  72. * @param Response $response
  73. * @param TokenInterface $token
  74. */
  75. public function loginSuccess(Request $request, Response $response, TokenInterface $token);
  76. }