Browse Source

1、测试环境拦截器截取路径与本地环境有差异,多了一层/api

master
bjang03 4 months ago
parent
commit
1d8c62e5c1
  1. 7
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java
  2. 14
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/ModuleAuthenUtils.java

7
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java

@ -6,6 +6,7 @@ import com.win.framework.common.pojo.CommonResult;
import com.win.module.system.util.ModuleAuthenUtils; import com.win.module.system.util.ModuleAuthenUtils;
import lombok.Cleanup; import lombok.Cleanup;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -15,11 +16,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@Component
@Slf4j @Slf4j
public class ModuleAuthenInterceptor implements HandlerInterceptor { public class ModuleAuthenInterceptor implements HandlerInterceptor {
@Resource
private ModuleAuthenUtils moduleAuthenUtils;
private MD5 md5 = MD5.create(); private MD5 md5 = MD5.create();
public int findThirdOccurrence(String str, char c) { public int findThirdOccurrence(String str, char c) {
int count = 0; int count = 0;
@ -37,7 +36,7 @@ public class ModuleAuthenInterceptor implements HandlerInterceptor {
String moduleName = request.getRequestURI().substring(0,findThirdOccurrence(request.getRequestURI(),'/')); String moduleName = request.getRequestURI().substring(0,findThirdOccurrence(request.getRequestURI(),'/'));
String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName)); String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName));
if(endTimeStr != null){ if(endTimeStr != null){
LocalDateTime endTime = LocalDateTime.parse(moduleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
if (endTime == null || endTime.isBefore(LocalDateTime.now())){ if (endTime == null || endTime.isBefore(LocalDateTime.now())){
response.setContentType("application/json;charset=utf-8"); response.setContentType("application/json;charset=utf-8");
CommonResult result = new CommonResult<>(); CommonResult result = new CommonResult<>();

14
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/ModuleAuthenUtils.java

@ -20,14 +20,14 @@ public class ModuleAuthenUtils {
public static String secretKey; public static String secretKey;
public static Map<String,String> module = new HashMap<>(); public static Map<String,String> module = new HashMap<>();
@Resource RedisTemplate redisTemplate; @Resource RedisTemplate redisTemplate;
public String decrypt(String encryptedData,String secretKey) throws Exception { public static String decrypt(String encryptedData,String secretKey) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec); cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData)); byte[] decryptedBytes = cipher.doFinal(Base64.decode(encryptedData));
return new String(decryptedBytes, StandardCharsets.UTF_8); return new String(decryptedBytes, StandardCharsets.UTF_8);
} }
public String encrypt(String data,String secretKey) throws Exception { public static String encrypt(String data,String secretKey) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM); SecretKeySpec secretKeySpec = new SecretKeySpec(Base64.decode(secretKey), ALGORITHM);
Cipher cipher = Cipher.getInstance(ALGORITHM); Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
@ -36,15 +36,15 @@ public class ModuleAuthenUtils {
} }
public void updateLicences(LicencesMessage ...message){ public void updateLicences(LicencesMessage ...message){
if(message != null && message.length>0){ if(message != null && message.length>0){
ModuleAuthenUtils.secretKey = message[0].getSecretKey(); secretKey = message[0].getSecretKey();
ModuleAuthenUtils.module = message[0].getData(); module = message[0].getData();
return; return;
} }
JSONObject json = new JSONObject(redisTemplate.opsForValue().get(ModuleAuthenUtils.LICENCES_REDIS_KEY)); JSONObject json = new JSONObject(redisTemplate.opsForValue().get(LICENCES_REDIS_KEY));
if(json.isEmpty()){ if(json.isEmpty()){
return; return;
} }
ModuleAuthenUtils.secretKey = json.getStr("secretKey"); secretKey = json.getStr("secretKey");
ModuleAuthenUtils.module = json.getJSONObject("data").toBean(Map.class); module = json.getJSONObject("data").toBean(Map.class);
} }
} }

Loading…
Cancel
Save