Java源码示例:de.schlichtherle.license.LicenseContentException

示例1
/**
 * 校验生成证书的参数信息
 * @author zifangsky
 * @date 2018/5/2 15:43
 * @since 1.0.0
 * @param 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("用户类型不能为空");
    }
}
 
示例2
/**
 * 校验生成证书的参数信息
 * @author zifangsky
 * @date 2018/5/2 15:43
 * @since 1.0.0
 * @param 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("用户类型不能为空");
    }
}
 
示例3
@Override
protected synchronized void validate(LicenseContent content)
          throws LicenseContentException {
    // Call super validate firstly, will verify expired
    super.validate(content);

    // Verify the customized license parameters
    String extra = (String) content.getExtra();
    List<ExtraParam> extraParams;
    try {
        TypeReference<List<ExtraParam>> type;
        type = new TypeReference<List<ExtraParam>>() {};
        extraParams = MAPPER.readValue(extra, type);
    } catch (IOException e) {
        throw new RuntimeException("Failed to read extra params", e);
    }
    ExtraParam param = this.matchParam(this.serverId, extraParams);
    if (param == null) {
        throw newLicenseException("The current server's id '%s' " +
                                  "is not authorized");
    }
    if (this.usingGraphs() > param.graphs()) {
        throw newLicenseException("The using graphs exceeded '%s'" +
                                  "authorized limit '%s'",
                                  this.usingGraphs(), param.graphs());
    }
}
 
示例4
/**
 * 复写validate方法,增加IP地址、Mac地址等其他信息校验
 * @author zifangsky
 * @date 2018/4/23 10:40
 * @since 1.0.0
 * @param content LicenseContent
 */
@Override
protected synchronized void validate(final LicenseContent content)
        throws LicenseContentException {
    //1. 首先调用父类的validate方法
    super.validate(content);

    //2. 然后校验自定义的License参数
    //License中可被允许的参数信息
    LicenseCheckModel expectedCheckModel = (LicenseCheckModel) content.getExtra();
    //当前服务器真实的参数信息
    LicenseCheckModel 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("不能获取服务器硬件信息");
    }
}
 
示例5
/**
 * 复写validate方法,增加IP地址、Mac地址等其他信息校验
 * @author zifangsky
 * @date 2018/4/23 10:40
 * @since 1.0.0
 * @param content LicenseContent
 */
@Override
protected synchronized void validate(final LicenseContent content)
        throws LicenseContentException {
    //1. 首先调用父类的validate方法
    super.validate(content);

    //2. 然后校验自定义的License参数
    //License中可被允许的参数信息
    LicenseCheckModel expectedCheckModel = (LicenseCheckModel) content.getExtra();
    //当前服务器真实的参数信息
    LicenseCheckModel 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("不能获取服务器硬件信息");
    }
}
 
示例6
@Override
protected synchronized void validate(LicenseContent content)
                                     throws LicenseContentException {
    // Call super validate, expected to be overwritten
    super.validate(content);
}
 
示例7
protected synchronized void validateCreate(LicenseContent content)
                                           throws LicenseContentException {
    // Just call super validate is ok
    super.validate(content);
}
 
示例8
@Override
protected synchronized void validateCreate(LicenseContent content)
          throws LicenseContentException {
    super.validateCreate(content);
}
 
示例9
private LicenseContentException newLicenseException(String message,
                                                    Object... args) {
    return new LicenseContentException(String.format(message, args));
}