【发布时间】:2022-01-05 08:09:13
【问题描述】:
我有一个带有一些端点的 Spring Boot 应用程序
/.wellknown 不需要任何身份验证并且对公众开放
/callback 需要 mtls(仅证书认证)。
对于上述要求,我找不到确切的实现。大部分实现
-
find 在服务器级别启用 mtls - 这意味着所有 APIS 都已启用 mtls。
-
使用 X.509 证书检查来检查证书和用户数据(在我的情况下,不涉及用户数据 - 它是唯一的服务器到服务器 mtls)。
在下面找到代码
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/*
* Enables x509 client authentication.
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.x509()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf()
.disable();
// @formatter:on
}
/*
* Create an in-memory authentication manager. We create 1 user (localhost which
* is the CN of the client certificate) which has a role of USER.
*/
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("localhost").password("none").roles("USER");
}
}
请帮助如何实现相同的 -
-
/callback - 检查客户端是否提供证书并在信任库中可用
-
/.well-known/ No mtls check response without any check
【问题讨论】:
-
一种方法是对
/.well-known/仅使用HTTP,这样您就可以在服务器配置中启用mTLS。
标签: spring spring-boot spring-mvc spring-security spring-security-rest