Spring Boot和Spring Actuator - 禁用安全性

3

我正在使用spring-boot 1.3.1和spring-boot-actuator来开发我的应用程序。在pom.xml中,我使用spring-boot-starter-parent作为父级。

如果要禁用安全性,我需要在application.yml文件中添加两个条目。

security:
  basic:
    enabled: false
management:
  security:
    enabled: false

它仍未禁用基本安全性。当我在本地Tomcat中启动应用程序时,我在日志文件中看到了默认密码。

3个回答

3

基本安全功能已被禁用,但即使将 security.basic.enabled 设置为 false,Spring Boot 仍然使用默认的用户名/密码配置身份验证管理器。 但基本安全已被禁用。 您可以重新配置 authenticationManager 以覆盖此行为,例如以下方式:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    @Autowired
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                    .withUser("me").password("secret").roles("ADMIN");
    }
} 

2
如果存在Spring Security,您需要添加自定义安全配置以允许对端点进行未经身份验证的访问。例如:
如果 Spring Security 存在,则需要添加自定义安全配置,以允许对端点进行未经身份验证的访问。类似这样:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

//....

@Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(HttpMethod.GET, "/actuator/**");
        super.configure(web);
    }
}

1
您可以通过在application.yml中设置用户名和密码来阻止Spring Boot记录默认密码。
security:
  basic:
    enabled: false
  user:
    name: user
    password: ****

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接