|
@ -20,6 +20,7 @@ import java.time.format.DateTimeFormatter; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class ModuleAuthenInterceptor implements HandlerInterceptor { |
|
|
public class ModuleAuthenInterceptor implements HandlerInterceptor { |
|
|
private MD5 md5 = MD5.create(); |
|
|
private MD5 md5 = MD5.create(); |
|
|
|
|
|
private Boolean onOff = false; |
|
|
public int findThirdOccurrence(String str, char c) { |
|
|
public int findThirdOccurrence(String str, char c) { |
|
|
int count = 0; |
|
|
int count = 0; |
|
|
int index = -1; |
|
|
int index = -1; |
|
@ -33,22 +34,24 @@ public class ModuleAuthenInterceptor implements HandlerInterceptor { |
|
|
} |
|
|
} |
|
|
@Override |
|
|
@Override |
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|
|
String[] uris = request.getRequestURI().split("admin-api"); |
|
|
if (onOff){ |
|
|
String uri = uris[uris.length-1]; |
|
|
String[] uris = request.getRequestURI().split("admin-api"); |
|
|
String moduleName = uri.substring(0,findThirdOccurrence(uri,'/')); |
|
|
String uri = uris[uris.length-1]; |
|
|
log.info(String.format("===uri-src=%s,uri-md5=%s===",moduleName,md5.digestHex(moduleName))); |
|
|
String moduleName = uri.substring(0,findThirdOccurrence(uri,'/')); |
|
|
log.info(String.format("===cache=%s===", new JSONObject(ModuleAuthenUtils.module).toString())); |
|
|
log.info(String.format("===uri-src=%s,uri-md5=%s===",moduleName,md5.digestHex(moduleName))); |
|
|
String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName)); |
|
|
log.info(String.format("===cache=%s===", new JSONObject(ModuleAuthenUtils.module).toString())); |
|
|
if(endTimeStr != null){ |
|
|
String endTimeStr = ModuleAuthenUtils.module.get(md5.digestHex(moduleName)); |
|
|
LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
|
if(endTimeStr != null){ |
|
|
if (endTime == null || endTime.isBefore(LocalDateTime.now())){ |
|
|
LocalDateTime endTime = LocalDateTime.parse(ModuleAuthenUtils.decrypt(endTimeStr,ModuleAuthenUtils.secretKey), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
|
response.setContentType("application/json;charset=utf-8"); |
|
|
if (endTime == null || endTime.isBefore(LocalDateTime.now())){ |
|
|
CommonResult result = new CommonResult<>(); |
|
|
response.setContentType("application/json;charset=utf-8"); |
|
|
result.setCode(403); |
|
|
CommonResult result = new CommonResult<>(); |
|
|
result.setMsg(String.format("【%s】模块权限到期,请联系服务商缴费", moduleName)); |
|
|
result.setCode(403); |
|
|
@Cleanup PrintWriter os = response.getWriter(); |
|
|
result.setMsg(String.format("【%s】模块权限到期,请联系服务商缴费", moduleName)); |
|
|
os.write(new JSONObject(result).toString()); |
|
|
@Cleanup PrintWriter os = response.getWriter(); |
|
|
return false; |
|
|
os.write(new JSONObject(result).toString()); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|