eureka整个SpringSecurity验证时因为csrf过滤了服务注册请求

这是因为 eureka开启安全策略后,在新版本的security中,添加了csrf过滤,任何一次服务请求默认都需要CSRF 的token,而Eureka-client不会生成该token,csrf将微服务的注册也给过滤了!故启动时会报如上错误。 此时则需要在注册中心中增加配置,将csrf过滤机制屏蔽

服务端自己重写WebSecurityConfigurerAdapter,客户端配置不变。

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Configure HttpSecurity as needed (e.g. enable http basic).
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        // 禁用CSRF保护
        http.csrf().disable();
        // 注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,如果是form方式,不能使用url格式登录
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}
```java

详细查看:https://blog.csdn.net/weixin_44128558/article/details/105766276
posted @ 2020-09-14 16:19  李成洪  阅读(704)  评论(0)    收藏  举报