| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | [[servlet-http]]= HTTPAll HTTP-based communication should be protected xref:features/exploits/http.adoc#http[using TLS].This section discusses the details of servlet-specific features that assist with HTTPS usage.[[servlet-http-redirect]]== Redirect to HTTPSIf a client makes a request using HTTP rather than HTTPS, you can configure Spring Security to redirect to HTTPS.For example, the following Java or Kotlin configuration redirects any HTTP requests to HTTPS:.Redirect to HTTPS====.Java[source,java,role="primary"]----@Configuration@EnableWebSecuritypublic class WebSecurityConfig extends		WebSecurityConfigurerAdapter {	@Override	protected void configure(HttpSecurity http) {		http			// ...			.requiresChannel(channel -> channel				.anyRequest().requiresSecure()			);	}}----.Kotlin[source,kotlin,role="secondary"]----@Configuration@EnableWebSecurityclass SecurityConfig : WebSecurityConfigurerAdapter() {    override fun configure(http: HttpSecurity) {        http {            // ...            requiresChannel {                secure(AnyRequestMatcher.INSTANCE, "REQUIRES_SECURE_CHANNEL")            }        }    }}----====The following XML configuration redirects all HTTP requests to HTTPS.Redirect to HTTPS with XML Configuration====[source,xml]----<http>	<intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/>...</http>----====[[servlet-hsts]]== Strict Transport SecuritySpring Security provides support for xref:servlet/exploits/headers.adoc#servlet-headers-hsts[Strict Transport Security] and enables it by default.[[servlet-http-proxy-server]]== Proxy Server ConfigurationSpring Security xref:features/exploits/http.adoc#http-proxy-server[integrates with proxy servers].
 |