logout.adoc 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. [[test-logout]]
  2. = Testing Logout
  3. While fairly trivial using standard Spring MVC Test, you can use Spring Security's testing support to make testing log out easier.
  4. For example, the following `logout` xref:servlet/test/mockmvc/request-post-processors.adoc[`RequestPostProcessor`] will submit a POST to "/logout" with a valid CSRF token:
  5. [tabs]
  6. ======
  7. Java::
  8. +
  9. [source,java,role="primary"]
  10. ----
  11. mvc
  12. .perform(logout())
  13. ----
  14. Kotlin::
  15. +
  16. [source,kotlin,role="secondary"]
  17. ----
  18. mvc
  19. .perform(logout())
  20. ----
  21. ======
  22. You can also customize the URL to post to.
  23. For example, the snippet below will submit a POST to "/signout" with a valid CSRF token:
  24. [tabs]
  25. ======
  26. Java::
  27. +
  28. [source,java,role="primary"]
  29. ----
  30. mvc
  31. .perform(logout("/signout"))
  32. ----
  33. Kotlin::
  34. +
  35. [source,kotlin,role="secondary"]
  36. ----
  37. mvc
  38. .perform(logout("/signout"))
  39. ----
  40. ======