| | |
| | | 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; |
| | |
| | | //1. 首先调用父类的validate方法 |
| | | super.validate(content); |
| | | |
| | | //2. 然后校验自定义的License参数 |
| | | //License中可被允许的参数信息 |
| | | LicenseCheck expectedCheckModel = (LicenseCheck) content.getExtra(); |
| | | //当前服务器真实的参数信息 |
| | | Object extra = content.getExtra(); |
| | | LicenseCheck serverCheckModel = LicenseUtils.getServerInfos(); |
| | | |
| | | if(expectedCheckModel != null && serverCheckModel != null){ |
| | | if (serverCheckModel == null) { |
| | | throw new LicenseContentException("不能获取服务器硬件信息"); |
| | | } |
| | | |
| | | if (LicenseBindingSupport.isV2Extra(extra)) { |
| | | LicenseBindModel bindModel = LicenseBindingSupport.parseBindModel(extra); |
| | | if (!LicenseBindingSupport.matches(bindModel, serverCheckModel)) { |
| | | throw new LicenseContentException("当前服务器不在授权节点范围内"); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | LicenseCheck expectedCheckModel = LicenseBindingSupport.parseLegacyLicenseCheck(extra); |
| | | if(expectedCheckModel != null){ |
| | | //校验IP地址 |
| | | if(!checkIpAddress(expectedCheckModel.getIpAddress(),serverCheckModel.getIpAddress())){ |
| | | throw new LicenseContentException("当前服务器的IP没在授权范围内"); |
| | |
| | | * 校验当前服务器硬件(主板、CPU等)序列号是否在可允许范围内 |
| | | */ |
| | | private boolean checkSerial(String expectedSerial,String serverSerial){ |
| | | if(!Cools.isEmpty(expectedSerial)){ |
| | | if(!Cools.isEmpty(serverSerial)){ |
| | | if(!isBlank(expectedSerial)){ |
| | | if(!isBlank(serverSerial)){ |
| | | if(expectedSerial.equals(serverSerial)){ |
| | | return true; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | private boolean isBlank(String value) { |
| | | return value == null || value.trim().isEmpty(); |
| | | } |
| | | |
| | | } |