springcloud gateway 针对某些路由跳过全局过滤器,有什么方法吗?
请问各位大佬,springcloud gateway 针对某些路由跳过全局过滤器,有什么方法吗?
网上看了一些方法,都是向请求的 attributes 里放参数,然后全局过滤器依据这些参数决定做不做鉴权,我觉得不太安全(恶意请求也可以向请求头里面放这些参数),请问有什么比较好的方法?
请问各位大佬,springcloud gateway 针对某些路由跳过全局过滤器,有什么方法吗?
网上看了一些方法,都是向请求的 attributes 里放参数,然后全局过滤器依据这些参数决定做不做鉴权,我觉得不太安全(恶意请求也可以向请求头里面放这些参数),请问有什么比较好的方法?
private String[] excludesUrls;
public String[] getExcludesUrls() {
return excludesUrls;
}
public void setExcludesUrls(String[] excludesUrls) {
this.excludesUrls = excludesUrls;
}
}
添加不鉴权的接口
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable();
http.csrf().disable()
.authorizeRequests()
.antMatchers(“/test/**”, “swagger-ui**”).permitAll()
.and().addFilterBefore(new TokenAuthFilter(permissionClient, redisService,
new String[]{“/api/**”},
excludesUrls.getExcludesUrls()),
UsernamePasswordAuthenticationFilter.class);
}
当然 TokenAuthFilter 继承 GenericFilterBean 实现的
不难的
配置中心的配置文件
gateway:
excludesUrls:
– /api/user/auth/**
– /api/cms/content/editorUpload
– /api/file/downloadFileByUri
– /api/file/previewFileByUri