Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在使用WebSecurity.ignoring()时修复CORS_Java_Spring_Spring Boot_Spring Security_Jwt - Fatal编程技术网

Java 如何在使用WebSecurity.ignoring()时修复CORS

Java 如何在使用WebSecurity.ignoring()时修复CORS,java,spring,spring-boot,spring-security,jwt,Java,Spring,Spring Boot,Spring Security,Jwt,我正在通过JWT授权使用Spring构建一个平台。 在网关服务中,我有用于解析令牌的自定义筛选器(基于BasicAuthenticationFilter),但它应该仅对安全配置中标记为.authenticated()的路由调用,因此任何人都可以访问的路由被添加到WebSecurity.ignoring() 问题在于,将路径添加到WebSecurity.ignering()也会对其禁用CORS配置,OPTIONS请求不会返回Access Control-*头 @覆盖 受保护的无效配置(HttpSe

我正在通过JWT授权使用Spring构建一个平台。 在网关服务中,我有用于解析令牌的自定义筛选器(基于BasicAuthenticationFilter),但它应该仅对安全配置中标记为
.authenticated()
的路由调用,因此任何人都可以访问的路由被添加到
WebSecurity.ignoring()

问题在于,将路径添加到
WebSecurity.ignering()
也会对其禁用CORS配置,
OPTIONS
请求不会返回
Access Control-*

@覆盖
受保护的无效配置(HttpSecurity http)引发异常{
http.authorizeRequests()
//身份验证服务
.antMatchers(“/auth/login”,“/auth/renew”)
.permitAll()
.antMatchers(“/auth/logout”、“/auth/session/**”)
.authenticated()
//用户服务
.antMatchers(HttpMethod.POST,“/user/”)
.permitAll()
.antMatchers(“/user/confirm/**”、“/user/recover”、“/user/validate/**”)
.permitAll()
.antMatchers(“/user/”,“/user/change/**”)
.authenticated()
//路线的另一部分。。。
http
.formLogin()
.disable()
.logout()
.disable();
http.sessionManagement().sessionCreationPolicy(sessionCreationPolicy.STATELESS);
addFilter(新的JwtAuthenticationFilter(authenticationManager(),jwtKey));
http.csrf().disable();
http.cors();
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略
//身份验证服务
.antMatchers(“/auth/login”,“/auth/renew”)
//用户服务
.antMatchers(HttpMethod.POST,“/user/”)
.antMatchers(“/user/confirm/**”、“/user/recover”、“/user/validate/**”)
//路线的另一部分。。。
}
@豆子
CorsConfiguration源CorsConfiguration源(){
CorsConfiguration配置=新的CorsConfiguration();
配置。设置允许的来源(corsOrigins);
configuration.setAllowedMethods(Collections.singletonList(“*”));
configuration.setAllowedHeaders(Collections.singletonList(“*”));
UrlBasedCorsConfigurationSource=新的UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration(“/**”,配置);
返回源;
}
对于某些路径,有没有办法只绕过特定的过滤器

-已解决-

通过启用
WebMvc
并添加cors配置(以前的配置可能会被删除),我已经解决了我的问题

@覆盖
公共作废添加公司标志(公司注册处){
registry.addMapping(“/**”)
.允许的来源(”http://localhost:3000")
.允许的方法(“*”)
.允许的标题(“*”)
.allowCredentials(真)
.maxAge(3600);
}
您可以使用其中的一些并与我们分享一个。你的问题很有趣。可能是重复的