Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
smart_gov_platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
smart_gov_platform
Commits
6743cb05
Commit
6743cb05
authored
Jul 09, 2024
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加门户license验证
parent
30c800dc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
7 deletions
+87
-7
portal-manager/src/main/java/com/mortals/xhx/common/utils/CipherUtil.java
...rc/main/java/com/mortals/xhx/common/utils/CipherUtil.java
+43
-2
portal-manager/src/main/java/com/mortals/xhx/common/utils/CompareTimeUtil.java
...in/java/com/mortals/xhx/common/utils/CompareTimeUtil.java
+5
-0
portal-manager/src/main/java/com/mortals/xhx/common/utils/LicenseUtil.java
...c/main/java/com/mortals/xhx/common/utils/LicenseUtil.java
+6
-3
portal-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/DemoStartedService.java
...als/xhx/daemon/applicationservice/DemoStartedService.java
+32
-1
portal-manager/src/main/resources/bootstrap.yml
portal-manager/src/main/resources/bootstrap.yml
+1
-1
No files found.
portal-manager/src/main/java/com/mortals/xhx/common/utils/CipherUtil.java
View file @
6743cb05
package
com.mortals.xhx.common.utils
;
import
cn.hutool.core.lang.Validator
;
import
cn.hutool.core.net.NetUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.exception.AppException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.ObjectUtils
;
import
java.io.*
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.UnknownHostException
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
/**
* 操作加密授权信息
...
...
@@ -20,6 +27,10 @@ public class CipherUtil {
private
static
boolean
isLinux
=
true
;
public
static
Set
<
String
>
macAndIp
=
new
LinkedHashSet
<>();
// 判断系统
static
{
String
osName
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
...
...
@@ -58,6 +69,10 @@ public class CipherUtil {
}
}
public
static
Set
<
String
>
getMacAndIpSet
()
{
return
macAndIp
;
}
/**
* 获取ip与mac信息
*
...
...
@@ -199,7 +214,7 @@ public class CipherUtil {
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
String
macAddress
=
NetUtil
.
getLocalMacAddress
();
/*
String macAddress = NetUtil.getLocalMacAddress();
System.out.println(macAddress);
...
...
@@ -208,10 +223,36 @@ public class CipherUtil {
System.out.println("HostName:" + localHost.getHostName());
System.out.println(CipherUtil.getApplicationInfo());
*/
Collection
<
NetworkInterface
>
networkInterfaces
=
NetUtil
.
getNetworkInterfaces
();
for
(
NetworkInterface
networkInterface
:
networkInterfaces
)
{
// networkInterface.getInetAddresses().nextElement().
// networkInterface.getInetAddresses()
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
while
(
inetAddresses
.
hasMoreElements
())
{
InetAddress
inetAddress
=
inetAddresses
.
nextElement
();
String
macAddress
=
NetUtil
.
getMacAddress
(
inetAddress
);
if
(
ObjectUtils
.
isEmpty
(
macAddress
))
continue
;
if
(!
Validator
.
isIpv4
(
inetAddress
.
getHostAddress
()))
continue
;
System
.
out
.
println
(
"macAddress:"
+
macAddress
);
System
.
out
.
println
(
"Ip:"
+
inetAddress
.
getHostAddress
());
}
}
/*
Collection<NetworkInterface> networkInterfaces = NetUtil.getNetworkInterfaces();
/*
for (NetworkInterface networkInterface : networkInterfaces) {
// networkInterface.getInetAddresses().nextElement().
...
...
portal-manager/src/main/java/com/mortals/xhx/common/utils/CompareTimeUtil.java
View file @
6743cb05
...
...
@@ -14,6 +14,7 @@ import java.text.DateFormat;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Set
;
/**
* 获取比较时间工具类
...
...
@@ -45,6 +46,10 @@ public class CompareTimeUtil {
// 解密比较时间
//String applicationInfo = CipherUtil.getApplicationInfo();
String
applicationInfo
=
CipherUtil
.
getMacAndIpInfo
();
Set
<
String
>
macAndIpSet
=
CipherUtil
.
getMacAndIpSet
();
String
licenseCode
=
DecodeUtil
.
encryptBySymmetry
(
applicationInfo
,
DecodeUtil
.
AES_KEY
,
DecodeUtil
.
AES
,
true
);
String
key
=
licenseCode
.
replaceAll
(
"\\s*"
,
""
).
replaceAll
(
"[^(A-Za-z)]"
,
""
);
key
=
key
.
length
()
>
16
?
key
.
substring
(
0
,
16
)
:
generateKey
(
key
);
...
...
portal-manager/src/main/java/com/mortals/xhx/common/utils/LicenseUtil.java
View file @
6743cb05
...
...
@@ -91,24 +91,27 @@ public class LicenseUtil {
}
// 获取授权比较时间
/*
long compareTime = CompareTimeUtil.getCompareTime();
// 判断授权时间
if (compareTime >= endTime || compareTime < startTime) {
throw new AppException("授权时间无效!");
}
*/
// 验证授权码是否正确
// 获取服务器的硬件信息编码
//获取 mac信息与ip信息
String
macAndIpInfo
=
CipherUtil
.
getMacAndIpInfo
();
// String macAndIpInfo = CipherUtil.getMacAndIpInfo();
Set
<
String
>
macAndIpSet
=
CipherUtil
.
getMacAndIpSet
();
// String applicationInfo = CipherUtil.getApplicationInfo();
// String applicationInfo = CipherUtil.getApplicationInfo();
// 对授权码进行解密
String
encryptData
=
DecodeUtil
.
decryptBySymmetry
(
licenseCode
,
DecodeUtil
.
AES_KEY
,
DecodeUtil
.
AES
,
true
);
// 对授权码进行与硬件信息编码进行匹配
if
(!
macAndIp
Info
.
equal
s
(
encryptData
))
{
if
(!
macAndIp
Set
.
contain
s
(
encryptData
))
{
throw
new
AppException
(
"授权码不匹配!"
);
}
return
paramMap
;
...
...
portal-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/DemoStartedService.java
View file @
6743cb05
package
com.mortals.xhx.daemon.applicationservice
;
import
cn.hutool.core.lang.Validator
;
import
cn.hutool.core.net.NetUtil
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.xhx.common.utils.CipherUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -8,7 +12,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.stereotype.Component
;
import
com.mortals.framework.springcloud.service.IApplicationStartedService
;
import
org.springframework.util.ObjectUtils
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.Collection
;
import
java.util.Enumeration
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
/**
...
...
@@ -22,6 +32,7 @@ import java.util.List;
* @date 2020年7月15日
*/
@Component
@Slf4j
public
class
DemoStartedService
implements
IApplicationStartedService
{
private
static
Log
logger
=
LogFactory
.
getLog
(
DemoStartedService
.
class
);
...
...
@@ -31,9 +42,29 @@ public class DemoStartedService implements IApplicationStartedService {
@Override
public
void
start
()
{
logger
.
info
(
"开始服务..[配置已加载完成,并且所有框架都已经初始化]"
);
//获取网卡并封装信息
Collection
<
NetworkInterface
>
networkInterfaces
=
NetUtil
.
getNetworkInterfaces
();
for
(
NetworkInterface
networkInterface
:
networkInterfaces
)
{
Enumeration
<
InetAddress
>
inetAddresses
=
networkInterface
.
getInetAddresses
();
while
(
inetAddresses
.
hasMoreElements
())
{
InetAddress
inetAddress
=
inetAddresses
.
nextElement
();
String
macAddress
=
NetUtil
.
getMacAddress
(
inetAddress
);
if
(
ObjectUtils
.
isEmpty
(
macAddress
))
continue
;
String
ip
=
inetAddress
.
getHostAddress
();
if
(!
Validator
.
isIpv4
(
ip
))
continue
;
log
.
info
(
"macAddress:"
+
macAddress
);
log
.
info
(
"Ip:"
+
ip
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"mac="
).
append
(
macAddress
).
append
(
"&ip="
).
append
(
ip
);
CipherUtil
.
macAndIp
.
add
(
sb
.
toString
());
}
}
logger
.
info
(
"开始服务..[配置已加载完成,并且所有框架都已经初始化]"
);
}
@Override
...
...
portal-manager/src/main/resources/bootstrap.yml
View file @
6743cb05
...
...
@@ -48,5 +48,5 @@ sys:
pub
:
/home/license/license.pub
log
:
/home/license
license
:
enable
:
fals
e
enable
:
tru
e
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