CSRF Token has been associated to this client

最近在整合SpringCloud Gateway的时候出现了CSRF Token has been associated to this client 的问题,网上有很多的方法给出的结果实验出现问题,记录一下处理过程。

通过auth服务直接获取token是正常的:

通过网关调用 auth 认证服务出现CSRF Token has been associated to this client:

 参考网上的方案:

@EnableWebSecurity
public class GatewaySecurityConfigure   extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }
}

由于 SpringCloudGateway 使用的是webflux,所以这个地方需要使用 

EnableWebFluxSecurity 而不是 EnableWebSecurity,所以最终修改成了:
@Configuration
@EnableWebFluxSecurity
public class GatewaySecurityConfigure  {

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        //配置白名单和访问规则,CommonEnum枚举类
        http.csrf().disable();
        return http.build();
    }
}

处理后正常:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值