|
|
@@ -45,7 +45,6 @@ public class CORSFilter implements Filter {
|
|
|
|
|
|
@Override
|
|
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
|
|
- log.warn("CORSFilter.doFilter start .....");
|
|
|
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
|
|
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
|
String requestPath = httpRequest.getRequestURI();
|
|
|
@@ -56,10 +55,12 @@ public class CORSFilter implements Filter {
|
|
|
}
|
|
|
|
|
|
// Host头验证
|
|
|
+ log.warn("-------Host头验证开始-------");
|
|
|
if(!validateHostHeader(httpRequest, response)){
|
|
|
log.warn("Host头验证白名单失败",ALLOWED_HOSTS);
|
|
|
return; // 验证失败已设置响应
|
|
|
}
|
|
|
+ log.warn("-------Host头验证结束-------");
|
|
|
// === Host头验证结束 ===
|
|
|
// response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
// response.setHeader("Access-Control-Max-Age", "3600");
|
|
|
@@ -67,19 +68,20 @@ public class CORSFilter implements Filter {
|
|
|
// response.setHeader("Access-Control-Allow-Credentials", "true");
|
|
|
// response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
|
|
|
/**Origin验证*/
|
|
|
+ log.warn("-------Origin头验证开始-------");
|
|
|
// 1. 获取请求的 Origin(跨域请求会带这个头)
|
|
|
String origin = httpRequest.getHeader("Origin");
|
|
|
|
|
|
// 2. 不存在启用的CORS跨域白名单配置,直接跳过
|
|
|
refreshHostWhitelistIfNeeded("CORS");
|
|
|
if(ALLOWED_CORSES.contains("N999999")){
|
|
|
- log.warn("没有配置参数:",ALLOWED_CORSES);
|
|
|
+ log.warn("没有配置参数1:",ALLOWED_CORSES);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
return;
|
|
|
}
|
|
|
//3.无Origin头(同源请求或非浏览器请求),跳过
|
|
|
if (origin == null) {
|
|
|
- log.warn("没有配置参数:",ALLOWED_CORSES);
|
|
|
+ log.warn("没有配置参数2:",ALLOWED_CORSES);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
return;
|
|
|
}
|
|
|
@@ -203,7 +205,7 @@ public class CORSFilter implements Filter {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.warn("拆分后newIPs的值为:{}",newIPs);
|
|
|
+ log.warn("拆分后newIPs的值为:{}---key值为{}",newIPs,key);
|
|
|
if("HOST".equals(key)){
|
|
|
refreshInterval_host = Long.parseLong((String)paramzlcs.get("can_shu_zhi_2_"));
|
|
|
lastRefreshTime_host = currentTime;
|
|
|
@@ -224,11 +226,13 @@ public class CORSFilter implements Filter {
|
|
|
ALLOWED_CORSES.clear();
|
|
|
ALLOWED_CORSES.add("N999999");
|
|
|
lastRefreshTime_cors = currentTime;
|
|
|
+ log.warn("没有启用参数,跳过CORS");
|
|
|
}
|
|
|
if("HOST".equals(key)){
|
|
|
ALLOWED_HOSTS.clear();
|
|
|
ALLOWED_HOSTS.add("N999999");
|
|
|
lastRefreshTime_host = currentTime;
|
|
|
+ log.warn("没有启用参数,跳过HOST");
|
|
|
}
|
|
|
//return;
|
|
|
}
|