1

我在我的 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());
}

}

4

1 回答 1

1

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

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

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

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

于 2016-08-09T19:52:12.387 回答