13693261870
2024-12-30 edc9a6674eb9b40e33a74c5f022d279712ed3b7c
添加许可工具
已添加18个文件
已修改14个文件
1985 ■■■■■ 文件已修改
se-api/se-api-system/se-api-system.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-core/pom.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-core/se-common-core.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-datascope/se-common-datascope.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-log/se-common-log.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-redis/se-common-redis.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-security/se-common-security.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-common/se-common-sensitive/se-common-sensitive.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-gateway/se-gateway.iml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/pom.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/controller/SysSoftController.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorMg.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCreatorParamVo.java 216 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseCustomMg.java 247 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseExtraParamVo.java 182 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseResultVo.java 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyMg.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/domain/vo/LicenseVerifyParamVo.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/service/NacosService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/service/impl/LinuxServerInfoService.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/service/impl/WindowsServerInfoService.java 74 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/service/inte/IACustomVerifyListener.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/service/inte/IAServerInfoService.java 214 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/utils/CommonUtils.java 231 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/utils/DateUtils.java 113 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/utils/JsonUtils.java 78 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/utils/ParamInitUtils.java 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/java/com/se/system/utils/ServerSerialUtils.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/resources/certfile.cer 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/resources/privateKeys.store 补丁 | 查看 | 原始文档 | blame | 历史
se-modules/se-system/src/main/resources/publicCerts.store 补丁 | 查看 | 原始文档 | blame | 历史
说明.txt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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" />
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>
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>
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" />
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" />
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" />
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" />
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" />
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" />
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>
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);
    }
}
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内容(除了truelicense自带的还包括自己定义的)
            LicenseContent licenseContent = ParamInitUtils.initLicenseContent(param);
            // 3、构建Lic管理器
            LicenseManager licenseManager = new LicenseCustomMg(licenseParam);
            // 4、根据param传入的lic生成的路径创建空文件
            File licenseFile = new File(this.param.getLicensePath());
            // 5、通过Lic管理器,将内容写入Lic文件中
            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);
        }
    }
}
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;
    /**
     * è¯ä¹¦ä¸‹è½½åœ°å€ == ä¸€æ—¦è¯ä¹¦create成功,这个值就会填充上
     */
    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));
    }
}
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的create方法</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校验方法,校验ip、mac、cpu序列号等 */
        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校验方法,校验ip、mac、cpu序列号等 */
        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方法,增加ip地址、mac地址、cpu序列号等其他信息的校验</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、 é¦–先调用父类的validate方法
        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 = "系统证书无效,当前服务器的IP没在授权范围内";
                System.out.println("message = " + message);
                throw new LicenseContentException(message);
            }
            // æ ¡éªŒMac地址
            if (expectedCheck.isMacCheck() && !checkIpAddress(expectedCheck.getMacAddress(), serverCheckModel.getMacAddress())) {
                String message = "系统证书无效,当前服务器的Mac地址没在授权范围内";
                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 = "系统证书无效,当前服务器的CPU序列号没在授权范围内";
                System.out.println("message = " + message);
                throw new LicenseContentException(message);
            }
        } else {
            System.out.println("不能获取服务器硬件信息");
            throw new LicenseContentException("不能获取服务器硬件信息");
        }
    }
    /**
     * <p>重写XMLDecoder解析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解析XML失败 ");
                e.printStackTrace();
            }
        }
        return null;
    }
    /**
     * æ ¡éªŒå½“前服务器的IP/Mac地址是否在可被允许的IP范围内<br/>
     * å¦‚果存在IP在可被允许的IP/Mac地址范围内,则返回true
     */
    private boolean checkIpAddress(List<String> expectedList, List<String> serverList) {
        /** å¦‚果期望的IP列表空直接返回false,因为既然验证ip,这一项必须要有元素 */
        if (CommonUtils.isEmpty(expectedList)) {
            return false;
        }
        /** å¦‚果当前服务器的IP列表空直接返回false,因为服务器不可能获取不到ip,没有的话验证个锤子 */
        if (CommonUtils.isEmpty(serverList)) {
            return false;
        }
        for (String expected : expectedList) {
            if (serverList.contains(expected.trim())) {
                return true;
            }
        }
        return false;
    }
    /**
     * <p>校验当前服务器硬件(主板、CPU等)序列号是否在可允许范围内</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;
        }
    }
}
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;
    /**
     * å¯è¢«å…è®¸çš„IP地址
     */
    private List<String> ipAddress;
    /**
     * æ˜¯å¦è®¤è¯mac
     */
    private boolean isMacCheck;
    /**
     * å¯è¢«å…è®¸çš„mac地址
     */
    private List<String> macAddress;
    /**
     * æ˜¯å¦è®¤è¯cpu序列号
     */
    private boolean isCpuCheck;
    /**
     * å¯è¢«å…è®¸çš„CPU序列号
     */
    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();
    }
}
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() {
    }
    /**
     * éªŒè¯ç»“果,true为验证通过,false则为失败
     */
    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;
    }
}
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、创建License证书管理器对象 */
//          LicenseManager licenseManager =new LicenseManager(licenseParam);
            // èµ°è‡ªå®šä¹‰çš„Lic管理
            LicenseCustomMg licenseManager = new LicenseCustomMg(licenseParam);
            /** 3、获取要安装的证书文件 */
            File licenseFile = new File(param.getLicensePath());
            /** 4、如果之前安装过证书,先卸载之前的证书 == ç»™null */
            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、创建License证书管理器对象 */
        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:")) {
                /**检测下当前应用的classes路径下有没有lic文件*/
                // ResourceUtils.getFile(licensePath);
            } else {
                /**直接构建file对象检测lic文件是否存在*/
                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);
        }
    }
}
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 + '\'' +
                '}';
    }
}
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
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;
    }
}
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();
    }
}
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);
}
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、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
                if (!address.isLoopbackAddress()
                        && !address.isLinkLocalAddress() && !address.isMulticastAddress()) {
                    result.add(address);
                }
            }
        }
        return result;
    }
    /**
     * <p>获取某个网络地址对应的Mac地址</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("-");
                }
                /** å°†åå…­è¿›åˆ¶byte转化为字符串 */
                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;
    }
}
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();
    }
}
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);
    }
}
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>>() {
        });
    }
}
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());
        /** è®¾ç½®è¯ä¹¦æ‰©å±•信息(对象 -- é¢å¤–çš„ip、mac、cpu等信息) */
        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);
    }
}
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的shell获取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的command获取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;
    }
}
se-modules/se-system/src/main/resources/certfile.cer
Binary files differ
se-modules/se-system/src/main/resources/privateKeys.store
Binary files differ
se-modules/se-system/src/main/resources/publicCerts.store
Binary files differ
˵Ã÷.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,CN=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
--------------------------------------------------------