3

我在我的应用程序中使用 spring-boot 1.3.1 和 spring-boot-actuator。我spring-boot-starter-parentpom.xml.

为了禁用安全性,我在我的application.yml.

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

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

4

3 回答 3

3

基本安全性被禁用,但 Spring Boot 使用默认用户/密码配置身份验证管理器,即使设置security.basic.enabledfalse. 但是基本安全被禁用。您可以重新配置authenticationManager以覆盖此行为,如下所示:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    @Autowired
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                    .withUser("me").password("secret").roles("ADMIN");
    }
} 
于 2016-01-26T21:55:41.790 回答
1

如果存在 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);
    }
}
于 2021-03-25T15:04:03.430 回答
1

您可以通过在 application.yml 中设置用户名/密码来停止 spring boot 以记录默认密码 -

security:
  basic:
    enabled: false
  user:
    name: user
    password: ****
于 2016-09-28T07:14:40.870 回答