添加一些新的回答,我假设所有人都在使用actuator,如果没有,我打赌一个类排除就足够了。我通过属性成功地禁用了它:
spring:
autoconfigure:
exclude: ${spring.autoconfigure.sac}, ${spring.autoconfigure.mwsas}
sac: org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
mwsas: org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
我通过属性引用了两个自动配置类,以保持长度不变(请注意,如果您像这样引用它,IntelliJ Ultimate会因为不知道这些占位值是什么以及它们是否真的合法而发出警告,所以如果这使您感到烦恼,请内联处理)。
然而,应用程序并不像https://www.baeldung.com/spring-boot-security-autoconfiguration所声称的那样在启动时失败,只需要禁用 SecurityAutoConfiguration
即可。
如果它确实起作用,您将不再看到自动生成的密码,这比接受的答案稍微少一点混乱,因为开发人员在阅读日志时不会因基本验证生成的密码而感到困惑,而安全性则允许所有人。
仅禁用主要自动配置类是不够的原因是因为有这个家伙:
@Configuration
class ManagementWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers(
EndpointRequest.to(HealthEndpoint.class, InfoEndpoint.class))
.permitAll().anyRequest().authenticated().and().formLogin().and()
.httpBasic();
}
}
之前我们做了很多工作来分离执行器和安全配置,这让我们都感到困惑,现在更加直观易懂了,但还是存在这样的构件。如果我说错了,Spring 开发人员可以纠正我 :-)
@EnableWebFlux
会有效地禁用所有 WebFlux 自动配置。这是您打算做的吗? - Brian Clozel@EnableWebFlux
会启用 WebFlux...但是我发现即使将其删除,Web服务器仍然会启动,但基本安全性仍然被启用。 - Jan Wytze