123
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package com.ruoyi.cai.filter;
|
package com.ruoyi.cai.filter;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ruoyi.cai.config.CaiProperties;
|
||||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||||
|
import com.ruoyi.cai.util.AES;
|
||||||
import com.ruoyi.cai.util.IpUtil;
|
import com.ruoyi.cai.util.IpUtil;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
@@ -24,6 +26,8 @@ public class Ipv6Filter implements Filter {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemConfigManager systemConfigManager;
|
private SystemConfigManager systemConfigManager;
|
||||||
|
@Autowired
|
||||||
|
private CaiProperties caiProperties;
|
||||||
|
|
||||||
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||||
|
|
||||||
@@ -55,12 +59,35 @@ public class Ipv6Filter implements Filter {
|
|||||||
for (String pathAnt : split) {
|
for (String pathAnt : split) {
|
||||||
boolean match = ANT_PATH_MATCHER.match(pathAnt, requestUri);
|
boolean match = ANT_PATH_MATCHER.match(pathAnt, requestUri);
|
||||||
if(match){
|
if(match){
|
||||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
if(caiProperties.isEnableApiEncryption()){
|
||||||
R<Void> fail = R.fail("请检测你的网络环境");
|
sendEncryption(servletResponse);
|
||||||
ServletUtils.renderString(response, JSON.toJSONString(fail));
|
}else{
|
||||||
|
sendNoEncryption(servletResponse);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filterChain.doFilter(servletRequest, servletResponse);
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String KEY = "UPsfSES4456W8ILv";
|
||||||
|
|
||||||
|
private void sendEncryption(ServletResponse servletResponse) {
|
||||||
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||||
|
R<Void> fail = R.fail("请检测你的网络环境");
|
||||||
|
String encrypt = null;
|
||||||
|
try {
|
||||||
|
encrypt = AES.encrypt(JSON.toJSONString(fail), KEY);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("加密失败!",e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ServletUtils.renderString(response, encrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNoEncryption(ServletResponse servletResponse){
|
||||||
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||||
|
R<Void> fail = R.fail("请检测你的网络环境");
|
||||||
|
ServletUtils.renderString(response, JSON.toJSONString(fail));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user