|
@@ -11,7 +11,9 @@ import javax.servlet.*;
|
|
|
import javax.servlet.annotation.WebFilter;
|
|
import javax.servlet.annotation.WebFilter;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -33,7 +35,7 @@ public class SecurityFilter implements Filter {
|
|
|
|
|
|
|
|
//不拦截
|
|
//不拦截
|
|
|
if ("/v1/meterbasecars/appregister".equals(path)
|
|
if ("/v1/meterbasecars/appregister".equals(path)
|
|
|
- ||"/v1/meterbasecars/applogin".equals(path) || 1 == 1){
|
|
|
|
|
|
|
+ ||"/v1/meterbasecars/applogin".equals(path)){
|
|
|
filterChain.doFilter(servletRequest,servletResponse);
|
|
filterChain.doFilter(servletRequest,servletResponse);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -43,23 +45,26 @@ public class SecurityFilter implements Filter {
|
|
|
// return;
|
|
// return;
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- // 1. 先尝试拿vCode
|
|
|
|
|
|
|
+// // 1. 先尝试拿vCode
|
|
|
StringBuffer url = request.getRequestURL();
|
|
StringBuffer url = request.getRequestURL();
|
|
|
String uri = request.getRequestURI();
|
|
String uri = request.getRequestURI();
|
|
|
String method = request.getMethod();
|
|
String method = request.getMethod();
|
|
|
String vCode = request.getParameter("verificationCode");
|
|
String vCode = request.getParameter("verificationCode");
|
|
|
- String contentType = request.getContentType();
|
|
|
|
|
- // 获取json字符串
|
|
|
|
|
-// String accept = request.getHeader("accept");
|
|
|
|
|
- String jsonStr = getRequestJson(request);
|
|
|
|
|
- // 2. 如果vCode为空,且method为POST,且contentType[0]为application/json
|
|
|
|
|
|
|
+// // 获取json字符串
|
|
|
if(vCode == null || StringUtils.isEmpty(vCode)) {
|
|
if(vCode == null || StringUtils.isEmpty(vCode)) {
|
|
|
- Object parse = JSON.parse(jsonStr);
|
|
|
|
|
- JSONObject object = new JSONObject(parse);
|
|
|
|
|
- vCode = object.getStr("verificationCode");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ vCode = request.getHeader("verificationCode");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+//// String accept = request.getHeader("accept");
|
|
|
|
|
+ // String jsonStr = getJsonParam((HttpServletRequest) servletRequest);
|
|
|
|
|
+// // 2. 如果vCode为空,且method为POST,且contentType[0]为application/json
|
|
|
|
|
+// if(vCode == null || StringUtils.isEmpty(vCode)) {
|
|
|
|
|
+// Object parse = JSON.parse(jsonStr);
|
|
|
|
|
+// JSONObject object = new JSONObject(parse);
|
|
|
|
|
+// vCode = object.getStr("verificationCode");
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
//取出验证码
|
|
//取出验证码
|
|
|
if(vCode == null || StringUtils.isEmpty(vCode)) {
|
|
if(vCode == null || StringUtils.isEmpty(vCode)) {
|
|
|
response.setContentType("application/json;charset=UTF-8");
|
|
response.setContentType("application/json;charset=UTF-8");
|
|
@@ -71,13 +76,10 @@ public class SecurityFilter implements Filter {
|
|
|
}
|
|
}
|
|
|
String verificationCode1 = vCode;
|
|
String verificationCode1 = vCode;
|
|
|
verificationCode1 = verificationCode1.toLowerCase(Locale.ROOT);
|
|
verificationCode1 = verificationCode1.toLowerCase(Locale.ROOT);
|
|
|
-// System.out.println(verificationCode1);
|
|
|
|
|
-
|
|
|
|
|
//生成原数据
|
|
//生成原数据
|
|
|
SimpleDateFormat df = new SimpleDateFormat("MM-yyyy-dd");
|
|
SimpleDateFormat df = new SimpleDateFormat("MM-yyyy-dd");
|
|
|
StringBuffer date = new StringBuffer(df.format(new Date()));
|
|
StringBuffer date = new StringBuffer(df.format(new Date()));
|
|
|
date = date.insert(2,"jisco");
|
|
date = date.insert(2,"jisco");
|
|
|
-// System.out.println(date);
|
|
|
|
|
|
|
|
|
|
//原数据MD5加密
|
|
//原数据MD5加密
|
|
|
String verificationCode2 = DigestUtils.md5DigestAsHex(date.toString().getBytes(StandardCharsets.UTF_8)).toLowerCase(Locale.ROOT);
|
|
String verificationCode2 = DigestUtils.md5DigestAsHex(date.toString().getBytes(StandardCharsets.UTF_8)).toLowerCase(Locale.ROOT);
|
|
@@ -100,31 +102,72 @@ public class SecurityFilter implements Filter {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static String getRequestJson(HttpServletRequest request) {
|
|
|
|
|
- boolean isGetRequest = request.getMethod().toLowerCase().equals("get");
|
|
|
|
|
- try {
|
|
|
|
|
- if (isGetRequest) {
|
|
|
|
|
- return new String(request.getQueryString().getBytes(
|
|
|
|
|
- "ISO-8859-1"), "UTF-8").replaceAll("%22", "\"");
|
|
|
|
|
- }
|
|
|
|
|
- int contentLength = request.getContentLength();
|
|
|
|
|
- if (contentLength < 0) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
- byte buffer[] = new byte[contentLength];
|
|
|
|
|
- for (int i = 0; i < contentLength;) {
|
|
|
|
|
-
|
|
|
|
|
- int readlen = request.getInputStream().read(buffer, i,
|
|
|
|
|
- contentLength - i);
|
|
|
|
|
- if (readlen == -1) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- i += readlen;
|
|
|
|
|
- }
|
|
|
|
|
- return new String(buffer, "UTF-8");
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取Json数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+// private String getJsonParam(HttpServletRequest request) {
|
|
|
|
|
+//
|
|
|
|
|
+// String jsonParam = "";
|
|
|
|
|
+// ServletInputStream inputStream = null;
|
|
|
|
|
+// try {
|
|
|
|
|
+// int contentLength = request.getContentLength();
|
|
|
|
|
+// if (!(contentLength < 0)) {
|
|
|
|
|
+// byte[] buffer = new byte[contentLength];
|
|
|
|
|
+// inputStream = request.getInputStream();
|
|
|
|
|
+// for (int i = 0; i < contentLength; ) {
|
|
|
|
|
+// int len = inputStream.read(buffer, i, contentLength);
|
|
|
|
|
+// if (len == -1) {
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// i += len;
|
|
|
|
|
+// }
|
|
|
|
|
+// jsonParam = new String(buffer, "utf-8");
|
|
|
|
|
+// }
|
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
|
+// } finally {
|
|
|
|
|
+// if (inputStream != null) {
|
|
|
|
|
+// try {
|
|
|
|
|
+// inputStream.close();
|
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+// return jsonParam;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+// public static String getRequestJson(HttpServletRequest request) {
|
|
|
|
|
+// boolean isGetRequest = request.getMethod().toLowerCase().equals("get");
|
|
|
|
|
+// try {
|
|
|
|
|
+//// if (isGetRequest) {
|
|
|
|
|
+//// return new String(request.getQueryString().getBytes(
|
|
|
|
|
+//// "ISO-8859-1"), "UTF-8").replaceAll("%22", "\"");
|
|
|
|
|
+//// }
|
|
|
|
|
+// int contentLength = request.getContentLength();
|
|
|
|
|
+// if (contentLength < 0) {
|
|
|
|
|
+// return null;
|
|
|
|
|
+// }
|
|
|
|
|
+// byte buffer[] = new byte[contentLength];
|
|
|
|
|
+// for (int i = 0; i < contentLength;) {
|
|
|
|
|
+//
|
|
|
|
|
+// int readlen = request.getInputStream().read(buffer, i,
|
|
|
|
|
+// contentLength - i);
|
|
|
|
|
+// if (readlen == -1) {
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// i += readlen;
|
|
|
|
|
+// }
|
|
|
|
|
+// return new String(buffer, "UTF-8");
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// e.printStackTrace();
|
|
|
|
|
+// }
|
|
|
|
|
+// return null;
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|