Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
license-generator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
license-generator
Commits
290b66d6
Commit
290b66d6
authored
Aug 25, 2025
by
liuzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加mac设置与url过滤设置
parent
e1f34e91
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
22 deletions
+54
-22
pom.xml
pom.xml
+6
-0
LicenseGenerator.java
src/main/java/com/tbyf/license/LicenseGenerator.java
+14
-8
LicenseParams.java
src/main/java/com/tbyf/license/LicenseParams.java
+5
-0
LicenseGeneratorTest.java
src/test/java/com/tbyf/license/LicenseGeneratorTest.java
+29
-14
No files found.
pom.xml
View file @
290b66d6
...
...
@@ -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
src/main/java/com/tbyf/license/LicenseGenerator.java
View file @
290b66d6
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
()));
}
...
...
src/main/java/com/tbyf/license/LicenseParams.java
View file @
290b66d6
...
...
@@ -55,4 +55,9 @@ public class LicenseParams {
* 需要限制的url, *为所有url都支持
*/
private
String
urls
;
/**
* 许可证持有者的标识,例如企业名称、个人姓名等
*/
private
String
holder
;
}
src/test/java/com/tbyf/license/LicenseGeneratorTest.java
View file @
290b66d6
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment