Kaynağa Gözat

删除true license

hanqingsong 2 yıl önce
ebeveyn
işleme
f03b7a62c9

+ 0 - 8
pom.xml

@@ -22,7 +22,6 @@
22 22
         <swagger.version>2.9.2</swagger.version>
23 23
         <swagger-boot.version>1.9.0.RELEASE</swagger-boot.version>
24 24
         <fastjson2.version>2.0.21</fastjson2.version>
25
-        <trueLicense.version>1.33</trueLicense.version>
26 25
     </properties>
27 26
     <dependencies>
28 27
         <dependency>
@@ -94,13 +93,6 @@
94 93
             <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
95 94
             <version>3.5.5</version>
96 95
         </dependency>
97
-        <!-- license -->
98
-        <dependency>
99
-            <groupId>de.schlichtherle.truelicense</groupId>
100
-            <artifactId>truelicense-core</artifactId>
101
-            <version>${trueLicense.version}</version>
102
-            <scope>provided</scope>
103
-        </dependency>
104 96
         <dependency>
105 97
             <groupId>org.springframework.boot</groupId>
106 98
             <artifactId>spring-boot-starter-web</artifactId>

+ 0 - 23
src/main/java/com/unissoft/config/WebMvcConfig.java

@@ -1,23 +0,0 @@
1
-package com.unissoft.config;
2
-
3
-import com.unissoft.license.LicenseCheckInterceptor;
4
-import org.springframework.context.annotation.Configuration;
5
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
6
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7
-
8
-/**
9
- * @author qingsong.han
10
- * @description: 注册拦截器
11
- * @create 2023-03-11 11:20
12
- */
13
-@Configuration
14
-public class WebMvcConfig implements WebMvcConfigurer {
15
-    /**
16
-     * 添加拦截器
17
-     */
18
-    @Override
19
-    public void addInterceptors(InterceptorRegistry registry) {
20
-        registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/user-info/login", "/user-info/identifyImage");
21
-    }
22
-
23
-}

+ 0 - 59
src/main/java/com/unissoft/license/CustomKeyStoreParam.java

@@ -1,59 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import de.schlichtherle.license.AbstractKeyStoreParam;
4
-import org.springframework.util.StringUtils;
5
-
6
-import java.io.*;
7
-
8
-/**
9
- * @author qingsong.han
10
- * @description: 自定义KeyStoreParam,用于将公私钥存储文件存放到其他磁盘位置而不是项目中
11
- * @create 2023-03-11 10:43
12
- */
13
-public class CustomKeyStoreParam extends AbstractKeyStoreParam {
14
-    /**
15
-     * 公钥/私钥在磁盘上的存储路径
16
-     */
17
-    private String storePath;
18
-    private String alias;
19
-    private String storePwd;
20
-    private String keyPwd;
21
-
22
-    CustomKeyStoreParam(Class clazz, String resource, String alias, String storePwd, String keyPwd) {
23
-        super(clazz, resource);
24
-        this.storePath = resource;
25
-        this.alias = alias;
26
-        this.storePwd = storePwd;
27
-        this.keyPwd = keyPwd;
28
-    }
29
-
30
-
31
-    @Override
32
-    public String getAlias() {
33
-        return alias;
34
-    }
35
-
36
-    @Override
37
-    public String getStorePwd() {
38
-        return storePwd;
39
-    }
40
-
41
-    @Override
42
-    public String getKeyPwd() {
43
-        return keyPwd;
44
-    }
45
-
46
-    /**
47
-     * @title getStream
48
-     * @description 复写de.schlichtherle.license.AbstractKeyStoreParam的getStream()方法
49
-     * 用于将公私钥存储文件存放到其他磁盘位置而不是项目中
50
-     * @author Administrator
51
-     */
52
-    @Override
53
-    public final InputStream getStream() throws IOException {
54
-        if (StringUtils.isEmpty(storePath))
55
-            throw new FileNotFoundException(storePath);
56
-        return new FileInputStream(new File(storePath));
57
-    }
58
-
59
-}

