Commit 6680e68e by yuquan.zhu Committed by chenzg

跨域

parent d23405ec
...@@ -5,6 +5,8 @@ import java.io.IOException; ...@@ -5,6 +5,8 @@ import java.io.IOException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
...@@ -12,12 +14,28 @@ import cn.hutool.json.JSONObject; ...@@ -12,12 +14,28 @@ import cn.hutool.json.JSONObject;
import cn.timer.api.utils.ResponseResult; import cn.timer.api.utils.ResponseResult;
//拦截登录失效的请求 //拦截登录失效的请求
@Component
public class RedisSessionInterceptor implements HandlerInterceptor { public class RedisSessionInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
// response.setHeader("Access-Control-Allow-Origin","http://120.24.24.239:8088");
//// response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));
// response.setHeader("Access-Control-Allow-Methods", "*");
// response.setHeader("Access-Control-Allow-Credentials", "true");
// response.setHeader("Access-Control-Allow-Headers", "*");
//
// System.out.print("request.Origin>"+request.getHeader("Origin"));
// //option预检查,直接通过请求
// if ("OPTIONS".equals(request.getMethod())){
// return true;
// }
/* /*
* Enumeration<String> names = request.getHeaderNames(); * Enumeration<String> names = request.getHeaderNames();
* while(names.hasMoreElements()) { String name = (String)names.nextElement(); * while(names.hasMoreElements()) { String name = (String)names.nextElement();
......
...@@ -80,13 +80,18 @@ public class WebSecurityConfig implements WebMvcConfigurer { ...@@ -80,13 +80,18 @@ public class WebSecurityConfig implements WebMvcConfigurer {
argumentResolvers.add(userMethodArgumentResolver); argumentResolvers.add(userMethodArgumentResolver);
} }
// @Override // @Override
// public void addCorsMappings(CorsRegistry registry) { // public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**") //// System.out.println("我是MyWebConfig跨域");
// .allowedOrigins("*") // //设置允许跨域的路径
// .allowCredentials(true) // registry.addMapping("/**")
// .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH") // //设置允许跨域请求的域名
// .maxAge(3600); // .allowedOrigins("*")
// //是否允许证书 不再默认开启
// .allowCredentials(true)
// //设置允许的方法
// .allowedMethods("*")
// //跨域允许时间
// .maxAge(3600);
// } // }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment