Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hp-smart
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
platform
hp-smart
Commits
66c50f7d
Commit
66c50f7d
authored
Apr 02, 2024
by
宋祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.过滤许可证校验
parent
ebd59c88
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
191 additions
and
0 deletions
+191
-0
LicenseStub.java
...n/java/com/baosight/iplat4j/core/license/LicenseStub.java
+191
-0
No files found.
src/main/java/com/baosight/iplat4j/core/license/LicenseStub.java
0 → 100644
View file @
66c50f7d
package
com
.
baosight
.
iplat4j
.
core
.
license
;
import
com.baosight.iplat4j.core.log.Logger
;
import
com.baosight.iplat4j.core.log.LoggerFactory
;
import
java.io.File
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* 重写许可证校验类,无正式许可证的情况不做校验
*
* @author:songx
* @date:2023/6/28,16:00
*/
public
class
LicenseStub
{
private
static
final
int
CHECK_INTERVAL
=
86400000
;
public
static
String
ERROR
;
public
static
boolean
OK
=
false
;
public
static
String
AUTHORIZED_ENTERPRISE
=
null
;
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
LicenseStub
.
class
);
private
static
String
LICENSE_FILE
=
"license.xml"
;
private
static
String
LICENSE_FILE_PATH
=
null
;
private
static
boolean
flag
=
false
;
private
static
LicenseManager
LICENSE
;
private
static
long
lastCheckTime
=
0L
;
public
LicenseStub
()
{
}
public
static
synchronized
void
init
()
{
File
f
=
new
File
(
LICENSE_FILE_PATH
);
if
(!
f
.
exists
())
{
ERROR
=
"许可证文件["
+
LICENSE_FILE_PATH
+
"]不存在!"
;
LOG
.
error
(
ERROR
);
}
LICENSE
=
LicenseManager
.
getInstance
(
LICENSE_FILE_PATH
);
}
public
static
String
[]
getLicenseInfo
()
{
String
[]
info
=
new
String
[
2
];
if
(
checkLicense
()
&&
LICENSE
!=
null
)
{
info
[
0
]
=
"0"
;
info
[
1
]
=
"许可证文件: "
+
LICENSE_FILE_PATH
+
"\n"
+
LICENSE
.
getAllInfo
();
}
else
{
info
[
0
]
=
"1"
;
info
[
1
]
=
"许可证文件: "
+
LICENSE_FILE_PATH
+
"\n"
+
(
ERROR
==
null
?
""
:
ERROR
);
}
return
info
;
}
public
static
String
[]
checkLicense2
()
{
// 无需校验许可证 modify by songx at 20230628
return
new
String
[]{
"true"
,
""
,
"9999999"
,
"true"
};
}
public
static
boolean
checkLicense
()
{
String
[]
ret
=
checkLicense2
();
return
"true"
.
equals
(
ret
[
0
]);
}
public
static
void
setLicenseDir
(
String
dir
)
{
if
(
LICENSE_FILE_PATH
==
null
)
{
LOG
.
info
(
"[LICENSE] check environment <PLAT_LICENSE>..."
);
String
platLicense
=
System
.
getenv
(
"PLAT_LICENSE"
);
if
(
platLicense
!=
null
)
{
LOG
.
info
(
"[LICENSE] environment <PLAT_LICENSE> defined as <"
+
platLicense
+
">."
);
File
f
=
new
File
(
platLicense
);
if
(
f
.
isFile
())
{
LICENSE_FILE_PATH
=
platLicense
;
LOG
.
info
(
"[LICENSE] use <"
+
LICENSE_FILE_PATH
+
">."
);
return
;
}
LOG
.
info
(
"[LICENSE] file <"
+
LICENSE_FILE_PATH
+
"> not exist."
);
}
else
{
LOG
.
info
(
"[LICENSE] environment <PLAT_LICENSE> not defined."
);
}
LICENSE_FILE_PATH
=
dir
+
File
.
separator
+
"license"
+
File
.
separator
+
LICENSE_FILE
;
LOG
.
info
(
"[LICENSE] use <"
+
LICENSE_FILE_PATH
+
"> instead."
);
}
}
private
static
void
setError
(
String
msg
)
{
OK
=
false
;
ERROR
=
msg
;
LOG
.
error
(
"[LICENSE] "
+
msg
);
LOG
.
error
(
msg
);
}
static
String
checkMac
(
String
macInLicense
)
{
if
(
macInLicense
!=
null
&&
macInLicense
.
trim
().
length
()
!=
0
)
{
String
[]
macs
=
macInLicense
.
trim
().
split
(
"(,|;|\\s)"
);
Set
<
String
>
hostMacs
=
getHostMac
();
if
(
hostMacs
==
null
)
{
return
"许可证验证失败,请在Java6或者以上环境运行!"
;
}
else
{
String
[]
var3
=
macs
;
int
var4
=
macs
.
length
;
for
(
int
var5
=
0
;
var5
<
var4
;
++
var5
)
{
String
mac
=
var3
[
var5
];
String
nmac
=
mac
.
replaceAll
(
"(:|-)"
,
":"
).
toUpperCase
();
if
(
hostMacs
.
contains
(
nmac
))
{
return
null
;
}
}
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"许可的MAC地址不符:"
);
sb
.
append
(
Arrays
.
toString
(
macs
));
sb
.
append
(
"; "
);
sb
.
append
(
"本机MAC地址:"
);
sb
.
append
(
hostMacs
);
return
sb
.
toString
();
}
}
else
{
return
null
;
}
}
private
static
Set
<
String
>
getHostMac
()
{
Enumeration
interfaces
=
null
;
try
{
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
}
catch
(
SocketException
var14
)
{
LOG
.
error
(
var14
.
getMessage
(),
var14
);
return
Collections
.
EMPTY_SET
;
}
HashSet
macs
=
new
HashSet
();
while
(
interfaces
.
hasMoreElements
())
{
NetworkInterface
ni
=
(
NetworkInterface
)
interfaces
.
nextElement
();
Object
var3
=
null
;
byte
[]
address
;
try
{
Method
getHardwareAddress
=
ni
.
getClass
().
getDeclaredMethod
(
"getHardwareAddress"
,
(
Class
[])
null
);
address
=
(
byte
[])
((
byte
[])
getHardwareAddress
.
invoke
(
ni
,
(
Object
[])
null
));
}
catch
(
NoSuchMethodException
var9
)
{
LOG
.
error
(
var9
.
getMessage
(),
var9
);
return
null
;
}
catch
(
SecurityException
var10
)
{
LOG
.
error
(
var10
.
getMessage
(),
var10
);
return
null
;
}
catch
(
IllegalAccessException
var11
)
{
LOG
.
error
(
var11
.
getMessage
(),
var11
);
return
null
;
}
catch
(
IllegalArgumentException
var12
)
{
LOG
.
error
(
var12
.
getMessage
(),
var12
);
return
null
;
}
catch
(
InvocationTargetException
var13
)
{
LOG
.
error
(
var13
.
getMessage
(),
var13
);
return
null
;
}
if
(
address
!=
null
&&
address
.
length
!=
0
)
{
StringBuilder
sb
=
new
StringBuilder
(
18
);
byte
[]
var5
=
address
;
int
var6
=
address
.
length
;
for
(
int
var7
=
0
;
var7
<
var6
;
++
var7
)
{
byte
b
=
var5
[
var7
];
if
(
sb
.
length
()
>
0
)
{
sb
.
append
(
':'
);
}
sb
.
append
(
String
.
format
(
"%02x"
,
b
).
toUpperCase
());
}
String
mac
=
sb
.
toString
().
trim
();
if
(
mac
.
length
()
>
0
)
{
LOG
.
info
(
"[LICENSE] local MAC: "
+
mac
);
macs
.
add
(
mac
);
}
}
}
return
macs
;
}
}
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