logout.adoc 805 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. ====
  6. .Java
  7. [source,java,role="primary"]
  8. ----
  9. mvc
  10. .perform(logout())
  11. ----
  12. .Kotlin
  13. [source,kotlin,role="secondary"]
  14. ----
  15. mvc
  16. .perform(logout())
  17. ----
  18. ====
  19. You can also customize the URL to post to.
  20. For example, the snippet below will submit a POST to "/signout" with a valid CSRF token:
  21. ====
  22. .Java
  23. [source,java,role="primary"]
  24. ----
  25. mvc
  26. .perform(logout("/signout"))
  27. ----
  28. .Kotlin
  29. [source,kotlin,role="secondary"]
  30. ----
  31. mvc
  32. .perform(logout("/signout"))
  33. ----
  34. ====