Browse Source

1、模块授权拦截器增加开关

master
bjang03 6 months ago
parent
commit
80bfc1f895
  1. 35
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java

35
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;

Loading…
Cancel
Save