私はSpring SecurityのSpring Bootアプリケーションを持っています。新しいエンドポイント/health
は、基本的なHTTP認証でアクセスできるように設定する必要があります。次のように現在のHttpSecurity
構成は次のとおりです。春のセキュリティを備えた特定のエンドポイントにHTTP基本認証を追加するにはどうすればよいですか?
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatchers()
.antMatchers(HttpMethod.OPTIONS, "/**")
.and()
.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.permitAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
私は/health
のベース認証を追加するにはどうすればよいですか?私はこのような何かを必要と理解し、私はこれは完全に正しいとは思わない、と正確にそれを追加する場所を私は本当に理解していない:
.authorizeRequests()
.antMatchers(
// Health status
"/health",
"/health/"
)
.hasRole(HEALTH_CHECK_ROLE)
.and()
.httpBasic()
.realmName(REALM_NAME)
.authenticationEntryPoint(getBasicAuthEntryPoint())
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
私はこれらのリソースが役立つことが判明したが、十分ではありません:
- http://www.baeldung.com/spring-security-basic-authentication
- http://websystique.com/spring-security/secure-spring-rest-api-using-basic-authentication/
'/ health/**'で試しましたか? –