【发布时间】:2016-03-13 22:07:21
【问题描述】:
我正在尝试保护我的 web 应用程序,以便所有请求都需要使用 https 进行。我正在使用基于 Java 的配置,特别是我有一个扩展 WebSecurityConfigurerAdapter 的类。我尝试使用@Override protected void configure(HttpSecurity http) {} 方法配置我的安全性,详细说明here 和here。
我已经尝试了这两种方法以及配置HttpSecurity 对象的许多变体,以及几种身份验证变体。在几乎所有情况下,我都会提出以下问题:
[nio-8080-exec-2] o.a.coyote.http11.Http11NioProcessor : Error parsing HTTP request header
我尝试对此进行一些阅读,但很多搜索结果对我来说都是死胡同。我的假设是,在我引用的两篇文章中暗示的解决方案会给我大致正确的答案,但是在我可以让 https 工作之前我需要做任何额外的配置吗?如果是,那是什么,如果不是,我在这里错过了什么?
下面是我目前的配置,复制了上面描述的错误(基本上是默认的一加https通道):
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// Specify the authentication mechanisms that will allow user access to the site.
@Autowired
public void configureGlobal(AuthenticationManagerBuilder builder) throws Exception {
builder.inMemoryAuthentication()
.withUser("user").password("password").roles("ROLES_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic()
.and()
.requiresChannel().anyRequest().requiresSecure();
}
}
在前端我收到了SSL Connection Error : Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
【问题讨论】:
-
你能带我们看全班吗?
-
好的,编辑了原始帖子以包含整个配置
-
尝试将
super.configure(http);添加为configure的第一行。 -
您的安全配置看起来不错,我们可以查看您的控制器类吗?你确定里面一切正常吗?
-
您的服务器上是否配置了 https?如果您只指示 Spring Security 始终使用 Https,但没有为 https 设置您的服务器,那么它将无法正常工作。当您使用 Spring Boot(为您添加标签)时,这已记录在 here。
标签: java spring-security spring-boot