Commit 6743cb05 authored by 赵啸非's avatar 赵啸非

添加门户license验证

parent 30c800dc
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().
......
......@@ -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);
......
......@@ -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 (!macAndIpInfo.equals(encryptData)) {
if (!macAndIpSet.contains(encryptData)) {
throw new AppException("授权码不匹配!");
}
return paramMap;
......
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
......
......@@ -48,5 +48,5 @@ sys:
pub: /home/license/license.pub
log: /home/license
license:
enable: false
enable: true
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