Commit 290b66d6 by liuzz

添加mac设置与url过滤设置

parent e1f34e91
......@@ -34,5 +34,10 @@
<version>1.18.28</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.43</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.tbyf.license;
import com.alibaba.fastjson2.JSON;
import global.namespace.fun.io.bios.BIOS;
import global.namespace.truelicense.api.License;
import global.namespace.truelicense.api.LicenseManagementContext;
......@@ -11,6 +12,8 @@ import global.namespace.truelicense.v4.V4;
import javax.security.auth.x500.X500Principal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class LicenseGenerator {
......@@ -56,16 +59,19 @@ public class LicenseGenerator {
public void generate(LicenseParams params) throws LicenseManagementException {
VendorLicenseManager manager = manager();
License license = manager.parameters().licenseFactory().license();
license.setConsumerAmount(1); // 消费者数量
license.setConsumerType(""); // business-企业 personally-个人 project-项目
license.setHolder(new X500Principal(DISTINGUISHED_NAME)); // 许可证持有者的唯一标识
license.setConsumerAmount(params.getAmount()); // 消费者数量
license.setConsumerType(params.getType()); // business-企业 personally-个人 project-项目
license.setHolder(new X500Principal(params.getHolder())); // 许可证持有者的唯一标识
license.setIssuer(new X500Principal(DISTINGUISHED_NAME)); // 许可证颁发者的唯一标识
license.setInfo("TBYF HIP License"); // 面向用户的说明文本
license.setInfo(params.getInfo()); // 面向用户的说明文本
license.setIssued(new Date()); // 许可证颁发日期
license.setNotBefore(new Date()); // 许可证生效日期
license.setNotAfter(new Date()); // 许可证失效日期
license.setSubject("CentralPharmacy-v1"); // 许可证管理的目标(如应用名称和版本范围 "MyApp 1.X")
license.setExtra(params.getMAC()); // 私有数据,如MAC地址
license.setNotBefore(params.getStartDate()); // 许可证生效日期
license.setNotAfter(new Date(params.getStartDate().getTime() + (long) params.getValidity() * 24 * 60 * 60 * 1000)); // 许可证失效日期
license.setSubject(params.getAppName() + "-" + params.getVersion()); // 许可证管理的目标(如应用名称和版本范围 "MyApp 1.X")
Map<String,Object> extra = new HashMap<>();
extra.put("mac",params.getMac());
extra.put("urls",params.getUrls());
license.setExtra(JSON.toJSONString(extra)); // 私有数据,如MAC地址
manager.generateKeyFrom(license)
.saveTo(BIOS.file(params.getLicensePath()));
}
......
......@@ -55,4 +55,9 @@ public class LicenseParams {
* 需要限制的url, *为所有url都支持
*/
private String urls;
/**
* 许可证持有者的标识,例如企业名称、个人姓名等
*/
private String holder;
}
package com.tbyf.license;
import global.namespace.truelicense.api.LicenseManagementException;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class LicenseGeneratorTest {
/**
* 中心药房开发环境
*/
@Test
void generate() throws LicenseManagementException, ParseException {
@SneakyThrows
void centerDevGenerate(){
LicenseGenerator licenseGenerator = new LicenseGenerator();
licenseGenerator.generate(
LicenseParams.builder()
.licensePath("dev.lic")
.validity(3)
// .expirationDate(toDate("2024-01-11 15:12:00"))
.MAC("14-75-5B-E3-DE-1F")
.build());
LicenseParams params = new LicenseParams();
params.setLicensePath("D:\\hip\\license\\CentralPharmacy.license");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
params.setStartDate(dateFormat.parse("2025-08-25"));
params.setValidity(10);
params.setAmount(100);
params.setType("business");
params.setInfo("中心药房开发环境");
params.setAppName("CentralPharmacy");
params.setVersion("1.x");
params.setMac("*");
params.setUrls("*");
params.setHolder("CN=TBYF");
licenseGenerator.generate(params);
}
Date toDate(String dateStr) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.parse(dateStr);
/**
* 中心药房正式环境
*/
@SneakyThrows
@Test
void centerProdGenerate(){
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment