自研系统加入license授权(附源码)

1.将ClientDemo(源码找作者获取)下的cn文件夹的内容导入项目对应的java目录下。

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

在这里插入图片描述

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.运行程序,查看证书安装情况。

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值