Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
license-spring-boot-starter
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-spring-boot-starter
Commits
24986356
Commit
24986356
authored
Jan 12, 2024
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fb3a3f77
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
10 deletions
+35
-10
LicenseManager.java
src/main/java/com/tbyf/license/LicenseManager.java
+18
-3
NetUtil.java
src/main/java/com/tbyf/license/NetUtil.java
+4
-0
LicenseAutoConfiguration.java
.../tbyf/license/autoconfigure/LicenseAutoConfiguration.java
+3
-1
LicenseInstallationServlet.java
...byf/license/autoconfigure/LicenseInstallationServlet.java
+5
-2
LicenseProperties.java
...ava/com/tbyf/license/autoconfigure/LicenseProperties.java
+1
-1
LicenseValidationFilter.java
...m/tbyf/license/autoconfigure/LicenseValidationFilter.java
+2
-1
spring.factories
src/main/resources/META-INF/spring.factories
+2
-2
No files found.
src/main/java/com/tbyf/license/LicenseManager.java
View file @
24986356
package
com
.
tbyf
.
license
;
import
com.tbyf.license.autoconfigure.LicenseProperties
;
import
global.namespace.fun.io.bios.BIOS
;
import
global.namespace.truelicense.api.ConsumerLicenseManager
;
import
global.namespace.truelicense.api.License
;
...
...
@@ -15,6 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Arrays
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
public
class
LicenseManager
implements
InitializingBean
{
...
...
@@ -34,7 +38,13 @@ public class LicenseManager implements InitializingBean {
LicenseProperties
licenseProperties
;
private
static
void
verifyMAC
(
Object
MAC
)
throws
LicenseValidationException
{
if
(
MAC
==
null
||
!
NetUtil
.
containsMAC
(
MAC
.
toString
()))
{
if
(
MAC
==
null
)
{
throw
new
LicenseValidationException
(
Messages
.
message
(
"Invalid License"
));
}
Set
<
String
>
MACs
=
Arrays
.
stream
(
MAC
.
toString
().
split
(
","
))
.
map
(
String:
:
trim
)
.
collect
(
Collectors
.
toSet
());
if
(!
NetUtil
.
containsAnyMAC
(
MACs
))
{
throw
new
LicenseValidationException
(
Messages
.
message
(
"Invalid License"
));
}
}
...
...
@@ -71,8 +81,12 @@ public class LicenseManager implements InitializingBean {
manager
().
install
(
BIOS
.
file
(
licensePath
));
}
public
void
uninstall
()
throws
Exception
{
manager
().
uninstall
();
public
void
uninstall
()
{
try
{
manager
().
uninstall
();
}
catch
(
Exception
ignored
)
{
}
}
public
LicenseValidPeriod
getLicenseValidPeriod
()
throws
LicenseManagementException
{
...
...
@@ -89,6 +103,7 @@ public class LicenseManager implements InitializingBean {
Files
.
createDirectories
(
dir
);
Path
licensePath
=
dir
.
resolve
(
Constants
.
LICENSE_FILE_NAME
);
if
(
Files
.
isRegularFile
(
licensePath
)
&&
Files
.
exists
(
licensePath
))
{
uninstall
();
install
(
licensePath
.
toString
());
}
}
...
...
src/main/java/com/tbyf/license/NetUtil.java
View file @
24986356
...
...
@@ -15,6 +15,10 @@ public class NetUtil {
return
getAllMACs
().
contains
(
MAC
.
toUpperCase
());
}
public
static
boolean
containsAnyMAC
(
Set
<
String
>
MACs
)
{
return
getAllMACs
().
stream
().
anyMatch
(
MACs:
:
contains
);
}
private
static
Set
<
String
>
getAllMACs
()
{
Set
<
String
>
allMACs
=
cache
;
if
(
allMACs
!=
null
&&
!
allMACs
.
isEmpty
())
{
...
...
src/main/java/com/tbyf/license/LicenseAutoConfiguration.java
→
src/main/java/com/tbyf/license/
autoconfigure/
LicenseAutoConfiguration.java
View file @
24986356
package
com
.
tbyf
.
license
;
package
com
.
tbyf
.
license
.
autoconfigure
;
import
com.tbyf.license.LicenseManager
;
import
org.springframework.boot.autoconfigure.AutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration
;
...
...
@@ -14,6 +15,7 @@ import javax.servlet.MultipartConfigElement;
@EnableConfigurationProperties
(
LicenseProperties
.
class
)
@ConditionalOnWebApplication
(
type
=
ConditionalOnWebApplication
.
Type
.
SERVLET
)
@AutoConfiguration
(
after
=
{
DispatcherServletAutoConfiguration
.
class
})
// @ConditionalOnProperty(prefix = "license", name = "enabled", havingValue = "true")
public
class
LicenseAutoConfiguration
{
@Bean
...
...
src/main/java/com/tbyf/license/LicenseInstallationServlet.java
→
src/main/java/com/tbyf/license/
autoconfigure/
LicenseInstallationServlet.java
View file @
24986356
package
com
.
tbyf
.
license
;
package
com
.
tbyf
.
license
.
autoconfigure
;
import
com.tbyf.license.Constants
;
import
com.tbyf.license.LicenseManager
;
import
lombok.Setter
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -31,6 +33,8 @@ public class LicenseInstallationServlet extends HttpServlet {
try
(
InputStream
is
=
filePart
.
getInputStream
())
{
Path
dest
=
Paths
.
get
(
properties
.
getLocation
(),
Constants
.
LICENSE_FILE_NAME
).
toAbsolutePath
().
normalize
();
Files
.
copy
(
is
,
dest
,
StandardCopyOption
.
REPLACE_EXISTING
);
this
.
licenseManager
.
uninstall
();
this
.
licenseManager
.
install
(
dest
.
toString
());
resp
.
setStatus
(
HttpStatus
.
OK
.
value
());
resp
.
setContentType
(
Constants
.
TEXT_PLAIN_MEDIA_TYPE
);
...
...
@@ -43,5 +47,4 @@ public class LicenseInstallationServlet extends HttpServlet {
}
}
}
src/main/java/com/tbyf/license/LicenseProperties.java
→
src/main/java/com/tbyf/license/
autoconfigure/
LicenseProperties.java
View file @
24986356
package
com
.
tbyf
.
license
;
package
com
.
tbyf
.
license
.
autoconfigure
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
...
...
src/main/java/com/tbyf/license/LicenseValidationFilter.java
→
src/main/java/com/tbyf/license/
autoconfigure/
LicenseValidationFilter.java
View file @
24986356
package
com
.
tbyf
.
license
;
package
com
.
tbyf
.
license
.
autoconfigure
;
import
com.tbyf.license.LicenseManager
;
import
global.namespace.fun.io.api.NoContentException
;
import
global.namespace.truelicense.api.LicenseManagementException
;
import
global.namespace.truelicense.api.LicenseValidationException
;
...
...
src/main/resources/META-INF/spring.factories
View file @
24986356
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tbyf.license.LicenseAutoConfiguration
\ No newline at end of file
com.tbyf.license.autoconfigure.LicenseAutoConfiguration
\ 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