禁用 webflux 安全性

sam*_*jee 2 spring-security spring-boot spring-webflux

有没有办法通过某些配置或 pom 修改来禁用 web-flux 安全性。现在我已经使用禁用它

  @Bean  public SecurityWebFilterChain securityWebFilterChain(final ServerHttpSecurity httpSecurity) {
return httpSecurity
        .authorizeExchange().anyExchange().permitAll().and()
        .build();  }
Run Code Online (Sandbox Code Playgroud)

这是在生产环境中执行此操作的最佳方法吗?每当我添加依赖项以从配置服务器读取值时,Spring Security 都会出现在类路径中,并且会出现弹出窗口。我不想要安全措施,因为我们有自己的安全措施。

Cia*_*rge 5

您可以使用仅在特定上下文中运行的配置/配置文件类,例如:

@Configuration
@Profile("dev")
public class SecurityConfig {
    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
        return http.authorizeExchange().anyExchange().permitAll().and().build();  
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,如果您希望将其作为应用程序的一部分运行,您可以运行:

mvn spring-boot:run -Dspring-boot.run.profiles=dev
Run Code Online (Sandbox Code Playgroud)

或者您可以将其包含在properties/yaml 文件中。希望这可以帮助。