From e5a147a88ec2a57d2d051d72a030c58b408f4701 Mon Sep 17 00:00:00 2001
From: 吴学文 <wuxuewen@wuxuewendeMacBook-Pro.local>
Date: 星期二, 07 五月 2019 20:14:54 +0800
Subject: [PATCH] 修改服务端接口未加入RequestBody 修复
---
java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java | 74 ++++++++++++++++++++++++++++++++++--
1 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java b/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
index 2456fd6..df20bcb 100644
--- a/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
+++ b/java110-core/src/main/java/com/java110/core/factory/AuthenticationFactory.java
@@ -15,8 +15,10 @@
import com.java110.common.constant.MappingConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.exception.NoAuthorityException;
+import com.java110.common.util.DateUtil;
import com.java110.common.util.StringUtil;
+import com.java110.core.context.ApiDataFlow;
import com.java110.core.context.DataFlow;
import org.apache.commons.codec.digest.DigestUtils;
@@ -27,10 +29,7 @@
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
-import java.util.Base64;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
/**
*
@@ -38,6 +37,16 @@
* Created by wuxw on 2018/4/23.
*/
public class AuthenticationFactory {
+
+ private final static String PASSWD_SALT= "hc@java110";
+ /**
+ * 鐢ㄦ埛瀵嗙爜 md5绛惧悕
+ * @param inStr
+ * @return
+ */
+ public static String passwdMd5(String inStr) throws NoAuthorityException{
+ return md5(md5(inStr+PASSWD_SALT));
+ }
/**
* md5绛惧悕
@@ -61,7 +70,26 @@
if(dataFlow == null){
throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR,"MD5绛惧悕杩囩▼涓嚭鐜伴敊璇�");
}
- String reqInfo = dataFlow.getTransactionId() + dataFlow.getAppId() + dataFlow.getReqBusiness().toJSONString()+dataFlow.getAppRoutes().get(0).getSecurityCode();
+ String reqInfo = dataFlow.getTransactionId() +dataFlow.getAppId();
+ reqInfo += ((dataFlow.getReqBusiness() == null || dataFlow.getReqBusiness().size() == 0)
+ ?dataFlow.getReqData() :dataFlow.getReqBusiness().toJSONString());
+ reqInfo += dataFlow.getAppRoutes().get(0).getSecurityCode();
+ return md5(reqInfo);
+ }
+
+ /**
+ * dataFlow 瀵硅薄绛惧悕
+ * @param dataFlow
+ * @return
+ */
+ public static String apiDataFlowMd5(ApiDataFlow dataFlow) throws NoAuthorityException{
+ if(dataFlow == null){
+ throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR,"MD5绛惧悕杩囩▼涓嚭鐜伴敊璇�");
+ }
+ String reqInfo = dataFlow.getTransactionId() + dataFlow.getRequestTime() + dataFlow.getAppId();
+ reqInfo += "GET,DELETE".equals(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_METHOD))?
+ dataFlow.getRequestHeaders().get("REQUEST_URL") :dataFlow.getReqData();
+ reqInfo += dataFlow.getAppRoutes().get(0).getSecurityCode();
return md5(reqInfo);
}
@@ -91,6 +119,20 @@
}else {
orders.put("sign", AuthenticationFactory.md5(orders.getString("transactionId"), orders.getString("responseTime"),
business == null ?"":business.toJSONString(), dataFlow.getAppRoutes().get(0).getSecurityCode()));
+ }
+ }
+
+ /**
+ * 娣诲姞 sign
+ * @param dataFlow
+ * @param headers
+ */
+ public static void putSign(DataFlow dataFlow,Map<String,String> headers){
+ if(dataFlow == null || dataFlow.getAppRoutes() == null || dataFlow.getAppRoutes().size() == 0 || StringUtil.isNullOrNone(dataFlow.getAppRoutes().get(0).getSecurityCode())) {
+ headers.put("resSign","");
+ }else {
+ headers.put("resSign", AuthenticationFactory.md5(dataFlow.getTransactionId(), headers.get("responseTime"),
+ dataFlow.getResData(), dataFlow.getAppRoutes().get(0).getSecurityCode()));
}
}
@@ -284,6 +326,28 @@
}
/**
+ * 鍒犻櫎Token
+ * @param token
+ * @return
+ * @throws Exception
+ */
+ public static void deleteToken(String token) throws Exception{
+ String jwtSecret = MappingCache.getValue(MappingConstant.KEY_JWT_SECRET);
+ if(StringUtil.isNullOrNone(jwtSecret)){
+ jwtSecret = CommonConstant.DEFAULT_JWT_SECRET;
+ }
+ Algorithm algorithm = Algorithm.HMAC256(jwtSecret);
+ JWTVerifier verifier = JWT.require(algorithm).withIssuer("java110").build();
+ DecodedJWT jwt = verifier.verify(token);
+ String jdi = jwt.getId();
+ //淇濆瓨token Id
+ String userId = JWTCache.getValue(jdi);
+ if(!StringUtil.isNullOrNone(userId)){ //璇存槑redis涓璲di 宸茬粡澶辨晥
+ JWTCache.removeValue(jdi);
+ }
+ }
+
+ /**
* 鏍¢獙Token
* @param token
* @return
--
Gitblit v1.8.0