+ 0 - 141
src/main/java/com/unissoft/license/CustomLicenseManager.java

@@ -1,141 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import de.schlichtherle.license.*;
4
-import de.schlichtherle.xml.GenericCertificate;
5
-import lombok.extern.slf4j.Slf4j;
6
-
7
-import java.beans.XMLDecoder;
8
-import java.io.BufferedInputStream;
9
-import java.io.ByteArrayInputStream;
10
-import java.io.UnsupportedEncodingException;
11
-import java.util.Date;
12
-
13
-/**
14
- * @author qingsong.han
15
- * @description: 自定义LicenseManager,用于增加额外的服务器硬件信息校验
16
- * @create 2023-03-11 10:46
17
- */
18
-@Slf4j
19
-public class CustomLicenseManager extends LicenseManager {
20
-    //XML编码
21
-    private static final String XML_CHARSET = "UTF-8";
22
-    //默认BUFSIZE
23
-    private static final int DEFAULT_BUFSIZE = 8 * 1024;
24
-
25
-    CustomLicenseManager(LicenseParam param) {
26
-        super(param);
27
-    }
28
-
29
-    /**
30
-     * @title create
31
-     * @description 复写create方法
32
-     * @author Administrator
33
-     */
34
-    @Override
35
-    protected synchronized byte[] create(LicenseContent content, LicenseNotary notary) throws Exception {
36
-        initialize(content);
37
-        this.validateCreate(content);
38
-        final GenericCertificate certificate = notary.sign(content);
39
-        return getPrivacyGuard().cert2key(certificate);
40
-    }
41
-
42
-    /**
43
-     * @title install
44
-     * @description 复写install方法,其中validate方法调用本类中的validate方法,校验IP地址、Mac地址等其他信息
45
-     * @author Administrator
46
-     */
47
-    @Override
48
-    protected synchronized LicenseContent install(final byte[] key, final LicenseNotary notary) throws Exception {
49
-        final GenericCertificate certificate = getPrivacyGuard().key2cert(key);
50
-        // 证书xml
51
-//        log.info("certificate.getEncoded(): {}", certificate.getEncoded());
52
-        notary.verify(certificate);
53
-        final LicenseContent content = (LicenseContent) this.load(certificate.getEncoded());
54
-        this.validate(content);
55
-        setLicenseKey(key);
56
-        setCertificate(certificate);
57
-        return content;
58
-    }
59
-
60
-    /**
61
-     * @title verify
62
-     * @description 复写verify方法,调用本类中的validate方法,校验IP地址、Mac地址等其他信息
63
-     * @author Administrator
64
-     */
65
-    @Override
66
-    protected synchronized LicenseContent verify(final LicenseNotary notary) throws Exception {
67
-        // Load license key from preferences,
68
-        final byte[] key = getLicenseKey();
69
-        if (null == key) {
70
-            throw new NoLicenseInstalledException(getLicenseParam().getSubject());
71
-        }
72
-        GenericCertificate certificate = getPrivacyGuard().key2cert(key);
73
-        notary.verify(certificate);
74
-        final LicenseContent content = (LicenseContent) this.load(certificate.getEncoded());
75
-        this.validate(content);
76
-        setCertificate(certificate);
77
-        return content;
78
-    }
79
-
80
-    /**
81
-     * @title validateCreate
82
-     * @description 校验生成证书的参数信息
83
-     * @author Administrator
84
-     */
85
-    private synchronized void validateCreate(final LicenseContent content) throws LicenseContentException {
86
-        final Date now = new Date();
87
-        final Date notBefore = content.getNotBefore();
88
-        final Date notAfter = content.getNotAfter();
89
-        if (null != notAfter && now.after(notAfter)) {
90
-            throw new LicenseContentException("证书失效时间不能早于当前时间");
91
-        }
92
-        if (null != notBefore && null != notAfter && notAfter.before(notBefore)) {
93
-            throw new LicenseContentException("证书生效时间不能晚于证书失效时间");
94
-        }
95
-        final String consumerType = content.getConsumerType();
96
-        if (null == consumerType) {
97
-            throw new LicenseContentException("用户类型不能为空");
98
-        }
99
-    }
100
-
101
-    /**
102
-     * @title validate
103
-     * @description 复写validate方法,增加IP地址、Mac地址等其他信息校验
104
-     * @author Administrator
105
-     */
106
-    @Override
107
-    protected synchronized void validate(final LicenseContent content) throws LicenseContentException {
108
-        //1. 首先调用父类的validate方法
109
-        super.validate(content);
110
-    }
111
-
112
-    /**
113
-     * @title load
114
-     * @description 重写XMLDecoder解析XML
115
-     * @author Administrator
116
-     */
117
-    private Object load(String encoded) {
118
-        BufferedInputStream inputStream = null;
119
-        XMLDecoder decoder = null;
120
-        try {
121
-            inputStream = new BufferedInputStream(new ByteArrayInputStream(encoded.getBytes(XML_CHARSET)));
122
-            decoder = new XMLDecoder(new BufferedInputStream(inputStream, DEFAULT_BUFSIZE), null, null);
123
-            return decoder.readObject();
124
-        } catch (UnsupportedEncodingException e) {
125
-            e.printStackTrace();
126
-        } finally {
127
-            try {
128
-                if (decoder != null) {
129
-                    decoder.close();
130
-                }
131
-                if (inputStream != null) {
132
-                    inputStream.close();
133
-                }
134
-            } catch (Exception e) {
135
-                log.error("XMLDecoder解析XML失败: {}", e);
136
-            }
137
-        }
138
-        return null;
139
-    }
140
-
141
-}

