【问题标题】:spring-boot Actuator together with Spring Security and Form Basic Authspring-boot Actuator 连同 Spring Security 和 Form Basic Auth
【发布时间】:2016-10-02 03:26:28
【问题描述】:

我在我的 spring-boot 项目中添加了“spring-boot-starter-actuator”依赖项。

该项目已经具有基于表单的安全性。

应用程序的根上下文是“/”。

我通过添加到 application.yaml 中在上下文根“/actuators”添加了执行器:

管理: 上下文路径:/执行器

非敏感执行器正在工作,例如“健康”。

当我尝试访问敏感的执行器时,会出现用户名/密码的弹出窗口。进行了身份验证,但随后我看到“403”访问被拒绝。

这是网络安全的配置:

@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private AuthenticationLookupService authenticationLookupService;
private AuthenticationManagerBuilder authenticationManagerBuilder;
private UrlSuccessAuthenticationHandler successHandler;

@Autowired
public void setAuthenticationLookupService(AuthenticationLookupService authenticationLookupService) {
    this.authenticationLookupService = authenticationLookupService;
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
    this.authenticationManagerBuilder = auth;
}

@Autowired
public void setSuccessHandler(UrlSuccessAuthenticationHandler successHandler) {
    this.successHandler = successHandler;
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
            .antMatchers("/", "/index.html", "/auth/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/index.html").successHandler(successHandler)
            .permitAll()
            .and()
            .logout()
            .permitAll();

    http.csrf().disable(); // todo: fix later
}

@PostConstruct
public void process() throws Exception {
    this.authenticationManagerBuilder.userDetailsService(this.authenticationLookupService).passwordEncoder(new ShaPasswordEncoder());
}

}

【问题讨论】:

    标签: spring-security spring-boot spring-boot-actuator


    【解决方案1】:

    在 application.properties 或 application.yml 中添加以下值,然后在弹出窗口询问用户名和密码时提供此凭据

    security.user.name=admin
    security.user.password=secret
    

    如果您提供值,请检查该用户是否具有 ADMIN 角色,因为执行器需要 ADMIN 角色用户才能访问敏感端点。

    更新 如果你使用的是 spring-boot 1.5.*+ 那么用户应该有ACTUATOR 角色

    【讨论】:

    • 我认为这里只有关于 ADMIN 角色的部分实际上是相关的。
    • @Nikem 如果用户希望仅使用某些凭据访问执行器值,那么我们可以使用我在回答中告诉的方法进行限制
    猜你喜欢
    • 2019-01-20
    • 1970-01-01
    • 2020-06-21
    • 2013-07-13
    • 2015-03-10
    • 2020-09-15
    • 2020-11-09
    • 1970-01-01
    • 2019-01-17
    相关资源
    最近更新 更多