From 80bfc1f895f2307ae2f7b02ca6a6ff822c3af9bb Mon Sep 17 00:00:00 2001 From: bjang03 Date: Mon, 20 May 2024 10:07:12 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=A8=A1=E5=9D=97=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/ModuleAuthenInterceptor.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java index fe3cac6..8219d64 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java @@ -20,6 +20,7 @@ import java.time.format.DateTimeFormatter; @Slf4j public class ModuleAuthenInterceptor implements HandlerInterceptor { private MD5 md5 = MD5.create(); + private Boolean onOff = false; public int findThirdOccurrence(String str, char c) { int count = 0; int index = -1; @@ -33,22 +34,24 @@ public class ModuleAuthenInterceptor implements HandlerInterceptor { } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - String[] uris = request.getRequestURI().split("admin-api"); - String uri = uris[uris.length-1]; - String moduleName = uri.substring(0,findThirdOccurrence(uri,'/')); - log.info(String.format("===uri-src=%s,uri-md5=%s===",moduleName,md5.digestHex(moduleName))); - log.info(String.format("===cache=%s===", new JSONObject(ModuleAuthenUtils.module).toString())); - String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName)); - if(endTimeStr != null){ - LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - if (endTime == null || endTime.isBefore(LocalDateTime.now())){ - response.setContentType("application/json;charset=utf-8"); - CommonResult result = new CommonResult<>(); - result.setCode(403); - result.setMsg(String.format("【%s】模块权限到期,请联系服务商缴费", moduleName)); - @Cleanup PrintWriter os = response.getWriter(); - os.write(new JSONObject(result).toString()); - return false; + if (onOff){ + String[] uris = request.getRequestURI().split("admin-api"); + String uri = uris[uris.length-1]; + String moduleName = uri.substring(0,findThirdOccurrence(uri,'/')); + log.info(String.format("===uri-src=%s,uri-md5=%s===",moduleName,md5.digestHex(moduleName))); + log.info(String.format("===cache=%s===", new JSONObject(ModuleAuthenUtils.module).toString())); + String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName)); + if(endTimeStr != null){ + LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + if (endTime == null || endTime.isBefore(LocalDateTime.now())){ + response.setContentType("application/json;charset=utf-8"); + CommonResult result = new CommonResult<>(); + result.setCode(403); + result.setMsg(String.format("【%s】模块权限到期,请联系服务商缴费", moduleName)); + @Cleanup PrintWriter os = response.getWriter(); + os.write(new JSONObject(result).toString()); + return false; + } } } return true;