+ 0 - 36
src/main/java/com/unissoft/license/LicenseCheckInterceptor.java

@@ -1,36 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import com.alibaba.fastjson2.JSON;
4
-import lombok.extern.slf4j.Slf4j;
5
-import org.springframework.web.servlet.HandlerInterceptor;
6
-
7
-import javax.servlet.http.HttpServletRequest;
8
-import javax.servlet.http.HttpServletResponse;
9
-import java.util.HashMap;
10
-import java.util.Map;
11
-
12
-/**
13
- * @author qingsong.han
14
- * @description: LicenseCheckInterceptor 校验证书
15
- * @create 2023-03-11 10:49
16
- */
17
-@Slf4j
18
-public class LicenseCheckInterceptor implements HandlerInterceptor {
19
-
20
-    @Override
21
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
22
-        LicenseVerify licenseVerify = new LicenseVerify();
23
-        //校验证书是否有效
24
-        boolean verifyResult = licenseVerify.verify();
25
-        if (verifyResult) {
26
-            return true;
27
-        } else {
28
-            response.setCharacterEncoding("utf-8");
29
-            Map<String, String> result = new HashMap<>(1);
30
-            result.put("result", "您的证书无效,请核查服务器是否取得授权或重新申请证书!");
31
-            response.getWriter().write(JSON.toJSONString(result));
32
-            return false;
33
-        }
34
-    }
35
-
36
-}

+ 0 - 85
src/main/java/com/unissoft/license/LicenseCheckListener.java

