Spring boot 具有X509身份验证的管理端口和服务器端口
我有一个通过x509验证的API。但是,我需要绕过执行器健康检查端点进行身份验证,这样我就可以在没有客户端证书的情况下进行健康检查 我意识到这可以通过为服务器和管理使用不同的端口来实现,执行器端点将命中这些端口 My application.yml配置如下:Spring boot 具有X509身份验证的管理端口和服务器端口,spring-boot,spring-boot-actuator,Spring Boot,Spring Boot Actuator,我有一个通过x509验证的API。但是,我需要绕过执行器健康检查端点进行身份验证,这样我就可以在没有客户端证书的情况下进行健康检查 我意识到这可以通过为服务器和管理使用不同的端口来实现,执行器端点将命中这些端口 My application.yml配置如下: server: port: 9000 ssl: key-store: classpath:keystore.jks key-store-password: password key-password: pas
server:
port: 9000
ssl:
key-store: classpath:keystore.jks
key-store-password: password
key-password: password
enabled: true
trust-store: classpath:truststore.jks
trust-store-password: password
client-auth: need
management:
server:
port: 9010
ssl:
enabled: false
security:
enabled: false
我的问题是,即使使用这种配置,管理端点也不是我可以访问健康端点的地方。
http://localhost:9010/health -->这不管用
我仍然可以通过服务器端口和证书访问它。
https://localhost:9000/health -->这很有效
我的安全配置如下:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.x509()
.subjectPrincipalRegex("CN=(.*?)(?:,|$)")
.userDetailsService(userDetailsService())
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER)
.and()
.csrf().disable();
}
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsService() {
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
if (username.equals("user")) {
return new User(username, "", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
}
throw new UsernameNotFoundException("User not found!");
}
};
}
我的pom中有spring boot执行器依赖项。我不明白为什么我的管理端口不工作
有什么建议吗?我发现这里出了什么问题。这是春季启动依赖性。我正在使用spring boot actuator,当我将其更改为spring boot starter actuator时,管理端口开始侦听我配置的端口。然后,我禁用了该端口上的SSL身份验证。在下面提供我的配置,以便对其他人有所帮助:
management:
server:
port: 8000
ssl:
enabled: false
server:
port: 9000
ssl:
key-store: classpath:keystore.jks
key-store-password: password
key-alias: alias
key-password: password
enabled: true
trust-store: classpath:truststore.jks
trust-store-password: password
client-auth: need
现在,我可以使用有效的客户端证书通过http在端口8000上访问我的执行器端点,如health,通过https在端口9000上访问我的应用程序rest API。当您尝试访问
http://localhost:9010/health
?什么都没有,这是最奇怪的部分,当你试图到达终点时,你有没有得到任何回应?(例如403状态代码或错误消息)我得到“连接被拒绝”Ok,这表明它根本没有打开端口9010。不知道为什么;你的application.yml看起来不错。