【问题标题】:Spring webflux Security - Disable csrf with propertySpring webflux Security - 使用属性禁用 csrf
【发布时间】:2021-05-06 07:32:38
【问题描述】:

我有一个如下的 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();
}

【问题讨论】:

    标签: java spring-security spring-webflux


    【解决方案1】:

    你只需添加如下内容:

    // All your stuff up here then
    
    if(!csrfEnabled) {
        http.csrf().disable();
    }
    
    return http.build();
    

    【讨论】:

      猜你喜欢
      • 2022-12-15
      • 2020-05-09
      • 2018-12-12
      • 1970-01-01
      • 2014-04-26
      • 2015-09-27
      • 2019-09-27
      • 2016-07-21
      相关资源
      最近更新 更多