@@ -1,85 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import de.schlichtherle.license.LicenseContent;
4
-import lombok.extern.slf4j.Slf4j;
5
-import org.springframework.beans.factory.annotation.Value;
6
-import org.springframework.context.ApplicationListener;
7
-import org.springframework.context.event.ContextRefreshedEvent;
8
-import org.springframework.stereotype.Component;
9
-
10
-/**
11
- * @author qingsong.han
12
- * @description:
13
- * @create 2023-03-11 10:54
14
- */
15
-@Slf4j
16
-@Component
17
-@SuppressWarnings("all")
18
-public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> {
19
-    /**
20
-     * 证书subject
21
-     */
22
-    @Value("${license.subject}")
23
-    private String subject;
24
-
25
-    /**
26
-     * 公钥别称
27
-     */
28
-    @Value("${license.publicAlias}")
29
-    private String publicAlias;
30
-
31
-    /**
32
-     * 访问公钥库的密码
33
-     */
34
-    @Value("${license.storePass}")
35
-    private String storePass;
36
-
37
-    /**
38
-     * 证书生成路径
39
-     */
40
-    /*@Value("${license.licensePath}")
41
-    private String licensePath;*/
42
-
43
-    /**
44
-     * 密钥库存储路径
45
-     */
46
-    /*@Value("${license.publicKeysStorePath}")
47
-    private String publicKeysStorePath;*/
48
-    @Override
49
-    public void onApplicationEvent(ContextRefreshedEvent event) {
50
-        // 证书生成路径
51
-        String licensePath;
52
-        // 密钥库存储路径
53
-        String publicKeysStorePath;
54
-        // 获取项目运行路径
55
-        String path = System.getProperty("user.dir");
56
-        // 判断windows和linux
57
-        if (path.contains("/")) {
58
-            // linux
59
-            licensePath = path + "/license.lic";
60
-            publicKeysStorePath = path + "/publicCerts.keystore";
61
-            log.info("licensePath:{} publicKeysStorePath:{}", licensePath, publicKeysStorePath);
62
-        } else {
63
-            // windows
64
-            licensePath = path + "\\license.lic";
65
-            publicKeysStorePath = path + "\\publicCerts.keystore";
66
-            log.info("licensePath:{} publicKeysStorePath:{}", licensePath, publicKeysStorePath);
67
-        }
68
-
69
-        //root application context 没有parent
70
-        log.info("++++++++ 开始安装证书 ++++++++");
71
-
72
-        LicenseVerifyParam param = new LicenseVerifyParam();
73
-        param.setSubject(subject);
74
-        param.setPublicAlias(publicAlias);
75
-        param.setStorePass(storePass);
76
-        param.setLicensePath(licensePath);
77
-        param.setPublicKeysStorePath(publicKeysStorePath);
78
-        LicenseVerify licenseVerify = new LicenseVerify();
79
-        //安装证书
80
-        LicenseContent install = licenseVerify.install(param);
81
-
82
-        log.info("++++++++ 证书安装结束 ++++++++", install);
83
-    }
84
-
85
-}

+ 0 - 25
src/main/java/com/unissoft/license/LicenseManagerHolder.java

@@ -1,25 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import de.schlichtherle.license.LicenseManager;
4
-import de.schlichtherle.license.LicenseParam;
5
-
6
-/**
7
- * @author qingsong.han
8
- * @description: LicenseManager的单例
9
- * @create 2023-03-11 11:10
10
- */
11
-class LicenseManagerHolder {
12
-    private static volatile LicenseManager LICENSE_MANAGER;
13
-
14
-    static LicenseManager getInstance(LicenseParam param) {
15
-        if (LICENSE_MANAGER == null) {
16
-            synchronized (LicenseManagerHolder.class) {
17
-                if (LICENSE_MANAGER == null) {
18
-                    LICENSE_MANAGER = new CustomLicenseManager(param);
19
-                }
20
-            }
21
-        }
22
-        return LICENSE_MANAGER;
23
-    }
24
-
25
-}

+ 0 - 79
src/main/java/com/unissoft/license/LicenseVerify.java

