相关疑难解决方法(0)

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

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

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

java security spring http

10
推荐指数
2
解决办法
8819
查看次数

AntMatcher和MvcMatcher之间的区别

有什么区别HttpSecurityantMatcher()功能?

任何人都可以解释何时使用它们?

spring spring-security

9
推荐指数
3
解决办法
1914
查看次数

标签 统计

spring ×2

http ×1

java ×1

security ×1

spring-security ×1