2
0

http.adoc 1.7 KB

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