From edc9a6674eb9b40e33a74c5f022d279712ed3b7c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 30 十二月 2024 17:01:13 +0800 Subject: [PATCH] 添加许可工具 --- se-modules/se-system/src/main/java/com/se/system/service/inte/IACustomVerifyListener.java | 38 + se-common/se-common-redis/se-common-redis.iml | 2 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorMg.java | 48 + se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java | 231 ++++++ se-common/se-common-security/se-common-security.iml | 2 se-modules/se-system/src/main/java/com/se/system/service/inte/IAServerInfoService.java | 214 ++++++ se-modules/se-system/src/main/resources/privateKeys.store | 0 se-common/se-common-log/se-common-log.iml | 2 se-modules/se-system/src/main/java/com/se/system/service/impl/LinuxServerInfoService.java | 63 + se-common/se-common-datascope/se-common-datascope.iml | 2 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java | 91 ++ se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseExtraParamVo.java | 182 +++++ se-modules/se-system/src/main/java/com/se/system/service/impl/WindowsServerInfoService.java | 74 ++ se-gateway/se-gateway.iml | 2 se-common/se-common-core/pom.xml | 7 se-common/se-common-sensitive/se-common-sensitive.iml | 2 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorParamVo.java | 216 ++++++ se-modules/se-system/src/main/java/com/se/system/utils/ServerSerialUtils.java | 55 + se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java | 78 + se-modules/se-system/src/main/java/com/se/system/utils/ParamInitUtils.java | 84 ++ 说明.txt | 9 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyMg.java | 102 +++ se-common/se-common-core/se-common-core.iml | 2 se-modules/se-system/src/main/java/com/se/system/utils/DateUtils.java | 113 +++ se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java | 20 se-api/se-api-system/se-api-system.iml | 2 se-modules/se-system/pom.xml | 7 se-modules/se-system/src/main/resources/certfile.cer | 0 se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseResultVo.java | 86 ++ se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCustomMg.java | 247 +++++++ se-modules/se-system/src/main/java/com/se/system/service/NacosService.java | 4 se-modules/se-system/src/main/resources/publicCerts.store | 0 32 files changed, 1,925 insertions(+), 60 deletions(-) diff --git a/se-api/se-api-system/se-api-system.iml b/se-api/se-api-system/se-api-system.iml index 7e47720..f5e2e69 100644 --- a/se-api/se-api-system/se-api-system.iml +++ b/se-api/se-api-system/se-api-system.iml @@ -94,8 +94,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.7" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter:3.1.7" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-context:3.1.7" level="project" /> diff --git a/se-common/se-common-core/pom.xml b/se-common/se-common-core/pom.xml index d483a29..c184693 100644 --- a/se-common/se-common-core/pom.xml +++ b/se-common/se-common-core/pom.xml @@ -111,12 +111,5 @@ <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </dependency> - - <!-- license --> - <dependency> - <groupId>de.schlichtherle.truelicense</groupId> - <artifactId>truelicense-core</artifactId> - <version>1.33</version> - </dependency> </dependencies> </project> diff --git a/se-common/se-common-core/se-common-core.iml b/se-common/se-common-core/se-common-core.iml index 904579d..6cb2b4a 100644 --- a/se-common/se-common-core/se-common-core.iml +++ b/se-common/se-common-core/se-common-core.iml @@ -99,8 +99,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.7" level="project" /> </component> </module> \ No newline at end of file diff --git a/se-common/se-common-datascope/se-common-datascope.iml b/se-common/se-common-datascope/se-common-datascope.iml index 807af6c..fe6f29f 100644 --- a/se-common/se-common-datascope/se-common-datascope.iml +++ b/se-common/se-common-datascope/se-common-datascope.iml @@ -80,8 +80,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="module" module-name="se-common-redis" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.7.18" level="project" /> <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.7.18" level="project" /> diff --git a/se-common/se-common-log/se-common-log.iml b/se-common/se-common-log/se-common-log.iml index 807af6c..fe6f29f 100644 --- a/se-common/se-common-log/se-common-log.iml +++ b/se-common/se-common-log/se-common-log.iml @@ -80,8 +80,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="module" module-name="se-common-redis" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.7.18" level="project" /> <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.7.18" level="project" /> diff --git a/se-common/se-common-redis/se-common-redis.iml b/se-common/se-common-redis/se-common-redis.iml index 98e24b2..a8c3c88 100644 --- a/se-common/se-common-redis/se-common-redis.iml +++ b/se-common/se-common-redis/se-common-redis.iml @@ -107,8 +107,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.7" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter:3.1.7" level="project" /> <orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-context:3.1.7" level="project" /> diff --git a/se-common/se-common-security/se-common-security.iml b/se-common/se-common-security/se-common-security.iml index b244580..daf2e70 100644 --- a/se-common/se-common-security/se-common-security.iml +++ b/se-common/se-common-security/se-common-security.iml @@ -79,8 +79,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="module" module-name="se-common-redis" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.7.18" level="project" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.7.18" level="project" /> diff --git a/se-common/se-common-sensitive/se-common-sensitive.iml b/se-common/se-common-sensitive/se-common-sensitive.iml index 39b8f6a..5c2ce80 100644 --- a/se-common/se-common-sensitive/se-common-sensitive.iml +++ b/se-common/se-common-sensitive/se-common-sensitive.iml @@ -79,8 +79,6 @@ <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> <orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.6.2" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="module" module-name="se-common-redis" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.7.18" level="project" /> <orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.7.18" level="project" /> diff --git a/se-gateway/se-gateway.iml b/se-gateway/se-gateway.iml index b21192d..44721bb 100644 --- a/se-gateway/se-gateway.iml +++ b/se-gateway/se-gateway.iml @@ -173,8 +173,6 @@ <orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" /> <orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" /> <orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-core:1.33" level="project" /> - <orderEntry type="library" name="Maven: de.schlichtherle.truelicense:truelicense-xml:1.33" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:3.0.0" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-spring-webmvc:3.0.0" level="project" /> <orderEntry type="library" name="Maven: io.springfox:springfox-core:3.0.0" level="project" /> diff --git a/se-modules/se-system/pom.xml b/se-modules/se-system/pom.xml index 4ffb72f..9d21e03 100644 --- a/se-modules/se-system/pom.xml +++ b/se-modules/se-system/pom.xml @@ -140,6 +140,13 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> + + <!-- license --> + <dependency> + <groupId>de.schlichtherle.truelicense</groupId> + <artifactId>truelicense-core</artifactId> + <version>1.33</version> + </dependency> </dependencies> <build> diff --git a/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java b/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java index 2732a6b..c75244f 100644 --- a/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java +++ b/se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java @@ -5,21 +5,15 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.se.system.domain.vo.LicenseExtraParamVo; import com.se.system.domain.vo.NacosConfigVo; import com.se.system.service.NacosService; -import org.omg.CORBA.ServerRequest; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.se.system.service.inte.IAServerInfoService; +import org.springframework.web.bind.annotation.*; import com.se.common.log.annotation.Log; import com.se.common.log.enums.BusinessType; import com.se.common.security.annotation.RequiresPermissions; -import com.se.system.domain.SysSoft; +import com.se.system.domain.*; import com.se.system.service.inte.ISysSoftService; import com.se.common.core.web.controller.BaseController; import com.se.common.core.web.domain.AjaxResult; @@ -133,4 +127,10 @@ } } } + + @GetMapping(value = "/test") + public void test() { + LicenseExtraParamVo serverInfos = IAServerInfoService.getServer("").getServerInfos(); + System.out.println("serverInfos = " + serverInfos); + } } diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorMg.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorMg.java new file mode 100644 index 0000000..c82bca6 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorMg.java @@ -0,0 +1,48 @@ +package com.se.system.domain.vo; + +import com.se.system.utils.ParamInitUtils; +import de.schlichtherle.license.LicenseContent; +import de.schlichtherle.license.LicenseManager; +import de.schlichtherle.license.LicenseParam; + +import java.io.File; +import java.text.MessageFormat; + +@SuppressWarnings("ALL") +public class LicenseCreatorMg { + public LicenseCreatorMg() { + } + + private LicenseCreatorParamVo param; + + public LicenseCreatorMg(LicenseCreatorParamVo param) { + this.param = param; + } + + /** + * <p>鐢熸垚License璇佷功</p> + * + * @return GxLicenseResult 璇佷功鐢熸垚缁撴灉 + */ + public LicenseResultVo generateLicense() { + try { + // 1銆佹牴鎹閮ㄤ紶鍏ョ殑鍒涘缓Lic鐨勫弬鏁颁俊鎭垵濮嬪寲lic鍙傛暟锛堢閽ラ儴鍒嗭級 + LicenseParam licenseParam = ParamInitUtils.initLicenseParam(param); + // 2銆佹牴鎹閮ㄤ紶鍏ョ殑鍒涘缓Lic鐨勫睘鎬т俊鎭垵濮嬪寲lic鍐呭锛堥櫎浜唗ruelicense鑷甫鐨勮繕鍖呮嫭鑷繁瀹氫箟鐨勶級 + LicenseContent licenseContent = ParamInitUtils.initLicenseContent(param); + // 3銆佹瀯寤篖ic绠$悊鍣� + LicenseManager licenseManager = new LicenseCustomMg(licenseParam); + // 4銆佹牴鎹畃aram浼犲叆鐨刲ic鐢熸垚鐨勮矾寰勫垱寤虹┖鏂囦欢 + File licenseFile = new File(this.param.getLicensePath()); + // 5銆侀�氳繃Lic绠$悊鍣紝灏嗗唴瀹瑰啓鍏ic鏂囦欢涓� + licenseManager.store(licenseContent, licenseFile); + return new LicenseResultVo("璇佷功鐢熸垚鎴愬姛锛�", licenseContent); + } catch (Exception e) { + System.out.println(e.getMessage()); + String message = MessageFormat.format("璇佷功鐢熸垚澶辫触锛侊細{0}", param); + System.out.println("message = " + message); + e.printStackTrace(); + return new LicenseResultVo(String.format("璇佷功鏂囦欢鐢熸垚澶辫触锛佸師鍥狅細%s", e.getMessage()), e); + } + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorParamVo.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorParamVo.java new file mode 100644 index 0000000..1c91b9d --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorParamVo.java @@ -0,0 +1,216 @@ +package com.se.system.domain.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.se.system.utils.*; + +import java.io.Serializable; +import java.util.Date; + +@SuppressWarnings("ALL") +public class LicenseCreatorParamVo implements Serializable { + public LicenseCreatorParamVo() { + } + + private static final long serialVersionUID = -7793154252684580872L; + + /** + * 璇佷功涓婚 + */ + private String subject; + + /** + * 绉侀挜鍒悕 + */ + private String privateAlias; + + /** + * 绉侀挜瀵嗙爜锛堥渶瑕佸Ε鍠勪繚绠★紝涓嶈兘璁╀娇鐢ㄨ�呯煡閬� + */ + private String keyPass; + + /** + * 绉侀挜搴撳瓨鍌ㄨ矾寰� + */ + private String privateKeysStorePath; + + /** + * 璁块棶绉侀挜搴撶殑瀵嗙爜 + */ + private String storePass; + + /** + * 璇佷功鐢熸垚璺緞 + */ + private String licensePath; + + /** + * 璇佷功鐢熸晥鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date issuedTime = new Date(); + + /** + * 璇佷功澶辨晥鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date expiryTime; + + /** + * 鐢ㄦ埛绫诲瀷 + */ + private String consumerType = "user"; + + /** + * 鐢ㄦ埛鏁伴噺 + */ + private Integer consumerAmount = 1; + + /** + * 鎻忚堪淇℃伅 + */ + private String description = ""; + + /** + * 棰濆鐨勬湇鍔″櫒纭欢鏍¢獙淇℃伅锛堟垨鑰呭叾浠栫殑淇℃伅閮藉彲浠ユ斁锛� + */ + private LicenseExtraParamVo licenseCheck; + + /** + * 璇佷功涓嬭浇鍦板潃 == 涓�鏃﹁瘉涔reate鎴愬姛锛岃繖涓�煎氨浼氬~鍏呬笂 + */ + private String licUrl; + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getPrivateAlias() { + return privateAlias; + } + + public void setPrivateAlias(String privateAlias) { + this.privateAlias = privateAlias; + } + + public String getKeyPass() { + return keyPass; + } + + public void setKeyPass(String keyPass) { + this.keyPass = keyPass; + } + + public String getStorePass() { + return storePass; + } + + public void setStorePass(String storePass) { + this.storePass = storePass; + } + + public String getLicensePath() { + return licensePath; + } + + public void setLicensePath(String licensePath) { + this.licensePath = licensePath; + } + + public String getPrivateKeysStorePath() { + return privateKeysStorePath; + } + + public void setPrivateKeysStorePath(String privateKeysStorePath) { + this.privateKeysStorePath = privateKeysStorePath; + } + + public Date getIssuedTime() { + return issuedTime; + } + + public void setIssuedTime(Date issuedTime) { + this.issuedTime = issuedTime; + } + + public Date getExpiryTime() { + return expiryTime; + } + + public void setExpiryTime(Date expiryTime) { + this.expiryTime = expiryTime; + } + + public String getConsumerType() { + return consumerType; + } + + public void setConsumerType(String consumerType) { + this.consumerType = consumerType; + } + + public Integer getConsumerAmount() { + return consumerAmount; + } + + public void setConsumerAmount(Integer consumerAmount) { + this.consumerAmount = consumerAmount; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public LicenseExtraParamVo getLicenseCheck() { + return licenseCheck; + } + + public void setLicenseCheck(LicenseExtraParamVo licenseCheck) { + this.licenseCheck = licenseCheck; + } + + public String getLicUrl() { + return licUrl; + } + + public void setLicUrl(String licUrl) { + this.licUrl = licUrl; + } + + @Override + public String toString() { + return "LicenseCreatorParam{" + + "subject='" + subject + '\'' + + ", privateAlias='" + privateAlias + '\'' + + ", keyPass='" + keyPass + '\'' + + ", privateKeysStorePath='" + privateKeysStorePath + '\'' + + ", storePass='" + storePass + '\'' + + ", licensePath='" + licensePath + '\'' + + ", issuedTime=" + issuedTime + + ", expiryTime=" + expiryTime + + ", consumerType='" + consumerType + '\'' + + ", consumerAmount=" + consumerAmount + + ", description='" + description + '\'' + + ", licenseCheck=" + licenseCheck + + ", licUrl='" + licUrl + '\'' + + '}'; + } + + public static void main(String[] args) { + LicenseCreatorParamVo param = new LicenseCreatorParamVo(); + LicenseExtraParamVo check = new LicenseExtraParamVo(); + param.setLicenseCheck(check); + System.out.println(JsonUtils.objectToJson(param)); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCustomMg.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCustomMg.java new file mode 100644 index 0000000..ddc7723 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCustomMg.java @@ -0,0 +1,247 @@ +package com.se.system.domain.vo; + +import com.se.system.service.inte.IAServerInfoService; +import com.se.system.utils.*; +import de.schlichtherle.license.*; +import de.schlichtherle.xml.GenericCertificate; + +import java.beans.XMLDecoder; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; +import java.util.Date; +import java.util.List; + +@SuppressWarnings("ALL") +public class LicenseCustomMg extends LicenseManager { + public LicenseCustomMg() { + } + + /** + * XML缂栫爜 + */ + private static final String XML_CHARSET = "UTF-8"; + /** + * 榛樿BUFF_SIZE + */ + private static final int DEFAULT_BUFF_SIZE = 8 * 1024; + + public LicenseCustomMg(LicenseParam param) { + super(param); + } + + /** + * <p>閲嶅啓LicenseManager鐨刢reate鏂规硶</p> + * + * @param content LicenseContent 璇佷功淇℃伅 + * @param notary notary 鍏淇℃伅 + * @return byte[] + * @throws Exception 榛樿寮傚父 + */ + @Override + protected synchronized byte[] create(LicenseContent content, LicenseNotary notary) throws Exception { + initialize(content); + /** 鍔犲叆鑷繁棰濆鐨勮鍙唴瀹逛俊鎭璇� == 涓昏鍙嬫儏鎻愮ず */ + this.validateCreate(content); + final GenericCertificate certificate = notary.sign(content); + return getPrivacyGuard().cert2key(certificate); + } + + + /** + * <p>閲嶅啓install鏂规硶</p> + * + * @param key 瀵嗗寵 + * @param notary 鍏淇℃伅 + * @return LicenseContent 璇佷功淇℃伅 + * @throws Exception 榛樿寮傚父 + */ + @Override + protected synchronized LicenseContent install(final byte[] key, final LicenseNotary notary) throws Exception { + final GenericCertificate certificate = getPrivacyGuard().key2cert(key); + notary.verify(certificate); + final LicenseContent licenseContent = (LicenseContent) this.load(certificate.getEncoded()); + /** 澧炲姞棰濆鐨勮嚜宸辩殑license鏍¢獙鏂规硶锛屾牎楠宨p銆乵ac銆乧pu搴忓垪鍙风瓑 */ + this.validate(licenseContent); + setLicenseKey(key); + setCertificate(certificate); + return licenseContent; + } + + /** + * <p>閲嶅啓verify鏂规硶</p> + * + * @param notary 鍏淇℃伅 + * @return LicenseContent 璇佷功淇℃伅 + * @throws Exception 榛樿寮傚父 + */ + @Override + protected synchronized LicenseContent verify(final LicenseNotary notary) throws Exception { + final byte[] key = getLicenseKey(); + if (null == key) { + throw new NoLicenseInstalledException(getLicenseParam().getSubject()); + } + GenericCertificate certificate = getPrivacyGuard().key2cert(key); + notary.verify(certificate); + final LicenseContent content = (LicenseContent) this.load(certificate.getEncoded()); + /** 澧炲姞棰濆鐨勮嚜宸辩殑license鏍¢獙鏂规硶锛屾牎楠宨p銆乵ac銆乧pu搴忓垪鍙风瓑 */ + this.validate(content); + setCertificate(certificate); + return content; + } + + /** + * <p>鏍¢獙鐢熸垚璇佷功鐨勫弬鏁颁俊鎭�</p> + * + * @param content LicenseContent 璇佷功鍐呭 + * @throws LicenseContentException 璇佷功鍐呭閿欒寮傚父 + */ + protected synchronized void validateCreate(final LicenseContent content) throws LicenseContentException { + // 褰撳墠鏃堕棿 + final Date now = new Date(); + // 鐢熸晥鏃堕棿 + final Date notBefore = content.getNotBefore(); + // 澶辨晥鏃堕棿 + final Date notAfter = content.getNotAfter(); + + if (null != notAfter && now.after(notAfter)) { + String message = "璇佷功澶辨晥鏃堕棿涓嶈兘鏃╀簬褰撳墠鏃堕棿"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + if (null != notBefore && null != notAfter && notAfter.before(notBefore)) { + String message = "璇佷功鐢熸晥鏃堕棿涓嶈兘鏅氫簬璇佷功澶辨晥鏃堕棿"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + final String consumerType = content.getConsumerType(); + if (null == consumerType) { + String message = "鐢ㄦ埛绫诲瀷涓嶈兘涓虹┖"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + + } + + /** + * <p>閲嶅啓validate鏂规硶锛屽鍔爄p鍦板潃銆乵ac鍦板潃銆乧pu搴忓垪鍙风瓑鍏朵粬淇℃伅鐨勬牎楠�</p> + * + * @param content LicenseContent 璇佷功鍐呭 + * @throws LicenseContentException 璇佷功鍐呭閿欒寮傚父 + */ + @Override + protected synchronized void validate(final LicenseContent content) throws LicenseContentException { + // 褰撳墠鏃堕棿 + final Date now = new Date(); + final Date notAfter = content.getNotAfter(); + if (now.after(notAfter)) { + throw new LicenseContentException("绯荤粺璇佷功杩囨湡锛屽綋鍓嶆椂闂村凡瓒呰繃璇佷功鏈夋晥鏈� -- " + + DateUtils.date2Str(content.getNotAfter()) + ""); + } + // 1銆� 棣栧厛璋冪敤鐖剁被鐨剉alidate鏂规硶 + super.validate(content); + // 2銆� 鐒跺悗鏍¢獙鑷畾涔夌殑License鍙傛暟 License涓彲琚厑璁哥殑鍙傛暟淇℃伅 + LicenseExtraParamVo expectedCheck = (LicenseExtraParamVo) content.getExtra(); + // 褰撳墠鏈嶅姟鍣ㄧ湡瀹炵殑鍙傛暟淇℃伅 + LicenseExtraParamVo serverCheckModel = IAServerInfoService.getServer(null).getServerInfos(); + if (expectedCheck != null && serverCheckModel != null) { + // 鏍¢獙IP鍦板潃 + if (expectedCheck.isIpCheck() && !checkIpAddress(expectedCheck.getIpAddress(), serverCheckModel.getIpAddress())) { + String message = "绯荤粺璇佷功鏃犳晥锛屽綋鍓嶆湇鍔″櫒鐨処P娌″湪鎺堟潈鑼冨洿鍐�"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + // 鏍¢獙Mac鍦板潃 + if (expectedCheck.isMacCheck() && !checkIpAddress(expectedCheck.getMacAddress(), serverCheckModel.getMacAddress())) { + String message = "绯荤粺璇佷功鏃犳晥锛屽綋鍓嶆湇鍔″櫒鐨凪ac鍦板潃娌″湪鎺堟潈鑼冨洿鍐�"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + // 鏍¢獙涓绘澘搴忓垪鍙� + if (expectedCheck.isBoardCheck() && !checkSerial(expectedCheck.getMainBoardSerial(), serverCheckModel.getMainBoardSerial())) { + String message = "绯荤粺璇佷功鏃犳晥锛屽綋鍓嶆湇鍔″櫒鐨勪富鏉垮簭鍒楀彿娌″湪鎺堟潈鑼冨洿鍐�"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + // 鏍¢獙CPU搴忓垪鍙� + if (expectedCheck.isCpuCheck() && !checkSerial(expectedCheck.getCpuSerial(), serverCheckModel.getCpuSerial())) { + String message = "绯荤粺璇佷功鏃犳晥锛屽綋鍓嶆湇鍔″櫒鐨凜PU搴忓垪鍙锋病鍦ㄦ巿鏉冭寖鍥村唴"; + System.out.println("message = " + message); + throw new LicenseContentException(message); + } + } else { + System.out.println("涓嶈兘鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭�"); + throw new LicenseContentException("涓嶈兘鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭�"); + } + } + + /** + * <p>閲嶅啓XMLDecoder瑙f瀽XML</p> + */ + private Object load(String encoded) { + BufferedInputStream inputStream = null; + XMLDecoder decoder = null; + try { + inputStream = new BufferedInputStream(new ByteArrayInputStream(encoded.getBytes(XML_CHARSET))); + decoder = new XMLDecoder(new BufferedInputStream(inputStream, DEFAULT_BUFF_SIZE), null, null); + return decoder.readObject(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } finally { + try { + if (decoder != null) { + decoder.close(); + } + if (inputStream != null) { + inputStream.close(); + } + } catch (Exception e) { + System.out.println("XMLDecoder瑙f瀽XML澶辫触 "); + e.printStackTrace(); + } + } + return null; + + } + + /** + * 鏍¢獙褰撳墠鏈嶅姟鍣ㄧ殑IP/Mac鍦板潃鏄惁鍦ㄥ彲琚厑璁哥殑IP鑼冨洿鍐�<br/> + * 濡傛灉瀛樺湪IP鍦ㄥ彲琚厑璁哥殑IP/Mac鍦板潃鑼冨洿鍐咃紝鍒欒繑鍥瀟rue + */ + private boolean checkIpAddress(List<String> expectedList, List<String> serverList) { + + /** 濡傛灉鏈熸湜鐨処P鍒楄〃绌虹洿鎺ヨ繑鍥瀎alse锛屽洜涓烘棦鐒堕獙璇乮p锛岃繖涓�椤瑰繀椤昏鏈夊厓绱� */ + if (CommonUtils.isEmpty(expectedList)) { + return false; + } + /** 濡傛灉褰撳墠鏈嶅姟鍣ㄧ殑IP鍒楄〃绌虹洿鎺ヨ繑鍥瀎alse锛屽洜涓烘湇鍔″櫒涓嶅彲鑳借幏鍙栦笉鍒癷p锛屾病鏈夌殑璇濋獙璇佷釜閿ゅ瓙 */ + if (CommonUtils.isEmpty(serverList)) { + return false; + } + for (String expected : expectedList) { + if (serverList.contains(expected.trim())) { + return true; + } + } + return false; + + } + + /** + * <p>鏍¢獙褰撳墠鏈嶅姟鍣ㄧ‖浠讹紙涓绘澘銆丆PU绛夛級搴忓垪鍙锋槸鍚﹀湪鍙厑璁歌寖鍥村唴</p> + * + * @param expectedSerial 涓绘澘淇℃伅 + * @param serverSerial 鏈嶅姟鍣ㄤ俊鎭� + * @return boolean + */ + private boolean checkSerial(String expectedSerial, String serverSerial) { + if (CommonUtils.isNotEmpty(expectedSerial)) { + if (CommonUtils.isNotEmpty(serverSerial)) { + return expectedSerial.equals(serverSerial); + } + return false; + } else { + return true; + } + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseExtraParamVo.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseExtraParamVo.java new file mode 100644 index 0000000..bd4fa03 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseExtraParamVo.java @@ -0,0 +1,182 @@ +package com.se.system.domain.vo; + +import java.io.Serializable; +import java.util.List; + +@SuppressWarnings("ALL") +public class LicenseExtraParamVo implements Serializable { + public LicenseExtraParamVo() { + } + + private static final long serialVersionUID = 8600137500316662317L; + + /** + * 鏄惁璁よ瘉ip + */ + private boolean isIpCheck; + + /** + * 鍙鍏佽鐨処P鍦板潃 + */ + private List<String> ipAddress; + + /** + * 鏄惁璁よ瘉mac + */ + private boolean isMacCheck; + + /** + * 鍙鍏佽鐨刴ac鍦板潃 + */ + private List<String> macAddress; + + /** + * 鏄惁璁よ瘉cpu搴忓垪鍙� + */ + private boolean isCpuCheck; + + /** + * 鍙鍏佽鐨凜PU搴忓垪鍙� + */ + private String cpuSerial; + + /** + * 鏄惁璁よ瘉涓绘澘鍙� + */ + private boolean isBoardCheck; + + /** + * 鍙鍏佽鐨勪富鏉垮簭鍒楀彿 + */ + private String mainBoardSerial; + + /** + * 鏄惁闄愬埗娉ㄥ唽浜烘暟 + */ + private boolean isRegisterCheck; + + /** + * 闄愬埗绯荤粺涓彲娉ㄥ唽鐨勪汉鏁� + */ + private Long registerAmount; + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public List<String> getIpAddress() { + return ipAddress; + } + + public void setIpAddress(List<String> ipAddress) { + this.ipAddress = ipAddress; + } + + public List<String> getMacAddress() { + return macAddress; + } + + public void setMacAddress(List<String> macAddress) { + this.macAddress = macAddress; + } + + public String getCpuSerial() { + return cpuSerial; + } + + public void setCpuSerial(String cpuSerial) { + this.cpuSerial = cpuSerial; + } + + public String getMainBoardSerial() { + return mainBoardSerial; + } + + public void setMainBoardSerial(String mainBoardSerial) { + this.mainBoardSerial = mainBoardSerial; + } + + public boolean isIpCheck() { + return isIpCheck; + } + + public void setIpCheck(boolean ipCheck) { + isIpCheck = ipCheck; + } + + public boolean isMacCheck() { + return isMacCheck; + } + + public void setMacCheck(boolean macCheck) { + isMacCheck = macCheck; + } + + public boolean isCpuCheck() { + return isCpuCheck; + } + + public void setCpuCheck(boolean cpuCheck) { + isCpuCheck = cpuCheck; + } + + public boolean isBoardCheck() { + return isBoardCheck; + } + + public void setBoardCheck(boolean boardCheck) { + isBoardCheck = boardCheck; + } + + public Long getRegisterAmount() { + return registerAmount; + } + + public void setRegisterAmount(Long registerAmount) { + this.registerAmount = registerAmount; + } + + public boolean isRegisterCheck() { + return isRegisterCheck; + } + + public void setRegisterCheck(boolean registerCheck) { + isRegisterCheck = registerCheck; + } + + @Override + public String toString() { + return "LicenseExtraParam{" + + " ipAddress=" + ipAddress + + ", macAddress=" + macAddress + + ", cpuSerial='" + cpuSerial + '\'' + + ", mainBoardSerial='" + mainBoardSerial + '\'' + + ", registerAmount='" + registerAmount + '\'' + + " }"; + } + + public String toJsonString() { + StringBuilder jsonBuilder = new StringBuilder(); + jsonBuilder.append("{"); + jsonBuilder.append("\"ipAddress\": ["); + for (String ip : ipAddress) { + jsonBuilder.append("\"").append(ip).append("\", "); + } + jsonBuilder.deleteCharAt(jsonBuilder.length() - 1); + jsonBuilder.deleteCharAt(jsonBuilder.length() - 1); + jsonBuilder.append("], "); + jsonBuilder.append("\"macAddress\": ["); + for (String mac : macAddress) { + jsonBuilder.append("\"").append(mac).append("\", "); + } + jsonBuilder.deleteCharAt(jsonBuilder.length() - 1); + jsonBuilder.deleteCharAt(jsonBuilder.length() - 1); + jsonBuilder.append("], "); + jsonBuilder.append("\"cpuSerial\": \"").append(cpuSerial).append("\", "); + jsonBuilder.append("\"mainBoardSerial\": \"").append(mainBoardSerial).append("\", "); + jsonBuilder.append("\"registerAmount\": \"").append(registerAmount).append("\""); + jsonBuilder.append("}"); + + return jsonBuilder.toString(); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseResultVo.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseResultVo.java new file mode 100644 index 0000000..13decc2 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseResultVo.java @@ -0,0 +1,86 @@ +package com.se.system.domain.vo; + +import de.schlichtherle.license.LicenseContent; + +@SuppressWarnings("ALL") +public class LicenseResultVo { + public LicenseResultVo() { + } + + /** + * 楠岃瘉缁撴灉锛宼rue涓洪獙璇侀�氳繃锛宖alse鍒欎负澶辫触 + */ + private Boolean result; + /** + * 闄勫姞淇℃伅 + */ + private String message; + /** + * 璇佷功鍐呭 + */ + private LicenseContent content; + /** + * 妫�楠屽け璐ラ敊璇� + */ + private Exception exception; + + public LicenseResultVo(LicenseContent content) { + this.result = true; + this.content = content; + } + + public LicenseResultVo(String message, LicenseContent content) { + this.result = true; + this.message = message; + this.content = content; + } + + public LicenseResultVo(Exception exception) { + this.result = false; + this.exception = exception; + } + + public LicenseResultVo(String message, Exception exception) { + this.result = false; + this.message = message; + this.exception = exception; + } + + public LicenseResultVo(boolean result, String message, Exception exception) { + this.result = result; + this.message = message; + this.exception = exception; + } + + public Boolean getResult() { + return result; + } + + public void setResult(Boolean result) { + this.result = result; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public LicenseContent getContent() { + return content; + } + + public void setContent(LicenseContent content) { + this.content = content; + } + + public Exception getException() { + return exception; + } + + public void setException(Exception exception) { + this.exception = exception; + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyMg.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyMg.java new file mode 100644 index 0000000..1c10ca7 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyMg.java @@ -0,0 +1,102 @@ +package com.se.system.domain.vo; + +import com.se.system.utils.*; +import de.schlichtherle.license.*; + +import java.io.File; +import java.io.FileNotFoundException; +import java.text.DateFormat; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; + +@SuppressWarnings("ALL") +public class LicenseVerifyMg { + public LicenseVerifyMg() { + } + + /** + * <p>瀹夎License璇佷功</p> + * + * @param param License鏍¢獙绫婚渶瑕佺殑鍙傛暟 + */ + public synchronized LicenseResultVo install(LicenseVerifyParamVo param) { + try { + /** 1銆佸垵濮嬪寲License璇佷功鍙傛暟 */ + LicenseParam licenseParam = ParamInitUtils.initLicenseParam(param); + /** 2銆佸垱寤篖icense璇佷功绠$悊鍣ㄥ璞� */ +// LicenseManager licenseManager =new LicenseManager(licenseParam); + // 璧拌嚜瀹氫箟鐨凩ic绠$悊 + LicenseCustomMg licenseManager = new LicenseCustomMg(licenseParam); + /** 3銆佽幏鍙栬瀹夎鐨勮瘉涔︽枃浠� */ + File licenseFile = new File(param.getLicensePath()); + /** 4銆佸鏋滀箣鍓嶅畨瑁呰繃璇佷功锛屽厛鍗歌浇涔嬪墠鐨勮瘉涔� == 缁檔ull */ + licenseManager.uninstall(); + /** 5銆佸紑濮嬪畨瑁� */ + LicenseContent content = licenseManager.install(licenseFile); + String message = MessageFormat.format("璇佷功瀹夎鎴愬姛锛岃瘉涔︽湁鏁堟湡锛歿0} - {1}", + DateUtils.date2Str(content.getNotBefore()), DateUtils.date2Str(content.getNotAfter())); + System.out.println("message = " + message); + return new LicenseResultVo(message, content); + } catch (LicenseContentException contentExc) { + String message = contentExc.getMessage(); + System.out.println("message = " + message); + return new LicenseResultVo(false, message, contentExc); + } catch (Exception e) { + e.printStackTrace(); + return new LicenseResultVo(false, e.getMessage(), e); + } + } + + /** + * <p>鏍¢獙License璇佷功</p> + * + * @param param License鏍¢獙绫婚渶瑕佺殑鍙傛暟 + */ + public LicenseResultVo verify(LicenseVerifyParamVo param) { + + /** 1銆佸垵濮嬪寲License璇佷功鍙傛暟 */ + LicenseParam licenseParam = ParamInitUtils.initLicenseParam(param); + /** 2銆佸垱寤篖icense璇佷功绠$悊鍣ㄥ璞� */ + LicenseManager licenseManager = new LicenseCustomMg(licenseParam); + DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + /** 3銆佸紑濮嬫牎楠岃瘉涔� */ + try { + /**杩欓噷瑕佸垽鏂笅lic鏂囦欢鏄笉鏄鐢ㄦ埛鎭舵剰鍒犻櫎浜�*/ + String licensePath = param.getLicensePath(); + if (licensePath == null || licensePath == "") { + String msg = "license.lic璺緞鏈寚瀹氾紝楠岃瘉涓嶉�氳繃锛�"; + System.out.println("msg = " + msg); + return new LicenseResultVo(false, msg, new Exception(msg)); + } + /**涓嬮潰涓や釜妫�娴嬪鏋滄枃浠朵笉瀛樺湪浼氭姏寮傚父锛岀劧鍚庝細琚崟鑾峰埌*/ + if (licensePath.contains("classpath:")) { + /**妫�娴嬩笅褰撳墠搴旂敤鐨刢lasses璺緞涓嬫湁娌℃湁lic鏂囦欢*/ + // ResourceUtils.getFile(licensePath); + } else { + /**鐩存帴鏋勫缓file瀵硅薄妫�娴媗ic鏂囦欢鏄惁瀛樺湪*/ + new File(licensePath); + } + LicenseContent licenseContent = licenseManager.verify(); + String message = MessageFormat.format("璇佷功鏍¢獙閫氳繃锛岃瘉涔︽湁鏁堟湡锛歿0} - {1}", + format.format(licenseContent.getNotBefore()), format.format(licenseContent.getNotAfter())); + System.out.println("message = " + message); + return new LicenseResultVo(message, licenseContent); + } catch (NoLicenseInstalledException ex) { + String message = "璇佷功鏈畨瑁咃紒"; + System.out.println("message = " + message); + return new LicenseResultVo(false, message, ex); + } catch (LicenseContentException cex) { + cex.printStackTrace(); + return new LicenseResultVo(false, cex.getMessage(), cex); + } catch (FileNotFoundException fnfe) { + String msg = String.format("license.lic鏂囦欢锛�%s锛変笉瀛樺湪锛岄獙璇佸け璐ワ紒", param.getLicensePath()); + System.out.println("msg = " + msg); + return new LicenseResultVo(false, msg, fnfe); + } catch (Exception e) { + String message = "璇佷功鏍¢獙澶辫触锛�"; + System.out.println("message = " + message); + return new LicenseResultVo(false, message, e); + } + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java new file mode 100644 index 0000000..86aa99b --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java @@ -0,0 +1,91 @@ +package com.se.system.domain.vo; + +@SuppressWarnings("ALL") +public class LicenseVerifyParamVo { + public LicenseVerifyParamVo() { + } + + /** + * 璇佷功涓婚 + */ + private String subject; + + /** + * 鍏挜鍒悕 + */ + private String publicAlias; + + /** + * 璁块棶鍏挜搴撶殑瀵嗙爜 + */ + private String storePass; + + /** + * 璇佷功鐢熸垚璺緞 + */ + private String licensePath; + + /** + * 鍏挜搴撳瓨鍌ㄨ矾寰� + */ + private String publicKeysStorePath; + + public LicenseVerifyParamVo(String subject, String publicAlias, String storePass, String licensePath, String publicKeysStorePath) { + this.subject = subject; + this.publicAlias = publicAlias; + this.storePass = storePass; + this.licensePath = licensePath; + this.publicKeysStorePath = publicKeysStorePath; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getPublicAlias() { + return publicAlias; + } + + public void setPublicAlias(String publicAlias) { + this.publicAlias = publicAlias; + } + + public String getStorePass() { + return storePass; + } + + public void setStorePass(String storePass) { + this.storePass = storePass; + } + + public String getLicensePath() { + return licensePath; + } + + public void setLicensePath(String licensePath) { + this.licensePath = licensePath; + } + + public String getPublicKeysStorePath() { + return publicKeysStorePath; + } + + public void setPublicKeysStorePath(String publicKeysStorePath) { + this.publicKeysStorePath = publicKeysStorePath; + } + + @Override + public String toString() { + return "LicenseVerifyParam{" + + "subject='" + subject + '\'' + + ", publicAlias='" + publicAlias + '\'' + + ", storePass='" + storePass + '\'' + + ", licensePath='" + licensePath + '\'' + + ", publicKeysStorePath='" + publicKeysStorePath + '\'' + + '}'; + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/service/NacosService.java b/se-modules/se-system/src/main/java/com/se/system/service/NacosService.java index 5c642e4..720e25c 100644 --- a/se-modules/se-system/src/main/java/com/se/system/service/NacosService.java +++ b/se-modules/se-system/src/main/java/com/se/system/service/NacosService.java @@ -1,11 +1,8 @@ package com.se.system.service; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.se.system.domain.vo.NacosConfigVo; import com.se.system.utils.CaffeineUtils; -import com.se.system.utils.StringUtils; -import nonapi.io.github.classgraph.json.JSONUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.stereotype.Component; @@ -18,7 +15,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.util.Map; @Component diff --git a/se-modules/se-system/src/main/java/com/se/system/service/impl/LinuxServerInfoService.java b/se-modules/se-system/src/main/java/com/se/system/service/impl/LinuxServerInfoService.java new file mode 100644 index 0000000..0812809 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/service/impl/LinuxServerInfoService.java @@ -0,0 +1,63 @@ +package com.se.system.service.impl; + +import com.se.system.service.inte.IAServerInfoService; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +@SuppressWarnings("ALL") +public class LinuxServerInfoService extends IAServerInfoService { + public LinuxServerInfoService() { + } + + private final String[] CPU_SHELL = {"/bin/bash", "-c", "dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"}; + + private final String[] MAIN_BOARD_SHELL = {"/bin/bash", "-c", "dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"}; + + @Override + protected String getCPUSerial() throws Exception { + String result = ""; + String CPU_ID_CMD = "dmidecode"; + BufferedReader bufferedReader = null; + Process p = null; + try { + p = Runtime.getRuntime().exec(new String[]{"sh", "-c", CPU_ID_CMD}); + bufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = null; + int index = -1; + while ((line = bufferedReader.readLine()) != null) { + // 瀵绘壘鏍囩ず瀛楃涓瞇hwaddr] + index = line.toLowerCase().indexOf("uuid"); + if (index >= 0) { + // 鍙栧嚭mac鍦板潃骞跺幓闄�2杈圭┖鏍� + result = line.substring(index + "uuid".length() + 1).trim(); + break; + } + } + } catch (IOException e) { + System.out.println("鑾峰彇cpu纭欢淇℃伅澶辫触 " + e); + } + return result.trim(); + } + + @Override + protected String getMainBoardSerial() throws Exception { + String result = ""; + String maniBord_cmd = "dmidecode | grep 'Serial Number' | awk '{print $3}' | tail -1"; + Process p; + try { + p = Runtime.getRuntime().exec(new String[]{"sh", "-c", maniBord_cmd}); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = br.readLine()) != null) { + result += line; + break; + } + br.close(); + } catch (IOException e) { + System.out.println("鑾峰彇涓绘澘淇℃伅閿欒" + e); + } + return result; + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/service/impl/WindowsServerInfoService.java b/se-modules/se-system/src/main/java/com/se/system/service/impl/WindowsServerInfoService.java new file mode 100644 index 0000000..0ddd9d8 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/service/impl/WindowsServerInfoService.java @@ -0,0 +1,74 @@ +package com.se.system.service.impl; + +import com.se.system.service.inte.IAServerInfoService; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.InputStreamReader; + +@SuppressWarnings("ALL") +public class WindowsServerInfoService extends IAServerInfoService { + public WindowsServerInfoService() { + } + + private final String CPU_COMMAND = "wmic cpu get processorid"; + + private final String MAIN_BOARD_COMMAND = "wmic baseboard get serialnumber"; + + @Override + protected String getCPUSerial() throws Exception { + String result = ""; + try { + File file = File.createTempFile("tmp", ".vbs"); + file.deleteOnExit(); + FileWriter fw = new FileWriter(file); + String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_Processor\") \n" + + "For Each objItem in colItems \n" + " Wscript.Echo objItem.ProcessorId \n" + + " exit for ' do the first cpu only! \n" + "Next \n"; + + fw.write(vbs); + fw.close(); + Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = input.readLine()) != null) { + result += line; + } + input.close(); + file.delete(); + } catch (Exception e) { + System.out.println("鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭け璐� " + e); + } + return result.trim(); + } + + @Override + protected String getMainBoardSerial() throws Exception { + String result = ""; + try { + File file = File.createTempFile("realhowto", ".vbs"); + file.deleteOnExit(); + FileWriter fw = new FileWriter(file); + + String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + + " exit for ' do the first cpu only! \n" + "Next \n"; + + fw.write(vbs); + fw.close(); + Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = input.readLine()) != null) { + result += line; + } + input.close(); + } catch (Exception e) { + System.out.println("鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭け璐� " + e); + } + return result.trim(); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/service/inte/IACustomVerifyListener.java b/se-modules/se-system/src/main/java/com/se/system/service/inte/IACustomVerifyListener.java new file mode 100644 index 0000000..49ce124 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/service/inte/IACustomVerifyListener.java @@ -0,0 +1,38 @@ +package com.se.system.service.inte; + +import com.se.system.domain.vo.*; + +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("ALL") +public abstract class IACustomVerifyListener { + /** + * 杞欢璇佷功鍙傛暟鍏ㄥ眬楠岃瘉鐩戝惉瀹瑰櫒 + */ + private static final List<IACustomVerifyListener> CUSTOM_VERIFY_LISTENER_LIST = new ArrayList<>(16); + + public static List<IACustomVerifyListener> getCustomListenerList() { + return CUSTOM_VERIFY_LISTENER_LIST; + } + + /*** + * 榛樿鏋勯�犲嚱鏁帮紝骞蹭簡涓�浠朵簨鎯咃紝灏辨槸浼氭妸鎵�鏈夊疄鐜颁簡杩欎釜鎶借薄绫荤殑瀛愮被瀹炰緥鍏ㄩ儴娣诲姞鍒板叏灞�鑷畾涔夐獙璇佺洃鍚櫒鍒楄〃涓� + * 鍥犱负鍦ㄨ皟鐢ㄥ瓙绫荤殑鏋勯�犲嚱鏁版椂锛屼細棣栧厛璋冪敤鐖剁被鐨勬瀯閫犲櫒 + */ + public IACustomVerifyListener() { + addCustomListener(this); + } + + public synchronized static void addCustomListener(IACustomVerifyListener verifyListener) { + CUSTOM_VERIFY_LISTENER_LIST.add(verifyListener); + } + + /** + * 涓氬姟绯荤粺鑷畾涔夎瘉涔﹁璇佹柟娉� + * + * @param licenseExtra 鑷畾涔夐獙璇佸弬鏁� + * @return boolean 鏄惁鎴愬姛 + */ + public abstract boolean verify(LicenseExtraParamVo licenseExtra); +} diff --git a/se-modules/se-system/src/main/java/com/se/system/service/inte/IAServerInfoService.java b/se-modules/se-system/src/main/java/com/se/system/service/inte/IAServerInfoService.java new file mode 100644 index 0000000..00b9aa1 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/service/inte/IAServerInfoService.java @@ -0,0 +1,214 @@ +package com.se.system.service.inte; + +import com.se.system.domain.vo.*; +import com.se.system.service.impl.LinuxServerInfoService; +import com.se.system.service.impl.WindowsServerInfoService; +import com.se.system.utils.*; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.stream.Collectors; + +@SuppressWarnings("ALL") +public abstract class IAServerInfoService { + public IAServerInfoService() { + } + + private static class GxServerInfosContainer { + private static List<String> ipAddress = null; + private static List<String> macAddress = null; + private static String cpuSerial = null; + private static String mainBoardSerial = null; + private static boolean isIpCheck = true; + private static boolean isMacCheck = true; + private static boolean isCpuCheck = true; + private static boolean isBoardCheck = true; + } + + /** + * <p>缁勮闇�瑕侀澶栨牎楠岀殑License鍙傛暟</p> + * + * @return LicenseExtraParam 鑷畾涔夋牎楠屽弬鏁� + */ + public LicenseExtraParamVo getServerInfos() { + LicenseExtraParamVo result = new LicenseExtraParamVo(); + try { + initServerInfos(); + result.setIpAddress(GxServerInfosContainer.ipAddress); + result.setMacAddress(GxServerInfosContainer.macAddress); + result.setCpuSerial(GxServerInfosContainer.cpuSerial); + result.setMainBoardSerial(GxServerInfosContainer.mainBoardSerial); + result.setIpCheck(GxServerInfosContainer.isIpCheck); + result.setMacCheck(GxServerInfosContainer.isMacCheck); + result.setCpuCheck(GxServerInfosContainer.isCpuCheck); + result.setBoardCheck(GxServerInfosContainer.isBoardCheck); + } catch (Exception e) { + System.out.println("鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭け璐� " + e); + } + return result; + } + + /** + * <p>鍒濆鍖栨湇鍔″櫒纭欢淇℃伅锛屽苟灏嗕俊鎭紦瀛樺埌鍐呭瓨</p> + * + * @throws Exception 榛樿寮傚父 + */ + private void initServerInfos() throws Exception { + if (GxServerInfosContainer.ipAddress == null) { + GxServerInfosContainer.ipAddress = this.getIpAddress(); + } + if (GxServerInfosContainer.macAddress == null) { + GxServerInfosContainer.macAddress = this.getMacAddress(); + } + if (GxServerInfosContainer.cpuSerial == null) { + GxServerInfosContainer.cpuSerial = this.getCPUSerial(); + } + if (GxServerInfosContainer.mainBoardSerial == null) { + GxServerInfosContainer.mainBoardSerial = this.getMainBoardSerial(); + } + } + + /** + * <p>鑾峰彇IP鍦板潃</p> + * + * @return List<String> IP鍦板潃 + * @throws Exception 榛樿寮傚父 + */ + public List<String> getIpAddress() throws Exception { + /** 鑾峰彇鎵�鏈夌綉缁滄帴鍙� */ + List<InetAddress> inetAddresses = getLocalAllInetAddress(); + if (CommonUtils.isNotEmpty(inetAddresses)) { + return inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList()); + } + return null; + } + + /** + * <p>鑾峰彇Mac鍦板潃</p> + * + * @return List<String> Mac鍦板潃 + * @throws Exception 榛樿寮傚父 + */ + public List<String> getMacAddress() throws Exception { + /** 鑾峰彇鎵�鏈夌綉缁滄帴鍙� */ + List<InetAddress> inetAddresses = getLocalAllInetAddress(); + if (CommonUtils.isNotEmpty(inetAddresses)) { + return inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList()); + } + return null; + } + + /** + * <p>鑾峰彇鏈嶅姟鍣ㄤ俊鎭�</p> + * + * @param osName 绯荤粺绫诲瀷 + * @return AGxServerInfos 鏈嶅姟淇℃伅 + */ + public static IAServerInfoService getServer(String osName) { + if ("".equals(osName) || osName == null) { + osName = System.getProperty("os.name").toLowerCase(); + } + IAServerInfoService abstractServerInfos; + // 鏍规嵁涓嶅悓鎿嶄綔绯荤粺绫诲瀷閫夋嫨涓嶅悓鐨勬暟鎹幏鍙栨柟娉� + if (osName.startsWith("windows")) { + abstractServerInfos = new WindowsServerInfoService(); + } else if (osName.startsWith("linux")) { + abstractServerInfos = new LinuxServerInfoService(); + } else {// 鍏朵粬鏈嶅姟鍣ㄧ被鍨� + abstractServerInfos = new LinuxServerInfoService(); + } + return abstractServerInfos; + } + + /** + * <p>鑾峰彇鏈嶅姟鍣ㄤ复鏃剁鐩樹綅缃�</p> + */ + public static String getServerTempPath() { + + String property = System.getProperty("user.dir"); + return property; + + // String osName = System.getProperty("os.name").toLowerCase(); + ////鏍规嵁涓嶅悓鎿嶄綔绯荤粺绫诲瀷閫夋嫨涓嶅悓鐨勬暟鎹幏鍙栨柟娉� + // if (osName.startsWith("windows")) { + // return property.substring(0,property.indexOf(":")+1); + //} else if (osName.startsWith("linux")) { + // return "/home"; + //}else{//鍏朵粬鏈嶅姟鍣ㄧ被鍨� + // return "/home"; + //} + } + + /** + * <p>鑾峰彇CPU搴忓垪鍙�</p> + * + * @return String 涓绘澘搴忓垪鍙� + * @throws Exception 榛樿寮傚父 + */ + protected abstract String getCPUSerial() throws Exception; + + /** + * <p>鑾峰彇涓绘澘搴忓垪鍙�</p> + * + * @return String 涓绘澘搴忓垪鍙� + * @throws Exception 榛樿寮傚父 + */ + protected abstract String getMainBoardSerial() throws Exception; + + /** + * <p>鑾峰彇褰撳墠鏈嶅姟鍣ㄦ墍鏈夌鍚堟潯浠剁殑缃戠粶鍦板潃</p> + * + * @return List<InetAddress> 缃戠粶鍦板潃鍒楄〃 + * @throws Exception 榛樿寮傚父 + */ + private List<InetAddress> getLocalAllInetAddress() throws Exception { + List<InetAddress> result = new ArrayList<>(4); + // 閬嶅巻鎵�鏈夌殑缃戠粶鎺ュ彛 + for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) { + NetworkInterface ni = (NetworkInterface) networkInterfaces.nextElement(); + // 鍦ㄦ墍鏈夌殑鎺ュ彛涓嬪啀閬嶅巻IP + for (Enumeration addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) { + InetAddress address = (InetAddress) addresses.nextElement(); + // 鎺掗櫎LoopbackAddress銆丼iteLocalAddress銆丩inkLocalAddress銆丮ulticastAddress绫诲瀷鐨処P鍦板潃 + if (!address.isLoopbackAddress() + && !address.isLinkLocalAddress() && !address.isMulticastAddress()) { + result.add(address); + } + } + } + return result; + } + + /** + * <p>鑾峰彇鏌愪釜缃戠粶鍦板潃瀵瑰簲鐨凪ac鍦板潃</p> + * + * @param inetAddr 缃戠粶鍦板潃 + * @return String Mac鍦板潃 + */ + private String getMacByInetAddress(InetAddress inetAddr) { + try { + byte[] mac = NetworkInterface.getByInetAddress(inetAddr).getHardwareAddress(); + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < mac.length; i++) { + if (i != 0) { + stringBuilder.append("-"); + } + /** 灏嗗崄鍏繘鍒禸yte杞寲涓哄瓧绗︿覆 */ + String temp = Integer.toHexString(mac[i] & 0xff); + if (temp.length() == 1) { + stringBuilder.append("0").append(temp); + } else { + stringBuilder.append(temp); + } + } + return stringBuilder.toString().toUpperCase(); + } catch (SocketException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java new file mode 100644 index 0000000..38d29b0 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java @@ -0,0 +1,231 @@ +package com.se.system.utils; + +import java.util.*; + +@SuppressWarnings("ALL") +public class CommonUtils { + public CommonUtils(String str) { + // + } + + public CommonUtils() { + } + + public static String validStringValue(Object object) { + return object == null ? "" : object.toString(); + } + + public static int validIntValue(Object object) { + return object == null ? 0 : Integer.valueOf(object.toString()); + } + + public static long validLongValue(Object object) { + return object == null ? 0L : Long.valueOf(object.toString()); + } + + public static boolean isNotEmpty(Object object) { + if (object == null) { + return false; + } else if (object instanceof Integer) { + return Integer.valueOf(object.toString()) > 0; + } else if (object instanceof Long) { + return Long.valueOf(object.toString()) > 0L; + } else if (object instanceof String) { + return ((String) object).trim().length() > 0; + } else if (object instanceof StringBuffer) { + return ((StringBuffer) object).toString().trim().length() > 0; + } else if (object instanceof Boolean) { + return Boolean.valueOf(object.toString()); + } else if (object instanceof List) { + return ((List) object).size() > 0; + } else if (object instanceof Set) { + return ((Set) object).size() > 0; + } else if (object instanceof Map) { + return ((Map) object).size() > 0; + } else if (object instanceof Iterator) { + return ((Iterator) object).hasNext(); + } else if (object.getClass().isArray()) { + return Arrays.asList(object).size() > 0; + } else { + return true; + } + } + + public static boolean isEmpty(Object object) { + if (object == null) { + return true; + } else if (object instanceof Integer) { + return Integer.valueOf(object.toString()) == 0; + } else if (object instanceof Long) { + return Long.valueOf(object.toString()) == 0L; + } else if (object instanceof String) { + return ((String) object).trim().length() == 0; + } else if (object instanceof StringBuffer) { + return ((StringBuffer) object).toString().trim().length() == 0; + } else if (object instanceof Boolean) { + return Boolean.valueOf(object.toString()); + } else if (object instanceof List) { + return ((List) object).size() == 0; + } else if (object instanceof Set) { + return ((Set) object).size() == 0; + } else if (object instanceof Map) { + return ((Map) object).size() == 0; + } else if (object instanceof Iterator) { + return !((Iterator) object).hasNext(); + } else if (object.getClass().isArray()) { + return Arrays.asList(object).size() == 0; + } else { + return false; + } + } + + public static List<Long> set2List(Set<Long> sets) { + List<Long> list = new ArrayList(); + if (sets != null && sets.size() > 0) { + Iterator var2 = sets.iterator(); + + while (var2.hasNext()) { + Object o = var2.next(); + Long id = Long.valueOf(o.toString()); + list.add(id); + } + + return list; + } else { + return null; + } + } + + public static List<String> set2ListStr(Set<?> set) { + ArrayList result = new ArrayList(); + + try { + if (set.size() > 0) { + set.forEach((s) -> { + result.add(s.toString()); + }); + } + } catch (Exception var3) { + System.err.println("HashSet杞崲澶辫触"); + } + + return result; + } + + public static Set<Long> list2Set(List<String> list) { + HashSet result = new HashSet(); + + try { + if (list.size() > 0) { + list.forEach((s) -> { + result.add(Long.parseLong(s)); + }); + } + } catch (Exception var3) { + System.err.println("List杞崲澶辫触"); + } + + return result; + } + + public static Set<Long> hashSetToSet(HashSet<?> sets) { + Set<Long> result = new HashSet(); + if (sets != null && sets.size() > 0) { + Iterator var2 = sets.iterator(); + + while (var2.hasNext()) { + Object o = var2.next(); + Long id = Long.valueOf(o.toString()); + result.add(id); + } + + return result; + } else { + return null; + } + } + + public static List<String> setToList(Set<?> set) { + ArrayList result = new ArrayList(); + try { + if (set.size() > 0) { + set.forEach((s) -> { + result.add(s.toString()); + }); + } + } catch (Exception var3) { + System.err.println("HashSet杞崲澶辫触"); + } + return result; + } + + public static List<String> listToList(List<?> list) { + ArrayList result = new ArrayList(); + try { + if (list.size() > 0) { + list.forEach((s) -> { + result.add(s.toString()); + }); + } + } catch (Exception var3) { + System.err.println("List杞崲澶辫触"); + } + return result; + } + + public static String listToString(List<String> list) { + if (list == null) { + return null; + } else { + String result = ""; + + try { + if (list.size() <= 0) { + return result; + } + + String s; + for (Iterator var2 = list.iterator(); var2.hasNext(); result = result + s + ";") { + s = (String) var2.next(); + } + + result = result.substring(0, result.length() - 1); + } catch (Exception var4) { + System.err.println("List杞崲澶辫触"); + } + + return result; + } + } + + public static List<String> StringTolist(String str) { + if (str != null && str.length() != 0) { + ArrayList list = new ArrayList(); + + try { + String[] strs = str.substring(1, str.length() - 1).replaceAll("\"", "").split(","); + String[] var3 = strs; + int var4 = strs.length; + + for (int var5 = 0; var5 < var4; ++var5) { + String result = var3[var5]; + list.add(result); + } + } catch (Exception var7) { + System.err.println("List杞崲澶辫触"); + } + + return list; + } else { + return null; + } + } + + public static void test(String[] args) { + Integer a = null; + System.out.println(isNotEmpty(a)); + String str = "[\"11\",\"222\"]"; + List<String> list = StringTolist(str); + System.out.println(); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/DateUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/DateUtils.java new file mode 100644 index 0000000..2f3f42c --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/utils/DateUtils.java @@ -0,0 +1,113 @@ +package com.se.system.utils; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Calendar; +import java.util.Date; + +@SuppressWarnings("ALL") +public class DateUtils { + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH_mm_ss"); + + private static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + private static Calendar calendar = Calendar.getInstance(); + + public DateUtils() { + } + + public static synchronized String getCurrentDateForFile() { + long currentTimeMillis = System.currentTimeMillis(); + Date date = new Date(currentTimeMillis); + return sdf.format(date); + } + + public static Long getTime(String time) { + if (CommonUtils.isEmpty(time)) { + System.out.println("鏃堕棿[" + time + "]鏍煎紡涓嶅悎娉�"); + return null; + } else if (time.length() < 11) { + dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate parse = LocalDate.parse(time, dtf); + return LocalDate.from(parse).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } else { + LocalDateTime parse = LocalDateTime.parse(time, dtf); + return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + } + + public static synchronized String getDate() { + Date date = new Date(); + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(date); + } + + public static synchronized String date2Str(Long time) { + Date date = new Date(time); + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(date); + } + + public static synchronized String date2Str(Date time) { + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(time); + } + + public static synchronized Date str2Date(String time) { + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + try { + return sdf.parse(time); + } catch (Exception var2) { + System.out.println("瀛楃涓瞇" + time + "]杞崲鏃ユ湡鏍煎紡寮傚父"); + return null; + } + } + + public static Date addYear(Date date, int mount) { + calendar.setTime(date); + calendar.add(1, mount); + return calendar.getTime(); + } + + public static Date addYear(Long time, int mount) { + Date date = new Date(time); + calendar.setTime(date); + calendar.add(1, mount); + return calendar.getTime(); + } + + public static Date addMonth(Date date, int mount) { + calendar.setTime(date); + calendar.add(2, mount); + return calendar.getTime(); + } + + public static Date addMonth(Long time, int mount) { + Date date = new Date(time); + calendar.setTime(date); + calendar.add(1, mount); + return calendar.getTime(); + } + + public static Date addDay(Date date, int mount) { + calendar.setTime(date); + calendar.add(5, mount); + return calendar.getTime(); + } + + public static Date addDay(Long time, int mount) { + Date date = new Date(time); + calendar.setTime(date); + calendar.add(5, mount); + return calendar.getTime(); + } + + public static void main(String[] args) { + Long time = 1555588742901L; + date2Str(time); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java index 6b80fd0..92bb592 100644 --- a/se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java +++ b/se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java @@ -1,42 +1,74 @@ package com.se.system.utils; -import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; - import java.io.IOException; -import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @SuppressWarnings("ALL") public class JsonUtils { - @SuppressWarnings("unchecked") - public static LinkedHashMap<String, Object> json2Map(String json) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - return mapper.readValue(json, LinkedHashMap.class); + public static final ObjectMapper OM = new ObjectMapper(); + + static { + OM.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + OM.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); + OM.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + OM.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + OM.configure(JsonParser.Feature.ALLOW_COMMENTS, true); } - public static String map2Json(Object obj) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - return mapper.writeValueAsString(obj); + public JsonUtils() { } - @SuppressWarnings("unchecked") - public static List<LinkedHashMap<String, Object>> json2ListMap(String json) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - return mapper.readValue(json, List.class); + public static String objectToJson(Object data) { + try { + return OM.writeValueAsString(data); + } catch (JsonProcessingException var2) { + var2.printStackTrace(); + return null; + } } - public static <T> T json2Object(String json, Class<T> valueType) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true).configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - return mapper.readValue(json, valueType); + public static String objectToJsonWithType(Object data, TypeReference typeReference) { + try { + return OM.writerFor(typeReference).writeValueAsString(data); + } catch (JsonProcessingException var3) { + var3.printStackTrace(); + return null; + } } - public static <T> T obj2Vo(Object obj, Class<T> valueType) { - return JSONObject.parseObject(JSONObject.toJSONString(obj), valueType); + public static <T> T jsonToPojo(String jsonData, Class<T> beanType) { + try { + return OM.readValue(jsonData, beanType); + } catch (Exception var3) { + var3.printStackTrace(); + return null; + } + } + + public static <T> List<T> jsonToList(String jsonData, Class<T> beanType) { + JavaType javaType = OM.getTypeFactory().constructParametricType(List.class, new Class[]{beanType}); + + try { + return (List) OM.readValue(jsonData, javaType); + } catch (Exception var4) { + var4.printStackTrace(); + return null; + } + } + + public static Map<String, Object> parseMap(String jsonStr) throws IOException { + return (Map) OM.readValue(jsonStr, Map.class); + } + + public static List<String> parseList(String jsonStr) throws IOException { + return (List) OM.readValue(jsonStr, new TypeReference<List<String>>() { + }); } } diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/ParamInitUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/ParamInitUtils.java new file mode 100644 index 0000000..cea8763 --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/utils/ParamInitUtils.java @@ -0,0 +1,84 @@ +package com.se.system.utils; + +import com.se.system.domain.vo.*; +import de.schlichtherle.license.*; + +import javax.security.auth.x500.X500Principal; +import java.util.prefs.Preferences; + +@SuppressWarnings("ALL") +public class ParamInitUtils { + public ParamInitUtils() { + } + + /** + * 璇佷功鐨勫彂琛岃�呭拰涓讳綋瀛楁淇℃伅 + */ + private final static X500Principal DEFAULT_HOLDER_AND_ISSUER = new X500Principal("CN=a, OU=a, O=a, L=a, ST=a, C=a"); + + /** + * <p>鍒濆鍖栬瘉涔︾敓鎴愬弬鏁�</p> + * + * @param param GxLicenseCreatorParam 鐢熸垚璇佷功鍙傛暟 + * @return LicenseParam 璇佷功鍙傛暟 + */ + public static LicenseParam initLicenseParam(LicenseCreatorParamVo param) { + Preferences preferences = Preferences.userNodeForPackage(LicenseCreator.class); + /** 璁剧疆瀵硅瘉涔﹀唴瀹瑰姞瀵嗙殑绉橀挜 */ + CipherParam cipherParam = new DefaultCipherParam(param.getStorePass()); + KeyStoreParam privateStoreParam = new DefaultKeyStoreParam(LicenseCreator.class + , param.getPrivateKeysStorePath() + , param.getPrivateAlias() + , param.getStorePass() + , param.getKeyPass()); + return new DefaultLicenseParam(param.getSubject(), preferences, privateStoreParam, cipherParam); + } + + /** + * <p>鍒濆鍖栬瘉涔﹀唴瀹逛俊鎭璞�</p> + * + * @param param GxLicenseCreatorParam 鐢熸垚璇佷功鍙傛暟 + * @return LicenseContent 璇佷功鍐呭 + */ + public static LicenseContent initLicenseContent(LicenseCreatorParamVo param) { + 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()); + /** 璁剧疆璇佷功鎵╁睍淇℃伅锛堝璞� -- 棰濆鐨刬p銆乵ac銆乧pu绛変俊鎭級 */ + licenseContent.setExtra(param.getLicenseCheck()); + return licenseContent; + } + + /** + * <p>鍒濆鍖栬瘉涔︾敓鎴愬弬鏁�</p> + * + * @param param License鏍¢獙绫婚渶瑕佺殑鍙傛暟 + */ + public static LicenseParam initLicenseParam(LicenseVerifyParamVo param) { + Preferences preferences = Preferences.userNodeForPackage(LicenseVerifyMg.class); + CipherParam cipherParam = new DefaultCipherParam(param.getStorePass()); + KeyStoreParam publicStoreParam = new DefaultKeyStoreParam(LicenseVerifyMg.class + /** 鍏挜搴撳瓨鍌ㄨ矾寰� */ + , param.getPublicKeysStorePath() + /** 鍏寵鍒悕 */ + , param.getPublicAlias() + /** 鍏挜搴撹闂瘑鐮� */ + , param.getStorePass() + , null); + return new DefaultLicenseParam(param.getSubject(), preferences, publicStoreParam, cipherParam); + } +} diff --git a/se-modules/se-system/src/main/java/com/se/system/utils/ServerSerialUtils.java b/se-modules/se-system/src/main/java/com/se/system/utils/ServerSerialUtils.java new file mode 100644 index 0000000..b1bd59d --- /dev/null +++ b/se-modules/se-system/src/main/java/com/se/system/utils/ServerSerialUtils.java @@ -0,0 +1,55 @@ +package com.se.system.utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Scanner; + +@SuppressWarnings("ALL") +public class ServerSerialUtils { + public ServerSerialUtils() { + } + + /** + * 鎵цLinux鐨剆hell鑾峰彇Linux淇℃伅 + * + * @param shell 鍛戒护 + * @return String Server淇℃伅 + * @throws Exception 榛樿寮傚父 + */ + public static String getLinuxSerial(String[] shell) throws Exception { + String serial = ""; + /** 浣跨敤dmidecode鍛戒护鑾峰彇鍒楀彿 */ + Process process = Runtime.getRuntime().exec(shell); + process.getOutputStream().close(); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line = reader.readLine().trim(); + if (CommonUtils.isNotEmpty(line)) { + serial = line; + } + reader.close(); + return serial; + } + + /** + * 鎵цwindows鐨刢ommand鑾峰彇Windows淇℃伅 + * + * @param command 鍛戒护 + * @return String Server淇℃伅 + * @throws Exception 榛樿寮傚父 + */ + public static String getWindowsSerial(String command) throws Exception { + String serial = ""; + /** 浣跨敤WMIC鑾峰彇搴忓垪鍙� */ + Process process = Runtime.getRuntime().exec(command); + process.getOutputStream().close(); + Scanner scanner = new Scanner(process.getInputStream()); + if (scanner.hasNext()) { + scanner.next(); + } + if (scanner.hasNext()) { + serial = scanner.next().trim(); + } + scanner.close(); + return serial; + } +} diff --git a/se-modules/se-system/src/main/resources/certfile.cer b/se-modules/se-system/src/main/resources/certfile.cer new file mode 100644 index 0000000..386a2e3 --- /dev/null +++ b/se-modules/se-system/src/main/resources/certfile.cer Binary files differ diff --git a/se-modules/se-system/src/main/resources/privateKeys.store b/se-modules/se-system/src/main/resources/privateKeys.store new file mode 100644 index 0000000..a5f96ba --- /dev/null +++ b/se-modules/se-system/src/main/resources/privateKeys.store Binary files differ diff --git a/se-modules/se-system/src/main/resources/publicCerts.store b/se-modules/se-system/src/main/resources/publicCerts.store new file mode 100644 index 0000000..a3b1535 --- /dev/null +++ b/se-modules/se-system/src/main/resources/publicCerts.store Binary files differ diff --git "a/\350\257\264\346\230\216.txt" "b/\350\257\264\346\230\216.txt" index 3dfcc55..039e65e 100644 --- "a/\350\257\264\346\230\216.txt" +++ "b/\350\257\264\346\230\216.txt" @@ -142,4 +142,13 @@ https://gitee.com/a1374469523/license http://localhost:8080/docker/test + +# 鐢熸垚涓�涓柊瀵嗛挜瀵� +keytool -genkey -alias privatekeys -keyalg DSA -keysize 1024 -keystore privateKeys.store -validity 3650 +Se_System_20!24锛孋N=wu, OU=se, O=se, L=bj, ST=bj, C=cn + +# 瀵煎嚭鎸囧畾鍒悕鐨勮瘉涔︽垨鍏挜 +keytool -export -alias privatekeys -file c:\certfile.cer -keystore privateKeys.store +# 瀵煎叆涓�涓瘉涔︽垨鍏挜 +keytool -import -alias publiccert -file c:\certfile.cer -keystore publicCerts.store -------------------------------------------------------- -- Gitblit v1.9.3