|
@@ -42,14 +42,15 @@ import static cn.hutool.core.util.StrUtil.*;
|
|
|
@Component
|
|
@Component
|
|
|
public class HttpUtil {
|
|
public class HttpUtil {
|
|
|
|
|
|
|
|
- @Value("${crypto.key}")
|
|
|
|
|
- private String cryptoKey;
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private CryptoConfig cryptoConfig;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public void modifyHttpData(ServletRequest request, ServletResponse response, FilterChain chain) throws Exception {
|
|
public void modifyHttpData(ServletRequest request, ServletResponse response, FilterChain chain) throws Exception {
|
|
|
HttpServletRequest originalRequest = (HttpServletRequest) request;
|
|
HttpServletRequest originalRequest = (HttpServletRequest) request;
|
|
|
String url = originalRequest.getRequestURI();
|
|
String url = originalRequest.getRequestURI();
|
|
|
- if (HttpMethod.POST.matches(originalRequest.getMethod()) && url.indexOf("put-file") < 0) {
|
|
|
|
|
- //只处理不是上传文件的post请求
|
|
|
|
|
|
|
+ if (HttpMethod.POST.matches(originalRequest.getMethod()) && !this.isInWhiteList(url)) {
|
|
|
|
|
+ //只处理不在白名单下的post请求
|
|
|
this.handelPost(request,response,chain,originalRequest);
|
|
this.handelPost(request,response,chain,originalRequest);
|
|
|
}else{
|
|
}else{
|
|
|
//其他请求直接通过
|
|
//其他请求直接通过
|
|
@@ -84,9 +85,24 @@ public class HttpUtil {
|
|
|
String originalRequestBody = ServletUtil.getBody(request);
|
|
String originalRequestBody = ServletUtil.getBody(request);
|
|
|
if (StrUtil.isNotBlank(originalRequestBody)) {
|
|
if (StrUtil.isNotBlank(originalRequestBody)) {
|
|
|
//报文不为空,解密
|
|
//报文不为空,解密
|
|
|
- String modifyRequestBody = SecureUtil.aes(cryptoKey.getBytes()).decryptStr(originalRequestBody);
|
|
|
|
|
|
|
+ String modifyRequestBody = SecureUtil.aes(cryptoConfig.getKey().getBytes()).decryptStr(originalRequestBody);
|
|
|
request = this.modifyRequestBodyAndContentType(originalRequest, modifyRequestBody, null);
|
|
request = this.modifyRequestBodyAndContentType(originalRequest, modifyRequestBody, null);
|
|
|
}
|
|
}
|
|
|
chain.doFilter(request, response);
|
|
chain.doFilter(request, response);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 白名单配置
|
|
|
|
|
+ * @param uri
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean isInWhiteList(String uri){
|
|
|
|
|
+ for(String url: cryptoConfig.getWhiteList()){
|
|
|
|
|
+ if(uri.contains(url)){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|