From 822f288fec81e930fdb0aeceb7315433ffbe0d08 Mon Sep 17 00:00:00 2001 From: whycq <10027870+whycq@user.noreply.gitee.com> Date: 星期四, 07 十二月 2023 10:04:00 +0800 Subject: [PATCH] # --- src/main/java/com/zy/system/entity/license/LicenseVerifyParam.java | 48 +++ src/main/java/com/zy/system/entity/license/LicenseManagerHolder.java | 22 + src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java | 57 ++++ src/main/java/com/zy/system/entity/license/CustomLicenseManager.java | 241 ++++++++++++++++++ src/main/java/com/zy/system/entity/license/LicenseVerify.java | 133 ++++++++++ src/main/java/com/zy/system/entity/license/WindowsServerInfos.java | 85 ++++++ src/main/java/com/zy/system/entity/license/AbstractServerInfos.java | 111 ++++++++ src/main/java/com/zy/system/entity/license/LicenseCheck.java | 45 +++ 8 files changed, 742 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java b/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java new file mode 100644 index 0000000..f771d16 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/AbstractServerInfos.java @@ -0,0 +1,111 @@ +package com.zy.system.entity.license; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * 鐢ㄤ簬鑾峰彇瀹㈡埛鏈嶅姟鍣ㄧ殑鍩烘湰淇℃伅锛屽锛欼P銆丮ac鍦板潃銆丆PU搴忓垪鍙枫�佷富鏉垮簭鍒楀彿绛� + */ +public abstract class AbstractServerInfos { + private static Logger logger = LogManager.getLogger(AbstractServerInfos.class); + + /** + * 缁勮闇�瑕侀澶栨牎楠岀殑License鍙傛暟 + */ + public LicenseCheck getServerInfos(){ + LicenseCheck result = new LicenseCheck(); + + try { + result.setIpAddress(this.getIpAddress()); + result.setMacAddress(this.getMacAddress()); + result.setCpuSerial(this.getCPUSerial()); + result.setMainBoardSerial(this.getMainBoardSerial()); + }catch (Exception e){ + logger.error("鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭け璐�",e); + } + + return result; + } + + /** + * 鑾峰彇IP鍦板潃 + */ + protected abstract List<String> getIpAddress() throws Exception; + + /** + * 鑾峰彇Mac鍦板潃 + */ + protected abstract List<String> getMacAddress() throws Exception; + + /** + * 鑾峰彇CPU搴忓垪鍙� + */ + protected abstract String getCPUSerial() throws Exception; + + /** + * 鑾峰彇涓绘澘搴忓垪鍙� + */ + protected abstract String getMainBoardSerial() throws Exception; + + /** + * 鑾峰彇褰撳墠鏈嶅姟鍣ㄦ墍鏈夌鍚堟潯浠剁殑InetAddress + */ + protected List<InetAddress> getLocalAllInetAddress() throws Exception { + List<InetAddress> result = new ArrayList<>(4); + + // 閬嶅巻鎵�鏈夌殑缃戠粶鎺ュ彛 + for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) { + NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement(); + // 鍦ㄦ墍鏈夌殑鎺ュ彛涓嬪啀閬嶅巻IP + for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) { + InetAddress inetAddr = (InetAddress) inetAddresses.nextElement(); + + //鎺掗櫎LoopbackAddress銆丼iteLocalAddress銆丩inkLocalAddress銆丮ulticastAddress绫诲瀷鐨処P鍦板潃 + if(!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/ + && !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()){ + result.add(inetAddr); + } + } + } + + return result; + } + + /** + * 鑾峰彇鏌愪釜缃戠粶鎺ュ彛鐨凪ac鍦板潃 + */ + protected String getMacByInetAddress(InetAddress inetAddr){ + try { + byte[] mac = NetworkInterface.getByInetAddress(inetAddr).getHardwareAddress(); + StringBuffer stringBuffer = new StringBuffer(); + + for(int i=0;i<mac.length;i++){ + if(i != 0) { + stringBuffer.append("-"); + } + + //灏嗗崄鍏繘鍒禸yte杞寲涓哄瓧绗︿覆 + String temp = Integer.toHexString(mac[i] & 0xff); + if(temp.length() == 1){ + stringBuffer.append("0" + temp); + }else{ + stringBuffer.append(temp); + } + } + + return stringBuffer.toString().toUpperCase(); + } catch (SocketException e) { + e.printStackTrace(); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java b/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java new file mode 100644 index 0000000..3d4e4b9 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/CustomKeyStoreParam.java @@ -0,0 +1,57 @@ +package com.zy.system.entity.license; + +import de.schlichtherle.license.AbstractKeyStoreParam; + +import java.io.*; + +/** + * 鑷畾涔塊eyStoreParam锛岀敤浜庡皢鍏閽ュ瓨鍌ㄦ枃浠跺瓨鏀惧埌鍏朵粬纾佺洏浣嶇疆鑰屼笉鏄」鐩腑 + */ +public class CustomKeyStoreParam extends AbstractKeyStoreParam { + + /** + * 鍏挜/绉侀挜鍦ㄧ鐩樹笂鐨勫瓨鍌ㄨ矾寰� + */ + private String storePath; + private String alias; + private String storePwd; + private String keyPwd; + + public CustomKeyStoreParam(Class clazz, String resource, String alias, String storePwd, String keyPwd) { + super(clazz, resource); + this.storePath = resource; + this.alias = alias; + this.storePwd = storePwd; + this.keyPwd = keyPwd; + } + + + @Override + public String getAlias() { + return alias; + } + + @Override + public String getStorePwd() { + return storePwd; + } + + @Override + public String getKeyPwd() { + return keyPwd; + } + + /** + * 澶嶅啓de.schlichtherle.license.AbstractKeyStoreParam鐨刧etStream()鏂规硶<br/> + * 鐢ㄤ簬灏嗗叕绉侀挜瀛樺偍鏂囦欢瀛樻斁鍒板叾浠栫鐩樹綅缃�屼笉鏄」鐩腑 + */ + @Override + public InputStream getStream() throws IOException { + final InputStream in = new FileInputStream(new File(storePath)); + if (null == in) { + throw new FileNotFoundException(storePath); + } + + return in; + } +} diff --git a/src/main/java/com/zy/system/entity/license/CustomLicenseManager.java b/src/main/java/com/zy/system/entity/license/CustomLicenseManager.java new file mode 100644 index 0000000..a0cd9e8 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/CustomLicenseManager.java @@ -0,0 +1,241 @@ +package com.zy.system.entity.license; + +import com.core.common.Cools; +import de.schlichtherle.license.*; +import de.schlichtherle.xml.GenericCertificate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.beans.XMLDecoder; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; +import java.util.Date; +import java.util.List; + +/** + * 鑷畾涔塋icenseManager锛岀敤浜庡鍔犻澶栫殑鏈嶅姟鍣ㄧ‖浠朵俊鎭牎楠� + */ +public class CustomLicenseManager extends LicenseManager{ + private static Logger logger = LogManager.getLogger(CustomLicenseManager.class); + + //XML缂栫爜 + private static final String XML_CHARSET = "UTF-8"; + //榛樿BUFSIZE + private static final int DEFAULT_BUFSIZE = 8 * 1024; + + public CustomLicenseManager() { + + } + + public CustomLicenseManager(LicenseParam param) { + super(param); + } + + /** + * 澶嶅啓create鏂规硶 + */ + @Override + protected synchronized byte[] create( + LicenseContent content, + LicenseNotary notary) + throws Exception { + initialize(content); + this.validateCreate(content); + final GenericCertificate certificate = notary.sign(content); + return getPrivacyGuard().cert2key(certificate); + } + + /** + * 澶嶅啓install鏂规硶锛屽叾涓璿alidate鏂规硶璋冪敤鏈被涓殑validate鏂规硶锛屾牎楠孖P鍦板潃銆丮ac鍦板潃绛夊叾浠栦俊鎭� + */ + @Override + protected synchronized LicenseContent install( + final byte[] key, + final LicenseNotary notary) + throws Exception { + final GenericCertificate certificate = getPrivacyGuard().key2cert(key); + + notary.verify(certificate); + final LicenseContent content = (LicenseContent)this.load(certificate.getEncoded()); + this.validate(content); + setLicenseKey(key); + setCertificate(certificate); + + return content; + } + + /** + * 澶嶅啓verify鏂规硶锛岃皟鐢ㄦ湰绫讳腑鐨剉alidate鏂规硶锛屾牎楠孖P鍦板潃銆丮ac鍦板潃绛夊叾浠栦俊鎭� + */ + @Override + protected synchronized LicenseContent verify(final LicenseNotary notary) + throws Exception { + GenericCertificate certificate = getCertificate(); + + // Load license key from preferences, + final byte[] key = getLicenseKey(); + if (null == key){ + throw new NoLicenseInstalledException(getLicenseParam().getSubject()); + } + + certificate = getPrivacyGuard().key2cert(key); + notary.verify(certificate); + final LicenseContent content = (LicenseContent)this.load(certificate.getEncoded()); + this.validate(content); + setCertificate(certificate); + + return content; + } + + /** + * 鏍¢獙鐢熸垚璇佷功鐨勫弬鏁颁俊鎭� + */ + protected synchronized void validateCreate(final LicenseContent content) + throws LicenseContentException { + final LicenseParam param = getLicenseParam(); + + final Date now = new Date(); + final Date notBefore = content.getNotBefore(); + final Date notAfter = content.getNotAfter(); + if (null != notAfter && now.after(notAfter)){ + throw new LicenseContentException("璇佷功澶辨晥鏃堕棿涓嶈兘鏃╀簬褰撳墠鏃堕棿"); + } + if (null != notBefore && null != notAfter && notAfter.before(notBefore)){ + throw new LicenseContentException("璇佷功鐢熸晥鏃堕棿涓嶈兘鏅氫簬璇佷功澶辨晥鏃堕棿"); + } + final String consumerType = content.getConsumerType(); + if (null == consumerType){ + throw new LicenseContentException("鐢ㄦ埛绫诲瀷涓嶈兘涓虹┖"); + } + } + + + /** + * 澶嶅啓validate鏂规硶锛屽鍔營P鍦板潃銆丮ac鍦板潃绛夊叾浠栦俊鎭牎楠� + */ + @Override + protected synchronized void validate(final LicenseContent content) + throws LicenseContentException { + //1. 棣栧厛璋冪敤鐖剁被鐨剉alidate鏂规硶 + super.validate(content); + + //2. 鐒跺悗鏍¢獙鑷畾涔夌殑License鍙傛暟 + //License涓彲琚厑璁哥殑鍙傛暟淇℃伅 + LicenseCheck expectedCheckModel = (LicenseCheck) content.getExtra(); + //褰撳墠鏈嶅姟鍣ㄧ湡瀹炵殑鍙傛暟淇℃伅 + LicenseCheck serverCheckModel = getServerInfos(); + + if(expectedCheckModel != null && serverCheckModel != null){ + //鏍¢獙IP鍦板潃 + if(!checkIpAddress(expectedCheckModel.getIpAddress(),serverCheckModel.getIpAddress())){ + //throw new LicenseContentException("褰撳墠鏈嶅姟鍣ㄧ殑IP娌″湪鎺堟潈鑼冨洿鍐�"); + } + + //鏍¢獙Mac鍦板潃 + if(!checkIpAddress(expectedCheckModel.getMacAddress(),serverCheckModel.getMacAddress())){ + //throw new LicenseContentException("褰撳墠鏈嶅姟鍣ㄧ殑Mac鍦板潃娌″湪鎺堟潈鑼冨洿鍐�"); + } + + //鏍¢獙涓绘澘搴忓垪鍙� + if(!checkSerial(expectedCheckModel.getMainBoardSerial(),serverCheckModel.getMainBoardSerial())){ + throw new LicenseContentException("褰撳墠鏈嶅姟鍣ㄧ殑涓绘澘搴忓垪鍙锋病鍦ㄦ巿鏉冭寖鍥村唴"); + } + + //鏍¢獙CPU搴忓垪鍙� + if(!checkSerial(expectedCheckModel.getCpuSerial(),serverCheckModel.getCpuSerial())){ + throw new LicenseContentException("褰撳墠鏈嶅姟鍣ㄧ殑CPU搴忓垪鍙锋病鍦ㄦ巿鏉冭寖鍥村唴"); + } + }else{ + throw new LicenseContentException("涓嶈兘鑾峰彇鏈嶅姟鍣ㄧ‖浠朵俊鎭�"); + } + } + + + /** + * 閲嶅啓XMLDecoder瑙f瀽XML + */ + private Object load(String encoded){ + BufferedInputStream inputStream = null; + XMLDecoder decoder = null; + try { + inputStream = new BufferedInputStream(new ByteArrayInputStream(encoded.getBytes(XML_CHARSET))); + + decoder = new XMLDecoder(new BufferedInputStream(inputStream, DEFAULT_BUFSIZE),null,null); + + return decoder.readObject(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } finally { + try { + if(decoder != null){ + decoder.close(); + } + if(inputStream != null){ + inputStream.close(); + } + } catch (Exception e) { + logger.error("XMLDecoder瑙f瀽XML澶辫触",e); + } + } + + return null; + } + + /** + * 鑾峰彇褰撳墠鏈嶅姟鍣ㄩ渶瑕侀澶栨牎楠岀殑License鍙傛暟 + */ + private LicenseCheck getServerInfos(){ + //鎿嶄綔绯荤粺绫诲瀷 + String osName = System.getProperty("os.name").toLowerCase(); + AbstractServerInfos abstractServerInfos = null; + + //鏍规嵁涓嶅悓鎿嶄綔绯荤粺绫诲瀷閫夋嫨涓嶅悓鐨勬暟鎹幏鍙栨柟娉� + if (osName.startsWith("windows")) { + abstractServerInfos = new WindowsServerInfos(); + } else if (osName.startsWith("linux")) { +// abstractServerInfos = new LinuxServerInfos(); + }else{//鍏朵粬鏈嶅姟鍣ㄧ被鍨� + abstractServerInfos = new WindowsServerInfos(); + } + + return abstractServerInfos.getServerInfos(); + } + + /** + * 鏍¢獙褰撳墠鏈嶅姟鍣ㄧ殑IP/Mac鍦板潃鏄惁鍦ㄥ彲琚厑璁哥殑IP鑼冨洿鍐�<br/> + * 濡傛灉瀛樺湪IP鍦ㄥ彲琚厑璁哥殑IP/Mac鍦板潃鑼冨洿鍐咃紝鍒欒繑鍥瀟rue + */ + private boolean checkIpAddress(List<String> expectedList,List<String> serverList){ + if(expectedList != null && expectedList.size() > 0){ + if(serverList != null && serverList.size() > 0){ + for(String expected : expectedList){ + if(serverList.contains(expected.trim())){ + return true; + } + } + } + + return false; + }else { + return true; + } + } + + /** + * 鏍¢獙褰撳墠鏈嶅姟鍣ㄧ‖浠讹紙涓绘澘銆丆PU绛夛級搴忓垪鍙锋槸鍚﹀湪鍙厑璁歌寖鍥村唴 + */ + private boolean checkSerial(String expectedSerial,String serverSerial){ + if(!Cools.isEmpty(expectedSerial)){ + if(!Cools.isEmpty(serverSerial)){ + if(expectedSerial.equals(serverSerial)){ + return true; + } + } + return false; + }else{ + return true; + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/zy/system/entity/license/LicenseCheck.java b/src/main/java/com/zy/system/entity/license/LicenseCheck.java new file mode 100644 index 0000000..660f818 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/LicenseCheck.java @@ -0,0 +1,45 @@ +package com.zy.system.entity.license; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 鑷畾涔夐渶瑕佹牎楠岀殑License鍙傛暟 + */ +@Data +public class LicenseCheck implements Serializable { + + private static final long serialVersionUID = 8600137500316662317L; + /** + * 鍙鍏佽鐨処P鍦板潃 + */ + private List<String> ipAddress; + + /** + * 鍙鍏佽鐨凪AC鍦板潃 + */ + private List<String> macAddress; + + /** + * 鍙鍏佽鐨凜PU搴忓垪鍙� + */ + private String cpuSerial; + + /** + * 鍙鍏佽鐨勪富鏉垮簭鍒楀彿 + */ + private String mainBoardSerial; + + @Override + public String toString() { + return "LicenseCheckModel{" + + "ipAddress=" + ipAddress + + ", macAddress=" + macAddress + + ", cpuSerial='" + cpuSerial + '\'' + + ", mainBoardSerial='" + mainBoardSerial + '\'' + + '}'; + } + +} diff --git a/src/main/java/com/zy/system/entity/license/LicenseManagerHolder.java b/src/main/java/com/zy/system/entity/license/LicenseManagerHolder.java new file mode 100644 index 0000000..64c6f39 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/LicenseManagerHolder.java @@ -0,0 +1,22 @@ +package com.zy.system.entity.license; + +import de.schlichtherle.license.LicenseManager; +import de.schlichtherle.license.LicenseParam; + +public class LicenseManagerHolder { + + private static volatile LicenseManager LICENSE_MANAGER; + + public static LicenseManager getInstance(LicenseParam param) { + if (LICENSE_MANAGER == null) { + synchronized (LicenseManagerHolder.class) { + if (LICENSE_MANAGER == null) { + LICENSE_MANAGER = new CustomLicenseManager(param); + } + } + } + + return LICENSE_MANAGER; + } + +} \ No newline at end of file diff --git a/src/main/java/com/zy/system/entity/license/LicenseVerify.java b/src/main/java/com/zy/system/entity/license/LicenseVerify.java new file mode 100644 index 0000000..2175930 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/LicenseVerify.java @@ -0,0 +1,133 @@ +package com.zy.system.entity.license; + +import de.schlichtherle.license.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.io.File; +import java.text.DateFormat; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.prefs.Preferences; + +/** + * License鏍¢獙绫� + */ +public class LicenseVerify { + private static Logger logger = LogManager.getLogger(LicenseVerify.class); + + /** + * 瀹夎License璇佷功 + */ + public synchronized LicenseContent install(LicenseVerifyParam param){ + LicenseContent result = null; + DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + //1. 瀹夎璇佷功 + try{ + LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param)); + licenseManager.uninstall(); + + result = licenseManager.install(new File(param.getLicensePath())); + logger.info(MessageFormat.format("璁稿彲璇佸姞杞芥垚鍔燂紝璁稿彲璇佹湁鏁堟湡锛歿0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter()))); + }catch (Exception e){ + logger.error("璁稿彲璇佸姞杞藉け璐ワ紒",e); + } + + return result; + } + + /** + * 鏍¢獙License璇佷功 + */ + public boolean verify(){ + try { + LicenseManager licenseManager = LicenseManagerHolder.getInstance(null); + DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + if (!updateSystemTime()) { + //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼 + return false; + } + + LicenseContent licenseContent = licenseManager.verify(); + logger.info(MessageFormat.format("璁稿彲璇佹牎楠岄�氳繃锛岃鍙瘉鏈夋晥鏈燂細{0} - {1}",format.format(licenseContent.getNotBefore()),format.format(licenseContent.getNotAfter()))); + return true; + }catch (Exception e){ + logger.error("璁稿彲璇佹牎楠屽け璐ワ紒",e); + return false; + } + } + + /** + * 鏍¢獙License璇佷功骞惰幏鍙栬瘉涔︿俊鎭� + */ + public LicenseContent getVerifyInfo(){ + LicenseManager licenseManager = LicenseManagerHolder.getInstance(null); + + if (!updateSystemTime()) { + //鏃堕棿鏇存柊澶辫触锛岀郴缁熸椂闂磋鏇存敼 + return null; + } + + //鏍¢獙璇佷功 + try { + LicenseContent licenseContent = licenseManager.verify(); + return licenseContent; + }catch (Exception e){ + logger.error("璁稿彲璇佹牎楠屽け璐ワ紒",e); + return null; + } + } + + /** + * 鍒濆鍖栬瘉涔︾敓鎴愬弬鏁� + * @param param License鏍¢獙绫婚渶瑕佺殑鍙傛暟 + * @return de.schlichtherle.license.LicenseParam + */ + private LicenseParam initLicenseParam(LicenseVerifyParam param){ + Preferences preferences = Preferences.userNodeForPackage(LicenseVerify.class); + + CipherParam cipherParam = new DefaultCipherParam(param.getStorePass()); + + KeyStoreParam publicStoreParam = new CustomKeyStoreParam(LicenseVerify.class + ,param.getPublicKeysStorePath() + ,param.getPublicAlias() + ,param.getStorePass() + ,null); + + return new DefaultLicenseParam(param.getSubject() + ,preferences + ,publicStoreParam + ,cipherParam); + } + + /** + * 鏇存柊鏃堕棿鍒版敞鍐岃〃涓� + */ + private boolean updateSystemTime() { + // 鑾峰彇鐢ㄦ埛鏍硅妭鐐� + Preferences userRoot = Preferences.userRoot(); + // 鑾峰彇鎸囧畾璺緞涓嬬殑鑺傜偣 + Preferences node = userRoot.node("/zhongyang"); + String key = "time"; + // 璇诲彇娉ㄥ唽琛� + String value = node.get(key, null); + if (value != null) { + long originTime = Long.parseLong(value); + long now = System.currentTimeMillis(); + long diff = now - originTime;//鐜板湪鏃堕棿 - 婧愭椂闂� = 鏃堕棿宸� + if (diff > 0) { + //鏃堕棿宸ぇ浜�0鎵嶅厑璁告洿鏂版敞鍐岃〃鏃堕棿 + node.put(key, String.valueOf(System.currentTimeMillis())); + return true; + } + }else { + // 鍐欏叆娉ㄥ唽琛� + node.put(key, String.valueOf(System.currentTimeMillis())); + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/com/zy/system/entity/license/LicenseVerifyParam.java b/src/main/java/com/zy/system/entity/license/LicenseVerifyParam.java new file mode 100644 index 0000000..33806e5 --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/LicenseVerifyParam.java @@ -0,0 +1,48 @@ +package com.zy.system.entity.license; + +import lombok.Data; + +/** + * 鏍¢獙绛惧悕鏂囦欢 + */ +@Data +public class LicenseVerifyParam { + + /** + * 璇佷功subject + */ + private String subject; + + /** + * 鍏挜鍒О + */ + private String publicAlias; + + /** + * 璁块棶鍏挜搴撶殑瀵嗙爜 + */ + private String storePass; + + /** + * 璇佷功鐢熸垚璺緞 + */ + private String licensePath; + + /** + * 瀵嗛挜搴撳瓨鍌ㄨ矾寰� + */ + private String publicKeysStorePath; + + public LicenseVerifyParam() { + + } + + public LicenseVerifyParam(String subject, String publicAlias, String storePass, String licensePath, String publicKeysStorePath) { + this.subject = subject; + this.publicAlias = publicAlias; + this.storePass = storePass; + this.licensePath = licensePath; + this.publicKeysStorePath = publicKeysStorePath; + } + +} diff --git a/src/main/java/com/zy/system/entity/license/WindowsServerInfos.java b/src/main/java/com/zy/system/entity/license/WindowsServerInfos.java new file mode 100644 index 0000000..c575e6d --- /dev/null +++ b/src/main/java/com/zy/system/entity/license/WindowsServerInfos.java @@ -0,0 +1,85 @@ +package com.zy.system.entity.license; + +import java.net.InetAddress; +import java.util.List; +import java.util.Scanner; +import java.util.stream.Collectors; + +/** + * 鐢ㄤ簬鑾峰彇瀹㈡埛Windows鏈嶅姟鍣ㄧ殑鍩烘湰淇℃伅 + */ +public class WindowsServerInfos extends AbstractServerInfos { + + @Override + protected List<String> getIpAddress() throws Exception { + List<String> result = null; + + //鑾峰彇鎵�鏈夌綉缁滄帴鍙� + List<InetAddress> inetAddresses = getLocalAllInetAddress(); + + if(inetAddresses != null && inetAddresses.size() > 0){ + result = inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList()); + } + + return result; + } + + @Override + protected List<String> getMacAddress() throws Exception { + List<String> result = null; + + //1. 鑾峰彇鎵�鏈夌綉缁滄帴鍙� + List<InetAddress> inetAddresses = getLocalAllInetAddress(); + + if(inetAddresses != null && inetAddresses.size() > 0){ + //2. 鑾峰彇鎵�鏈夌綉缁滄帴鍙g殑Mac鍦板潃 + result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList()); + } + + return result; + } + + @Override + protected String getCPUSerial() throws Exception { + //搴忓垪鍙� + String serialNumber = ""; + + //浣跨敤WMIC鑾峰彇CPU搴忓垪鍙� + Process process = Runtime.getRuntime().exec("wmic cpu get processorid"); + process.getOutputStream().close(); + Scanner scanner = new Scanner(process.getInputStream()); + + if(scanner.hasNext()){ + scanner.next(); + } + + if(scanner.hasNext()){ + serialNumber = scanner.next().trim(); + } + + scanner.close(); + return serialNumber; + } + + @Override + protected String getMainBoardSerial() throws Exception { + //搴忓垪鍙� + String serialNumber = ""; + + //浣跨敤WMIC鑾峰彇涓绘澘搴忓垪鍙� + Process process = Runtime.getRuntime().exec("wmic baseboard get serialnumber"); + process.getOutputStream().close(); + Scanner scanner = new Scanner(process.getInputStream()); + + if(scanner.hasNext()){ + scanner.next(); + } + + if(scanner.hasNext()){ + serialNumber = scanner.next().trim(); + } + + scanner.close(); + return serialNumber; + } +} \ No newline at end of file -- Gitblit v1.9.1