http-basic.adoc 819 B

1234567891011121314151617181920212223242526272829
  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. ====
  6. .Java
  7. [source,java,role="primary"]
  8. ----
  9. mvc
  10. .perform(get("/").with(httpBasic("user","password")))
  11. ----
  12. .Kotlin
  13. [source,kotlin,role="secondary"]
  14. ----
  15. mvc.get("/") {
  16. with(httpBasic("user","password"))
  17. }
  18. ----
  19. ====
  20. 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:
  21. [source,text]
  22. ----
  23. Authorization: Basic dXNlcjpwYXNzd29yZA==
  24. ----