2
0

http.adoc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ====
  11. .Java
  12. [source,java,role="primary"]
  13. ----
  14. @Configuration
  15. @EnableWebSecurity
  16. public class WebSecurityConfig {
  17. @Bean
  18. public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
  19. http
  20. // ...
  21. .requiresChannel(channel -> channel
  22. .anyRequest().requiresSecure()
  23. );
  24. return http.build();
  25. }
  26. }
  27. ----
  28. .Kotlin
  29. [source,kotlin,role="secondary"]
  30. ----
  31. @Configuration
  32. @EnableWebSecurity
  33. class SecurityConfig {
  34. @Bean
  35. open fun filterChain(http: HttpSecurity): SecurityFilterChain {
  36. http {
  37. // ...
  38. requiresChannel {
  39. secure(AnyRequestMatcher.INSTANCE, "REQUIRES_SECURE_CHANNEL")
  40. }
  41. }
  42. return http.build()
  43. }
  44. }
  45. ----
  46. ====
  47. The following XML configuration will redirect all HTTP requests to HTTPS
  48. .Redirect to HTTPS with XML Configuration
  49. ====
  50. [source,xml]
  51. ----
  52. <http>
  53. <intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/>
  54. ...
  55. </http>
  56. ----
  57. ====
  58. [[servlet-hsts]]
  59. == Strict Transport Security
  60. Spring Security provides support for xref:servlet/exploits/headers.adoc#servlet-headers-hsts[Strict Transport Security] and enables it by default.
  61. [[servlet-http-proxy-server]]
  62. == Proxy Server Configuration
  63. Spring Security xref:features/exploits/http.adoc#http-proxy-server[integrates with proxy servers].