http-basic.adoc 836 B

1234567891011121314151617181920212223242526272829303132
  1. = Testing HTTP Basic Authentication
  2. While it has always been possible to authenticate with HTTP Basic, it was a bit tedious to remember the header name, format, and encode the values.
  3. Now this can be done using Spring Security's `httpBasic` xref:servlet/test/mockmvc/request-post-processors.adoc[`RequestPostProcessor`].
  4. For example, the snippet below:
  5. [tabs]
  6. ======
  7. Java::
  8. +
  9. [source,java,role="primary"]
  10. ----
  11. mvc
  12. .perform(get("/").with(httpBasic("user","password")))
  13. ----
  14. Kotlin::
  15. +
  16. [source,kotlin,role="secondary"]
  17. ----
  18. mvc.get("/") {
  19. with(httpBasic("user","password"))
  20. }
  21. ----
  22. ======
  23. will attempt to use HTTP Basic to authenticate a user with the username "user" and the password "password" by ensuring the following header is populated on the HTTP Request:
  24. [source,text]
  25. ----
  26. Authorization: Basic dXNlcjpwYXNzd29yZA==
  27. ----