RememberMeServicesInterface.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\RememberMe;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  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. const COOKIE_ATTR_NAME = '_security_remember_me_cookie';
  31. /**
  32. * This method will be called whenever the TokenStorage does not contain
  33. * a TokenInterface object and the framework wishes to provide an implementation
  34. * with an opportunity to authenticate the request using remember-me capabilities.
  35. *
  36. * No attempt whatsoever is made to determine whether the browser has requested
  37. * remember-me services or presented a valid cookie. Any and all such determinations
  38. * are left to the implementation of this method.
  39. *
  40. * If a browser has presented an unauthorised cookie for whatever reason,
  41. * make sure to throw an AuthenticationException as this will consequentially
  42. * result in a call to loginFail() and therefore an invalidation of the cookie.
  43. *
  44. * @return TokenInterface
  45. */
  46. public function autoLogin(Request $request);
  47. /**
  48. * Called whenever an interactive authentication attempt was made, but the
  49. * credentials supplied by the user were missing or otherwise invalid.
  50. *
  51. * This method needs to take care of invalidating the cookie.
  52. */
  53. public function loginFail(Request $request);
  54. /**
  55. * Called whenever an interactive authentication attempt is successful
  56. * (e.g. a form login).
  57. *
  58. * An implementation may always set a remember-me cookie in the Response,
  59. * although this is not recommended.
  60. *
  61. * Instead, implementations should typically look for a request parameter
  62. * (such as a HTTP POST parameter) that indicates the browser has explicitly
  63. * requested for the authentication to be remembered.
  64. */
  65. public function loginSuccess(Request $request, Response $response, TokenInterface $token);
  66. }