From ce954232b5f4d99bbbf39cd99e31f6d475ccf974 Mon Sep 17 00:00:00 2001 From: 623756217 <623756217@qq.com> Date: Tue, 27 Dec 2022 11:58:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0CrossConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../softbot/config/AdminInterceptor.java | 42 +++++++++--------- .../gitlink/softbot/config/CrossConfig.java | 34 ++++++++++++++ .../controller/user/UserController.class | Bin 14824 -> 14824 bytes 3 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/gitlink/softbot/config/CrossConfig.java diff --git a/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java b/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java index f1a1e5f..c12f46b 100644 --- a/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java +++ b/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java @@ -1,21 +1,21 @@ -package com.gitlink.softbot.config; - -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@Component -public class AdminInterceptor extends OncePerRequestFilter { - - @Override - protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { - httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); - httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD,PATCH"); - filterChain.doFilter(httpServletRequest, httpServletResponse); - } -} +//package com.gitlink.softbot.config; +// +//import org.springframework.stereotype.Component; +//import org.springframework.web.filter.OncePerRequestFilter; +// +//import javax.servlet.FilterChain; +//import javax.servlet.ServletException; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +// +//@Component +//public class AdminInterceptor extends OncePerRequestFilter { +// +// @Override +// protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { +// httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); +// httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD,PATCH"); +// filterChain.doFilter(httpServletRequest, httpServletResponse); +// } +//} diff --git a/src/main/java/com/gitlink/softbot/config/CrossConfig.java b/src/main/java/com/gitlink/softbot/config/CrossConfig.java new file mode 100644 index 0000000..861e737 --- /dev/null +++ b/src/main/java/com/gitlink/softbot/config/CrossConfig.java @@ -0,0 +1,34 @@ +package com.gitlink.softbot.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * ClassName CrossConfig + * + * @author ZengWei + * Date 2021/7/15 + */ + +@Configuration +public class CrossConfig { + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + corsConfiguration.setMaxAge(3600L); // 预检请求的有效期,单位为秒。 + corsConfiguration.setAllowCredentials(true);// 是否支持安全证书(必需参数) + return corsConfiguration; + } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } +} diff --git a/target/classes/com/gitlink/softbot/controller/user/UserController.class b/target/classes/com/gitlink/softbot/controller/user/UserController.class index c8738f550cf4b5e238039819e47b964163703f48..e3264233443f85fee361462f03235869b4305de4 100644 GIT binary patch delta 191 zcmaD+{Gxb6j3Ms~1}=t~48jbv7~~mdPkv~kIJwL424`KoM*I< zb0bh>6Hwje$%Pi;ll6^va_$3)><6kj095ms_Y}~a(?Iz%Ky%Il&3Vds9VmYTD1Q@d z#xv9PoR5JbPk4`KoM*I< za}!WxGf>@@$%Pi;ll6^va_$F;900002vqZ!_cYL)GeG&XKy%Ik&3Vds11NtJD1QrV z#xv9PoKJuvPk|!Oz#?1Cc5!}U;Ai;EAi?lua)tQ=$$t#o4F4H~85tNv85tR*8JQTA b8JQW>7#V