http.adoc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. [[servlet-http]]
  2. = HTTP
  3. All HTTP based communication should be protected xref:features/exploits/http.adoc#http[using TLS].
  4. Below you can find details around Servlet specific features that assist with HTTPS usage.
  5. [[servlet-http-redirect]]
  6. == Redirect to HTTPS
  7. If a client makes a request using HTTP rather than HTTPS, Spring Security can be configured to redirect to HTTPS.
  8. For example, the following Java configuration will redirect any HTTP requests to HTTPS:
  9. .Redirect to HTTPS
  10. [tabs]
  11. ======
  12. Java::
  13. +
  14. [source,java,role="primary"]
  15. ----
  16. @Configuration
  17. @EnableWebSecurity
  18. public class WebSecurityConfig extends
  19. WebSecurityConfigurerAdapter {
  20. @Override
  21. protected void configure(HttpSecurity http) {
  22. http
  23. // ...
  24. .requiresChannel(channel -> channel
  25. .anyRequest().requiresSecure()
  26. );
  27. }
  28. }
  29. ----
  30. Kotlin::
  31. +
  32. [source,kotlin,role="secondary"]
  33. ----
  34. @Configuration
  35. @EnableWebSecurity
  36. class SecurityConfig : WebSecurityConfigurerAdapter() {
  37. override fun configure(http: HttpSecurity) {
  38. http {
  39. // ...
  40. requiresChannel {
  41. secure(AnyRequestMatcher.INSTANCE, "REQUIRES_SECURE_CHANNEL")
  42. }
  43. }
  44. }
  45. }
  46. ----
  47. ======
  48. The following XML configuration will redirect all HTTP requests to HTTPS
  49. .Redirect to HTTPS with XML Configuration
  50. [source,xml]
  51. ----
  52. <http>
  53. <intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/>
  54. ...
  55. </http>
  56. ----
  57. [[servlet-hsts]]
  58. == Strict Transport Security
  59. Spring Security provides support for xref:servlet/exploits/headers.adoc#servlet-headers-hsts[Strict Transport Security] and enables it by default.
  60. [[servlet-http-proxy-server]]
  61. == Proxy Server Configuration
  62. Spring Security xref:features/exploits/http.adoc#http-proxy-server[integrates with proxy servers].