mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-11 16:57:14 +08:00
refactor(license): 优化 license 模块
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
## continew-starter-license-generate 食用方法
|
||||
## continew-starter-license-generate 使用方法
|
||||
|
||||
1. 引入依赖
|
||||
|
||||
@@ -66,7 +66,8 @@ public class LicenseGenerateController {
|
||||
paramVO.setStorePass("123456a");
|
||||
//设置过期时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
long expire = new Date().getTime() + (24L * 3600L * 1000L);
|
||||
long expire = Instant.now().toEpochMilli() + (24L * 3600L * 1000L);;
|
||||
// long expire = new Date().getTime() + (24L * 3600L * 1000L);
|
||||
calendar.setTimeInMillis(expire);
|
||||
paramVO.setExpireTime(calendar.getTime());
|
||||
//设置额外校验参数(服务器信息)
|
||||
@@ -78,7 +79,4 @@ public class LicenseGenerateController {
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
注:默认生成 license 为C:/license下。将压缩包发送给客户端使用。
|
||||
注:默认生成 license 为FileUtil.getTmpDirPath()下。将压缩包发送给客户端使用。
|
@@ -13,64 +13,23 @@
|
||||
<packaging>jar</packaging>
|
||||
<description>license 生成模块 基于 truelicens 实现</description>
|
||||
|
||||
<properties>
|
||||
<truelicense.version>1.33</truelicense.version>
|
||||
<zip4j.version>2.2.6</zip4j.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!--ContiNew Starter 日志模块 - 核心模块-->
|
||||
<dependency>
|
||||
<groupId>top.continew</groupId>
|
||||
<artifactId>continew-starter-log-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- license 依赖-->
|
||||
<dependency>
|
||||
<groupId>de.schlichtherle.truelicense</groupId>
|
||||
<artifactId>truelicense-core</artifactId>
|
||||
<version>${truelicense.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--zip4j压缩文件-->
|
||||
<dependency>
|
||||
<groupId>net.lingala.zip4j</groupId>
|
||||
<artifactId>zip4j</artifactId>
|
||||
<version>${zip4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--jackson-->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--apache-commons-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.license.autoconfigure;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import top.continew.license.service.LicenseCreateService;
|
||||
import top.continew.starter.core.constant.PropertiesConstants;
|
||||
|
||||
/**
|
||||
* license 生成模块 自动配置
|
||||
*
|
||||
* @author loach
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(LicenseGenerateProperties.class)
|
||||
@ConditionalOnProperty(prefix = PropertiesConstants.LICENSE_GENERATE, name = PropertiesConstants.ENABLED, havingValue = "true", matchIfMissing = true)
|
||||
public class LicenseGenerateAutoConfiguration {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LicenseGenerateAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* license 生成服务接口
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LicenseCreateService licenseCreateService() {
|
||||
return LicenseCreateService.getInstance();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'License-Generate' completed initialization.");
|
||||
}
|
||||
}
|
@@ -14,25 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.license.autoConfiguration;
|
||||
package top.continew.license.autoconfigure;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import top.continew.license.service.LicenseCreateService;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import top.continew.starter.core.constant.PropertiesConstants;
|
||||
|
||||
/**
|
||||
* @Desc:
|
||||
* @Author loach
|
||||
* @ClassName top.continew.license.AutoConfiguration.LicenseGenerateAutoConfiguration
|
||||
* @Date 2025-03-23 10:57
|
||||
* license 生成模块配置属性
|
||||
*
|
||||
* @author Jasmine
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Configuration
|
||||
public class LicenseGenerateAutoConfiguration {
|
||||
@ConfigurationProperties(PropertiesConstants.LICENSE_GENERATE)
|
||||
public class LicenseGenerateProperties {
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public LicenseCreateService licenseCreateService() {
|
||||
return LicenseCreateService.getInstance();
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
@@ -16,12 +16,33 @@
|
||||
|
||||
package top.continew.license.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.schlichtherle.license.*;
|
||||
import net.lingala.zip4j.ZipFile;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import de.schlichtherle.license.CipherParam;
|
||||
import de.schlichtherle.license.DefaultCipherParam;
|
||||
import de.schlichtherle.license.DefaultLicenseParam;
|
||||
import de.schlichtherle.license.KeyStoreParam;
|
||||
import de.schlichtherle.license.LicenseContent;
|
||||
import de.schlichtherle.license.LicenseManager;
|
||||
import de.schlichtherle.license.LicenseParam;
|
||||
import net.lingala.zip4j.ZipFile;
|
||||
import top.continew.license.dto.ConfigParam;
|
||||
import top.continew.license.dto.LicenseCreatorParam;
|
||||
import top.continew.license.dto.LicenseCreatorParamVO;
|
||||
@@ -32,13 +53,6 @@ import top.continew.license.manager.ServerLicenseManager;
|
||||
import top.continew.license.util.ExecCmdUtil;
|
||||
import top.continew.license.util.ServerInfoUtils;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/**
|
||||
* 证书生成接口 实现类
|
||||
*
|
||||
@@ -114,7 +128,7 @@ public class LicenseCreateService {
|
||||
String privateAlias = customerName + "-private-alias";
|
||||
String publicAlias = customerName + "-public-alias";
|
||||
String relativePath = relativePath(paramVO);
|
||||
String currentCustomerDir = relativePath + customerName + uuid() + "/";
|
||||
String currentCustomerDir = relativePath + customerName + uuid() + File.separator;
|
||||
File file = new File(currentCustomerDir);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
|
@@ -16,13 +16,13 @@
|
||||
|
||||
package top.continew.license.util;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* 运行命令行工具类
|
||||
*
|
||||
@@ -50,7 +50,7 @@ public class ExecCmdUtil {
|
||||
process = Runtime.getRuntime().exec(cmd);
|
||||
}
|
||||
} else {
|
||||
cmd = ArrayUtils.addAll(new String[] {"/bin/sh", "-c"}, cmd);
|
||||
cmd = ArrayUtil.addAll(new String[] {"/bin/sh", "-c"}, cmd);
|
||||
process = Runtime.getRuntime().exec(cmd);
|
||||
}
|
||||
|
||||
|
@@ -1 +1 @@
|
||||
top.continew.license.autoConfiguration.LicenseGenerateAutoConfiguration
|
||||
top.continew.license.autoconfigure.LicenseGenerateAutoConfiguration
|
Reference in New Issue
Block a user