gpt4 book ai didi

java - 如何使用 spring security 为特定端点添加 HTTP 基本身份验证?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:21:17 24 4
gpt4 key购买 nike

我有一个带有 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);

如何为 /health 添加基本身份验证?我想我需要这样的东西,但我不认为这是完全正确的,而且我真的不明白应该在哪里添加它:

    .authorizeRequests()
.antMatchers(
// Health status
"/health",
"/health/"
)
.hasRole(HEALTH_CHECK_ROLE)
.and()
.httpBasic()
.realmName(REALM_NAME)
.authenticationEntryPoint(getBasicAuthEntryPoint())
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)

我发现这些资源很有帮助,但还不够:

最佳答案

关于java - 如何使用 spring security 为特定端点添加 HTTP 基本身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43524211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com