From 54be1e5481d58ea7fa39a34c0bd0e442c406a4b8 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Thu, 21 Sep 2023 11:49:38 +0800
Subject: [PATCH] 后台修改
---
src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java | 32 +++++++++++++++++++-------------
1 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java b/src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java
index e03251c..dc1c044 100644
--- a/src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java
+++ b/src/main/java/cc/mrbird/febs/common/interceptor/DappInterceptor.java
@@ -2,6 +2,7 @@
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.FebsResponse;
+import cc.mrbird.febs.common.properties.SystemProperties;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.common.utils.SpringContextUtil;
@@ -14,6 +15,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.HandlerInterceptor;
import org.web3j.crypto.Hash;
@@ -33,6 +35,8 @@
private final DappMemberDao dappMemberDao = SpringContextUtil.getBean(DappMemberDao.class);
private final RedisUtils redisUtils = SpringContextUtil.getBean(RedisUtils.class);
+ private SystemProperties systemProperties = SpringContextUtil.getBean(SystemProperties.class);
+
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if ("OPTIONS".equals(request.getMethod().toUpperCase())) {
@@ -48,19 +52,21 @@
return false;
}
- Map<Object, Object> signKey = redisUtils.hmget(AppContants.REDIS_KEY_SIGN);
- Object signObj = signKey.get(headAddress);
+ if (!systemProperties.isDebug()) {
+ Map<Object, Object> signKey = redisUtils.hmget(AppContants.REDIS_KEY_SIGN);
+ Object signObj = signKey.get(headAddress);
- if (signObj == null) {
- responseUnAuth(response);
- return false;
- }
- String sign = (String) signObj;
+ if (signObj == null) {
+ responseUnAuth(response);
+ return false;
+ }
+ String sign = (String) signObj;
- String calKey = LoginUserUtil.sha3(sign + path + headAddress).replace("0x", "");
- if (!calKey.equals(key)) {
- responseUnAuth(response);
- return false;
+ String calKey = LoginUserUtil.sha3(sign + path + headAddress).replace("0x", "");
+ if (!calKey.equals(key)) {
+ responseUnAuth(response);
+ return false;
+ }
}
DappMemberEntity memberEntity = dappMemberDao.selectByAddress(headAddress, null);
@@ -78,8 +84,8 @@
response.setContentType("application/json; charset=utf-8");
FebsResponse code = new FebsResponse().code(HttpStatus.UNAUTHORIZED);
- String encryptBase64 = SecureUtil.rsa(AppContants.RESP_PRIVATE_KEY, AppContants.RESP_PUBLIC_KEY).encryptBase64(JSONObject.toJSONString(code).getBytes(), KeyType.PublicKey);
- response.getWriter().write(new ObjectMapper().writeValueAsString(encryptBase64));
+// String encryptBase64 = SecureUtil.rsa(AppContants.RESP_PRIVATE_KEY, AppContants.RESP_PUBLIC_KEY).encryptBase64(JSONObject.toJSONString(code).getBytes(), KeyType.PublicKey);
+ response.getWriter().write(new ObjectMapper().writeValueAsString(code));
}
public static void main(String[] args) {
--
Gitblit v1.9.1