Spring boot 如何配置Spring Boot应用程序以接受未知的SSL客户端证书?

Spring boot 如何配置Spring Boot应用程序以接受未知的SSL客户端证书?,spring-boot,security,authentication,ssl,spring-security,Spring Boot,Security,Authentication,Ssl,Spring Security,我创建了一个具有双向SSL身份验证的Spring Boot 2应用程序。 简而言之,它归结为以下配置: @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests

我创建了一个具有双向SSL身份验证的Spring Boot 2应用程序。
简而言之,它归结为以下配置:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated()
                .and().x509();
    }
该应用程序具有密钥库/信任库,可与导入的客户端证书配合使用。
出乎意料的是,如果我尝试连接未知的客户端证书,由于SSL握手失败,连接无法建立。

但是,即使证书不被接受,我也希望访问应用程序层,并使用来自应用程序的HTTP响应进行响应


有什么方法可以实现这一点吗?

如果不需要在服务器端进行证书握手,这意味着,您不需要
SSL
。因此,请在配置文件中停用它:

server:
  ssl:
     enabled: false

PS:仅在
HTTP
协议中公开您的
REST
webservice是危险的。也许,在您的开发环境中进行这样的配置是有意义的。

回答我自己的问题:我可以使用Spring Boot属性

server.ssl.client-auth: want
而不是

server.ssl.client-auth: need
第一个选项仍然允许连接到tomcat,即使证书无效或不存在。然后该请求将被安全筛选器拒绝