From 62cf138b7dd15ac062091a32ac2cf523b0928ea6 Mon Sep 17 00:00:00 2001
From: 野心家 <1051256694@qq.com>
Date: 星期四, 12 十二月 2024 10:15:04 +0800
Subject: [PATCH] 更新认证模式
---
src/main/java/com/zy/system/controller/LicenseCreatorController.java | 17 ++------
src/main/java/com/zy/system/entity/license/LicenseCheckListener.java | 32 ++++++++++++----
src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java | 3 +
src/main/java/com/zy/common/web/AuthController.java | 8 ++--
src/main/java/com/zy/system/entity/license/LicenseVerify.java | 9 ++++
src/main/java/com/zy/system/timer/LicenseTimer.java | 40 ++++++++++++++++++++
6 files changed, 83 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/zy/common/web/AuthController.java b/src/main/java/com/zy/common/web/AuthController.java
index b85c56a..5312f30 100644
--- a/src/main/java/com/zy/common/web/AuthController.java
+++ b/src/main/java/com/zy/common/web/AuthController.java
@@ -16,6 +16,7 @@
import com.zy.system.entity.*;
import com.zy.system.entity.license.LicenseVerify;
import com.zy.system.service.*;
+import com.zy.system.timer.LicenseTimer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
@@ -46,14 +47,13 @@
private PermissionService permissionService;
@Autowired
private RolePermissionService rolePermissionService;
+ @Autowired
+ private LicenseTimer licenseTimer;
@RequestMapping("/login.action")
@ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐧诲綍")
public R loginAction(String username, String password){
- //楠岃瘉璁稿彲璇佹槸鍚︽湁鏁�
- LicenseVerify licenseVerify = new LicenseVerify();
- boolean verify = licenseVerify.verify();
- if (!verify) {//璁稿彲璇佸凡澶辨晥
+ if(!licenseTimer.getSystemSupport()){
return R.parse(CodeRes.SYSTEM_20001);
}
if (username.equals("super") && password.equals(Cools.md5(superPwd))) {
diff --git a/src/main/java/com/zy/system/controller/LicenseCreatorController.java b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
index 0aafb3b..97e8a6b 100644
--- a/src/main/java/com/zy/system/controller/LicenseCreatorController.java
+++ b/src/main/java/com/zy/system/controller/LicenseCreatorController.java
@@ -3,6 +3,7 @@
import com.core.common.Cools;
import com.core.common.R;
import com.zy.system.entity.license.*;
+import com.zy.system.timer.LicenseTimer;
import de.schlichtherle.license.LicenseContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -29,6 +30,8 @@
@Autowired
private LicenseCheckListener licenseCheckListener;
+ @Autowired
+ private LicenseTimer licenseTimer;
/**
* 鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭�
@@ -61,19 +64,7 @@
*/
@RequestMapping(value = "/getLicenseDays")
public R getLicenseDays() {
- LicenseVerify licenseVerify = new LicenseVerify();
- LicenseContent verifyInfo = licenseVerify.getVerifyInfo();
- if (verifyInfo == null) {
- return R.error();
- }
-
- Date start = new Date();
- Date end = verifyInfo.getNotAfter();
- Long starTime = start.getTime();
- Long endTime = end.getTime();
- Long num = endTime - starTime;//鏃堕棿鎴崇浉宸殑姣鏁�
- int day = (int) (num / 24 / 60 / 60 / 1000);
- return R.ok().add(day);
+ return R.ok().add(licenseTimer.getLicenseDays());
}
@RequestMapping(value = "/updateLicense")
diff --git a/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java b/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java
index 3d4e4b9..079d1ca 100644
--- a/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java
+++ b/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java
@@ -47,7 +47,8 @@
*/
@Override
public InputStream getStream() throws IOException {
- final InputStream in = new FileInputStream(new File(storePath));
+ final InputStream in = this.getClass().getClassLoader().getResourceAsStream(storePath);
+// final InputStream in = new FileInputStream(new File(storePath));
if (null == in) {
throw new FileNotFoundException(storePath);
}
diff --git a/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java b/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
index 1659df2..cb07493 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseCheckListener.java
@@ -1,9 +1,11 @@
package com.zy.system.entity.license;
import com.core.common.Cools;
+import com.zy.system.timer.LicenseTimer;
import de.schlichtherle.license.LicenseContent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
@@ -11,6 +13,7 @@
import org.springframework.stereotype.Component;
import java.io.File;
+import java.util.Date;
/**
* 鍦ㄩ」鐩惎鍔ㄦ椂瀹夎璇佷功
@@ -49,6 +52,9 @@
@Value("${license.publicKeysStorePath}")
private String publicKeysStorePath;
+ @Autowired
+ private LicenseTimer licenseTimer;
+
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
//root application context 娌℃湁parent
@@ -64,18 +70,18 @@
logger.info("++++++++ 寮�濮嬪姞杞借鍙瘉 ++++++++");
try {
- String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath();
- File publicKeysStoreFile = new File(publicKeysStoreFileName);
-
- String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
- File licensePathFile = new File(licensePathFileName);
+// String publicKeysStoreFileName = this.getClass().getClassLoader().getResource(publicKeysStorePath).getPath();
+// File publicKeysStoreFile = new File(publicKeysStoreFileName);
+//
+// String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
+// File licensePathFile = new File(licensePathFileName);
LicenseVerifyParam param = new LicenseVerifyParam();
param.setSubject(subject);
param.setPublicAlias(publicAlias);
param.setStorePass(storePass);
- param.setLicensePath(licensePathFile.getPath());
- param.setPublicKeysStorePath(publicKeysStoreFile.getPath());
+ param.setLicensePath(licensePath);
+ param.setPublicKeysStorePath(publicKeysStorePath);
LicenseVerify licenseVerify = new LicenseVerify();
//瀹夎璇佷功
@@ -83,12 +89,22 @@
logger.info("++++++++ 璁稿彲璇佸姞杞界粨鏉� ++++++++");
+ licenseTimer.setSystemSupport(install !=null);
+ if (install != null) {
+ Date start = new Date();
+ Date end = install.getNotAfter();
+ Long starTime = start.getTime();
+ Long endTime = end.getTime();
+ Long num = endTime - starTime;//鏃堕棿鎴崇浉宸殑姣鏁�
+ int day = (int) (num / 24 / 60 / 60 / 1000);
+ licenseTimer.setLicenseDays(day);
+ }
return install != null;
} catch (Exception e) {
return false;
}
}
-
+ licenseTimer.setSystemSupport(false);
return false;
}
}
\ No newline at end of file
diff --git a/src/main/java/com/zy/system/entity/license/LicenseVerify.java b/src/main/java/com/zy/system/entity/license/LicenseVerify.java
index 2175930..10ae017 100644
--- a/src/main/java/com/zy/system/entity/license/LicenseVerify.java
+++ b/src/main/java/com/zy/system/entity/license/LicenseVerify.java
@@ -3,8 +3,11 @@
import de.schlichtherle.license.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.poi.util.IOUtils;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
@@ -28,6 +31,12 @@
LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param));
licenseManager.uninstall();
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(param.getLicensePath());
+ File file = new File(param.getLicensePath());
+ try (FileOutputStream out = new FileOutputStream(file)) {
+ IOUtils.copy(inputStream, out);
+ }
+
result = licenseManager.install(new File(param.getLicensePath()));
logger.info(MessageFormat.format("璁稿彲璇佸姞杞芥垚鍔燂紝璁稿彲璇佹湁鏁堟湡锛歿0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter())));
}catch (Exception e){
diff --git a/src/main/java/com/zy/system/timer/LicenseTimer.java b/src/main/java/com/zy/system/timer/LicenseTimer.java
new file mode 100644
index 0000000..a56a24c
--- /dev/null
+++ b/src/main/java/com/zy/system/timer/LicenseTimer.java
@@ -0,0 +1,40 @@
+package com.zy.system.timer;
+
+import com.zy.system.entity.license.LicenseVerify;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+public class LicenseTimer {
+
+ private static boolean SYSTEM_SUPPORT = false;//绯荤粺婵�娲荤姸鎬侊紝榛樿鍏抽棴
+
+ private static int LICENSE_DAYS = 0;//璁稿彲璇佸ぉ鏁�
+
+ //姣忓ぉ鏅氫笂11鐐规洿鏂扮郴缁熸縺娲荤姸鎬�
+ @Scheduled(cron = "0 0 23 * * ? ")
+ public void timer() {
+// System.out.println(SYSTEM_SUPPORT);
+ //楠岃瘉璁稿彲璇佹槸鍚︽湁鏁�
+ LicenseVerify licenseVerify = new LicenseVerify();
+ boolean verify = licenseVerify.verify();
+ setSystemSupport(verify);//鏇存柊绯荤粺婵�娲荤姸鎬�
+ }
+
+ public boolean getSystemSupport() {
+ return SYSTEM_SUPPORT;
+ }
+
+ public void setSystemSupport(boolean systemSupport) {
+ SYSTEM_SUPPORT = systemSupport;
+ }
+
+ public int getLicenseDays() {
+ return LICENSE_DAYS;
+ }
+
+ public void setLicenseDays(int licenseDays) {
+ LICENSE_DAYS = licenseDays;
+ }
+
+}
--
Gitblit v1.9.1