我有一个带Spring Security的Spring Boot应用程序./health
要配置新端点,以便可以通过基本HTTP身份验证进行访问.目前的HttpSecurity
配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatchers()
.antMatchers(HttpMethod.OPTIONS, "/**")
.and()
.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.permitAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
Run Code Online (Sandbox Code Playgroud)
}
如何为基础身份验证添加/health
?我想我需要这样的东西,但我不认为这是完全正确的,我真的不明白在哪里添加它:
.authorizeRequests()
.antMatchers(
// Health status
"/health",
"/health/"
)
.hasRole(HEALTH_CHECK_ROLE)
.and()
.httpBasic()
.realmName(REALM_NAME)
.authenticationEntryPoint(getBasicAuthEntryPoint())
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
Run Code Online (Sandbox Code Playgroud)
我发现这些资源很有用,但还不够:
有什么区别HttpSecurity
和antMatcher()
功能?
任何人都可以解释何时使用它们?