@@ -1,79 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import de.schlichtherle.license.*;
4
-import lombok.extern.slf4j.Slf4j;
5
-
6
-import java.io.File;
7
-import java.text.DateFormat;
8
-import java.text.MessageFormat;
9
-import java.text.SimpleDateFormat;
10
-import java.util.prefs.Preferences;
11
-
12
-/**
13
- * @author qingsong.han
14
- * @description: License校验类
15
- * @create 2023-03-11 10:42
16
- */
17
-@Slf4j
18
-class LicenseVerify {
19
-    /**
20
-     * @title install
21
-     * @description 安装License证书
22
-     * @author Administrator
23
-     */
24
-    synchronized LicenseContent install(LicenseVerifyParam param) {
25
-        LicenseContent result = null;
26
-        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
27
-        //1. 安装证书
28
-        try {
29
-            LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param));
30
-            licenseManager.uninstall();
31
-            result = licenseManager.install(new File(param.getLicensePath()));
32
-            log.info(MessageFormat.format("证书安装成功,证书有效期:{0} - {1}", format.format(result.getNotBefore()), format.format(result.getNotAfter())));
33
-        } catch (Exception e) {
34
-            log.error("证书安装失败!", e);
35
-        }
36
-        return result;
37
-    }
38
-
39
-    /**
40
-     * @title verify
41
-     * @description 校验License证书
42
-     * @author Administrator
43
-     */
44
-    boolean verify() {
45
-        LicenseManager licenseManager = LicenseManagerHolder.getInstance(null);
46
-        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
47
-        //2. 校验证书
48
-        try {
49
-            LicenseContent licenseContent = licenseManager.verify();
50
-            log.info(MessageFormat.format("证书校验通过,证书有效期:{0} - {1}", format.format(licenseContent.getNotBefore()), format.format(licenseContent.getNotAfter())));
51
-            return true;
52
-        } catch (Exception e) {
53
-            log.error("证书校验失败!", e);
54
-            return false;
55
-        }
56
-    }
57
-
58
-    /**
59
-     * @title initLicenseParam
60
-     * @description 初始化证书生成参数
61
-     * @author Administrator
62
-     * @updateTime 2022/4/30 0030 18:29
63
-     */
64
-    private LicenseParam initLicenseParam(LicenseVerifyParam param) {
65
-        Preferences preferences = Preferences.userNodeForPackage(LicenseVerify.class);
66
-        CipherParam cipherParam = new DefaultCipherParam(param.getStorePass());
67
-        KeyStoreParam publicStoreParam = new CustomKeyStoreParam(LicenseVerify.class
68
-                , param.getPublicKeysStorePath()
69
-                , param.getPublicAlias()
70
-                , param.getStorePass()
71
-                , null);
72
-
73
-        return new DefaultLicenseParam(param.getSubject()
74
-                , preferences
75
-                , publicStoreParam
76
-                , cipherParam);
77
-    }
78
-
79
-}

+ 0 - 37
src/main/java/com/unissoft/license/LicenseVerifyParam.java

@@ -1,37 +0,0 @@
1
-package com.unissoft.license;
2
-
3
-import lombok.Data;
4
-
5
-/**
6
- * @author qingsong.han
7
- * @description: License校验类需要的参数
8
- * @create 2023-03-11 10:41
9
- */
10
-@Data
11
-class LicenseVerifyParam {
12
-    /**
13
-     * 证书subject
14
-     */
15
-    private String subject;
16
-
17
-    /**
18
-     * 公钥别称
19
-     */
20
-    private String publicAlias;
21
-
22
-    /**
23
-     * 访问公钥库的密码
24
-     */
25
-    private String storePass;
26
-
27
-    /**
28
-     * 证书生成路径
29
-     */
30
-    private String licensePath;
31
-
32
-    /**
33
-     * 密钥库存储路径
34
-     */
35
-    private String publicKeysStorePath;
36
-
37
-}

+ 1 - 5
src/main/resources/application.yml

@@ -64,8 +64,4 @@ mybatis-plus:
64 64
 web:
65 65
   upload-path: /home/files
66 66
 cxf:
67
-  path: /intelligent
68
-license:
69
-  subject: smart-grp-front-back
70
-  publicAlias: publicCert
71
-  storePass: public_qsHAN@liangs798
67
+  path: /intelligent