|
|
@@ -45,6 +45,7 @@ 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,6 +57,7 @@ public class CORSFilter implements Filter {
|
|
|
|
|
|
// Host头验证
|
|
|
if(!validateHostHeader(httpRequest, response)){
|
|
|
+ log.warn("Host头验证白名单失败",ALLOWED_HOSTS);
|
|
|
return; // 验证失败已设置响应
|
|
|
}
|
|
|
// === Host头验证结束 ===
|
|
|
@@ -71,11 +73,13 @@ public class CORSFilter implements Filter {
|
|
|
// 2. 不存在启用的CORS跨域白名单配置,直接跳过
|
|
|
refreshHostWhitelistIfNeeded("CORS");
|
|
|
if(ALLOWED_CORSES.contains("N999999")){
|
|
|
+ log.warn("没有配置参数:",ALLOWED_CORSES);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
return;
|
|
|
}
|
|
|
//3.无Origin头(同源请求或非浏览器请求),跳过
|
|
|
if (origin == null) {
|
|
|
+ log.warn("没有配置参数:",ALLOWED_CORSES);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
return;
|
|
|
}
|
|
|
@@ -90,6 +94,7 @@ public class CORSFilter implements Filter {
|
|
|
|
|
|
if (requestDomain.equals(currentDomain)) {
|
|
|
// 情况2:同源请求(协议+域名相同,端口不同也视为同源)
|
|
|
+ log.warn("同源请求requestDomain:{}->currentDomain:{}",requestDomain,currentDomain);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
} else if (ALLOWED_CORSES.contains(requestDomain)) {
|
|
|
// 情况3:合法的跨域请求(白名单)
|
|
|
@@ -98,6 +103,7 @@ public class CORSFilter implements Filter {
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
|
return;
|
|
|
}*/
|
|
|
+ log.warn("合法的跨域请求ALLOWED_CORSES:{}->->requestDomain:{}",requestDomain,currentDomain);
|
|
|
filterChain.doFilter(httpRequest, response);
|
|
|
} else {
|
|
|
// 情况4:非法的跨域请求
|
|
|
@@ -184,6 +190,7 @@ public class CORSFilter implements Filter {
|
|
|
String paramSql = "select biao_ti_,can_shu_zhi_1_,can_shu_zhi_2_ from t_zlcsb where shi_fou_qi_yong_ = 1 and jian_zhi_='"+key+"'";
|
|
|
//String.format(paramSql,key);
|
|
|
Map<String,Object> paramzlcs = commonDao.queryOne(paramSql);
|
|
|
+ log.warn("paramzlcs的值为:{}---key值为{}",paramzlcs,key);
|
|
|
|
|
|
if (BeanUtils.isNotEmpty(paramzlcs)) {
|
|
|
String bmdIp = (String)paramzlcs.get("can_shu_zhi_1_");
|
|
|
@@ -196,17 +203,20 @@ public class CORSFilter implements Filter {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ log.warn("拆分后newIPs的值为:{}",newIPs);
|
|
|
if("HOST".equals(key)){
|
|
|
refreshInterval_host = Long.parseLong((String)paramzlcs.get("can_shu_zhi_2_"));
|
|
|
lastRefreshTime_host = currentTime;
|
|
|
ALLOWED_HOSTS.clear();
|
|
|
ALLOWED_HOSTS.addAll(newIPs);
|
|
|
+ log.warn("读取配置后添加的HOST的IP为:{}",ALLOWED_HOSTS);
|
|
|
}
|
|
|
if("CORS".equals(key)){
|
|
|
refreshInterval_cors = Long.parseLong((String)paramzlcs.get("can_shu_zhi_2_"));
|
|
|
lastRefreshTime_cors = currentTime;
|
|
|
ALLOWED_CORSES.clear();
|
|
|
ALLOWED_CORSES.addAll(newIPs);
|
|
|
+ log.warn("读取配置后添加的CORS的IP为:{}",ALLOWED_CORSES);
|
|
|
}
|
|
|
}else{
|
|
|
//没有启用参数,跳过
|
|
|
@@ -222,14 +232,6 @@ public class CORSFilter implements Filter {
|
|
|
}
|
|
|
//return;
|
|
|
}
|
|
|
- /* if("HOST".equals(key)){
|
|
|
- ALLOWED_HOSTS.clear();
|
|
|
- ALLOWED_HOSTS.addAll(newIPs);
|
|
|
- }
|
|
|
- if("CORS".equals(key)){
|
|
|
- ALLOWED_CORSES.clear();
|
|
|
- ALLOWED_CORSES.addAll(newIPs);
|
|
|
- }*/
|
|
|
} catch (Exception e) {
|
|
|
log.error("刷新Host白名单失败", e);
|
|
|
}
|