当前位置: 首页 > 知识库问答 >
问题:

Spring webflux安全-使用属性禁用csrf

凤凡
2023-03-14

我有一个Spring WebFlux安全性,如下所示,并希望使用属性控制CSRF。我如何在这里单独添加CSRF检查?

@Bean
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
    return http.authorizeExchange().matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
        //.pathMatchers("/register", "/login").permitAll()
        .anyExchange().authenticated()
        .and().formLogin()
        .securityContextRepository(securityContextRepository())
        .and()
        .exceptionHandling()
        .accessDeniedHandler(new HttpStatusServerAccessDeniedHandler(HttpStatus.BAD_REQUEST))
        .and().csrf().disable()
        .build();
}

共有1个答案

林意蕴
2023-03-14

您只需添加以下内容:

// All your stuff up here then

if(!csrfEnabled) {
    http.csrf().disable();
}

return http.build();
 类似资料:
  • 当我使用security.basic.enabled=false在具有以下依赖项的Spring Boot项目上禁用安全性时: 为了修复此异常,我必须添加属性-management.security.enabled=false。我的理解是,当执行器在类路径中时,应该将security.basic.enabled=false和management.security.enabled=false设置为禁用

  • 我使用spring boot版本“1.3.0.M5”(我也尝试了版本“1.2.5.Release”)。我添加了Spring Security性:

  • 如何在我的Spring boot应用程序中禁用oauth2安全过滤,或者跳过安全检查,我只想直接点击Spring boot@RestController中的GET和POSTendpoint,而不经过安全过滤。 我正在使用以下配置 Spring版本

  • 我正在使用Spring Boot安全性和Oauth2。我不想禁用健康endpoint的安全性。 我可以完全禁用安全性,或者编写自己的实现并禁用autoconfigured One。 但是如何修改()的现有实现? 我试图创建自己的配置而不禁用AutoConfigurated一个,但由于冲突,这是不可能的。 以下是错误消息: 此外,我试图显式地为我自己的安全配置设置更高的顺序,但看起来自动配置的一个覆

  • 我正在使用Activiti7,我想禁用activiti安全性。我尝试重写WebSecurityConfigurerAdapter配置方法,但它不起作用

  • 我想使用Spring Security进行JWT身份验证。但它带有默认身份验证。我正在尝试禁用它,但在2.0中不推荐使用旧的方法--通过禁用它。 这是我尝试过的: 我怎么能简单地禁用基本安全? 更新 知道我使用的不是web mvc而是web Flux可能会很高兴。