From 48c1de18235020edff108339ed1d12bade8a2b90 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期一, 08 十二月 2025 16:37:02 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/system/entity/license/LicenseCreator.java |   86 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/system/entity/license/LicenseCreator.java b/src/main/java/com/zy/system/entity/license/LicenseCreator.java
new file mode 100644
index 0000000..01f2ad1
--- /dev/null
+++ b/src/main/java/com/zy/system/entity/license/LicenseCreator.java
@@ -0,0 +1,86 @@
+package com.zy.system.entity.license;
+
+import de.schlichtherle.license.*;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import javax.security.auth.x500.X500Principal;
+import java.io.File;
+import java.text.MessageFormat;
+import java.util.prefs.Preferences;
+
+/**
+ * License鐢熸垚绫�
+ */
+public class LicenseCreator {
+    private static Logger logger = LogManager.getLogger(LicenseCreator.class);
+    private final static X500Principal DEFAULT_HOLDER_AND_ISSUER = new X500Principal("CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN");
+    private LicenseCreatorParam param;
+
+    public LicenseCreator(LicenseCreatorParam param) {
+        this.param = param;
+    }
+
+    /**
+     * 鐢熸垚License璇佷功
+     */
+    public boolean generateLicense(){
+        try {
+            LicenseManager licenseManager = new CustomLicenseManager(initLicenseParam());
+            LicenseContent licenseContent = initLicenseContent();
+
+            licenseManager.store(licenseContent,new File(param.getLicensePath()));
+
+            return true;
+        }catch (Exception e){
+            logger.error(MessageFormat.format("璇佷功鐢熸垚澶辫触锛歿0}",param),e);
+            return false;
+        }
+    }
+
+    /**
+     * 鍒濆鍖栬瘉涔︾敓鎴愬弬鏁�
+     */
+    private LicenseParam initLicenseParam(){
+        Preferences preferences = Preferences.userNodeForPackage(LicenseCreator.class);
+
+        //璁剧疆瀵硅瘉涔﹀唴瀹瑰姞瀵嗙殑绉橀挜
+        CipherParam cipherParam = new DefaultCipherParam(param.getStorePass());
+
+        KeyStoreParam privateStoreParam = new CustomKeyStoreParam(LicenseCreator.class
+                ,param.getPrivateKeysStorePath()
+                ,param.getPrivateAlias()
+                ,param.getStorePass()
+                ,param.getKeyPass());
+
+        LicenseParam licenseParam = new DefaultLicenseParam(param.getSubject()
+                ,preferences
+                ,privateStoreParam
+                ,cipherParam);
+
+        return licenseParam;
+    }
+
+    /**
+     * 璁剧疆璇佷功鐢熸垚姝f枃淇℃伅
+     */
+    private LicenseContent initLicenseContent(){
+        LicenseContent licenseContent = new LicenseContent();
+        licenseContent.setHolder(DEFAULT_HOLDER_AND_ISSUER);
+        licenseContent.setIssuer(DEFAULT_HOLDER_AND_ISSUER);
+
+        licenseContent.setSubject(param.getSubject());
+        licenseContent.setIssued(param.getIssuedTime());
+        licenseContent.setNotBefore(param.getIssuedTime());
+        licenseContent.setNotAfter(param.getExpiryTime());
+        licenseContent.setConsumerType(param.getConsumerType());
+        licenseContent.setConsumerAmount(param.getConsumerAmount());
+        licenseContent.setInfo(param.getDescription());
+
+        //鎵╁睍鏍¢獙鏈嶅姟鍣ㄧ‖浠朵俊鎭�
+        licenseContent.setExtra(param.getLicenseCheck());
+
+        return licenseContent;
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.1