spring boot执行器端点安全性不适用于spring boot 1.5.22

pcww981p  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(226)

每当我试图访问spring启动执行器url端点时,我都会收到401–未经授权的错误。
我将spring boot启动器端点安全性与spring boot 1.5.22和spring boot starter安全性1.5.22(spring security.4.2.13)一起使用
代码看起来像

@Configuration
@EnableWebSecurity
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(ActuatorSecurityConfig.class);

    private static final String ADMIN_ACTUATOR="ADMIN_ACTUATOR";

    @Override
    protected void configure(AuthenticationManagerBuilder authBuilder) throws Exception {
        authBuilder.inMemoryAuthentication().withUser("mfadmin").password("{noop}"+"mfAdmin@123").roles(ADMIN_ACTUATOR);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // secure all endpoints with basic auth
        http.authorizeRequests()
                .antMatchers("/**") .permitAll()
                 .antMatchers("/beans","/env","/info").hasRole(ADMIN_ACTUATOR)
                 .and().httpBasic()
                .and().csrf().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    }

 }

应用程序属性包含

management.security.enabled=true
endpoints.health.sensitive=false
management.endpoint.health.show-details=ALWAYS
management.endpoints.web.exposure.include=*

每当我访问bean和env-spring-activator-url端点时,它都不会请求身份验证,并且会抛出一个类似下面的错误。然而,信息和健康工作良好,它不会要求身份验证,即使对于信息url,我期待身份验证。
所以我不确定我错过了什么。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题