将license验证加入到系统中

1.将ClientDemo下的cn文件夹的内容导入项目对应的java目录下。

2.将license-config.properties文件导入resources目录下。

将license验证加入到系统中_第1张图片

3.在项目的pom.xml中添加如下依赖。

    <properties>
        <!-- Apache HttpClient -->
        <httpclient>4.5.5</httpclient>
        <!-- License -->
        <truelicense>1.33</truelicense>
    </properties>


</dependencies>下:
        <!-- Apache HttpClient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient}</version>
        </dependency>

        <!-- Jackson对自动解析JSON和XML格式的支持 -->
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>
        <!-- License -->
        <dependency>
            <groupId>de.schlichtherle.truelicense</groupId>
            <artifactId>truelicense-core</artifactId>
            <version>${truelicense}</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
        </dependency>


最后:
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.tld</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

4.在BcdFlightApplication.java启动项中添加:

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;

@ServletComponentScan
@ComponentScan(basePackageClasses = {BcdFlightApplication.class, LicenseCheckListener.class})
@PropertySource({"license-config.properties"}) //加载额外的配置
public class BcdFlightApplication extends SpringBootServletInitializer {  ...  }

5.在WebMvcConfig.java中添加需要校验的接口。

    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/flight/hlFlyPlan/**");
        registry.addInterceptor(new LicenseCheckInterceptor()).addPathPatterns("/flight/hlFlyDemand/**");
    }

6.linux执行license.sh文件,获取认证所需相关信息;

windows执行(获取IP,mac,CPU,主板信息.bat)文件,获取认证所需相关信息。

7.使用JDK自带的 keytool 工具生成公私钥证书库:

#生成命令
keytool -genkeypair -keysize 1024 -validity 3650 -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -keypass "private_password1234" -dname "CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN"

#导出命令
keytool -exportcert -alias "privateKey" -keystore "privateKeys.keystore" -storepass "public_password1234" -file "certfile.cer"

#导入命令
keytool -import -alias "publicCert" -file "certfile.cer" -keystore "publicCerts.keystore" -storepass "public_password1234"

windows:将privateKeys.keystore,publicCerts.keystore导入C:/layman/目录下
Linux:将privateKeys.keystore,publicCerts.keystore导入/layman/目录下

8.本地启动ServerDemo服务,在postman中执行http://127.0.0.1:7000/license/generateLicense,生成license.lic文件。

windows:将license.lic导入C:/layman/目录下
Linux:将license.lic导入/layman/目录下

9.运行程序,查看证书安装情况。

在这里插入图片描述

你可能感兴趣的:(license,java,license)