# HTTP
所有基于HTTP的通信都应该受到保护using TLS。
下面你可以找到有关 Servlet 特定特性的详细信息,这些特性有助于HTTPS的使用。
# 重定向到HTTPS
如果客户机使用HTTP而不是HTTPS发出请求,则可以将安全性配置为重定向到HTTPS。
例如,以下 Java 配置将把任何HTTP请求重定向到HTTPS:
例1.重定向到HTTPS
Java
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) {
http
// ...
.requiresChannel(channel -> channel
.anyRequest().requiresSecure()
);
}
}
Kotlin
@Configuration
@EnableWebSecurity
class SecurityConfig : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http {
// ...
requiresChannel {
secure(AnyRequestMatcher.INSTANCE, "REQUIRES_SECURE_CHANNEL")
}
}
}
}
下面的XML配置将把所有HTTP请求重定向到HTTPS
例2.使用XML配置重定向到HTTPS
<http>
<intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/>
...
</http>
# 严格的运输安全
Spring 安全性为严格的运输安全提供支持,并在默认情况下启用它。
# 代理服务器配置
Spring 安全性与代理服务器集成。