1
13693261870
2025-01-14 042eb4875c91a38b19f160bf68fb658552f7e7bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.se.system.service;
 
import com.se.system.domain.vo.LicenseExtraParamVo;
import com.se.system.service.inte.IACustomVerifyListener;
 
@SuppressWarnings("ALL")
public class CustomVerifyListenerService extends IACustomVerifyListener {
    /**
     * 单例Bean,这个静态变量会缓存证书中最大用户注册数的
     */
    private static Long registerAmount = 0L;
 
    @Override
    public boolean verify(LicenseExtraParamVo licenseExtra) {
        registerAmount = null == licenseExtra.getRegisterAmount() ? 0 : licenseExtra.getRegisterAmount();
        System.out.println("======= 自定义证书验证监听器A 实现verify方法  =======");
        System.out.println("证书最大验证人数是:" + registerAmount);
        /**
         * 这里,可以做一些和业务系统有关的参数验证
         * 在这个业务系统这个监听方法中,我们可以先去user表查询下,当前系统的注册用户数量
         * 然后拿着这个数量和lic参数中约束的最大注册用户量进行比较,如果>,则抛出异常
         * 这样做的目的是防止业务系统部署到客户端本地服务器上时,数据库是公开的,防止对方通过手动改表来添加用户
         */
        long count = 1001;
        if (count >= registerAmount) {
            System.out.println("系统当前用户数超过最大用户注册限制数【" + registerAmount + "】");
        }
 
        System.out.println("系统注册最大用户数量未超过" + count + ",验证用过!");
        return true;
    }
 
    /**
     * 这个单独的重载的验证方法,主要是用于业务系统中进行调用,带参数的verify方法用于注解
     * 而这个不带参数的verify,更加灵活些,比如在系统中注册接口(Controller)上,除了自身@VLicense注解外,
     * 可以在调用这个方法,来额外的验证注册人数是否已满
     *
     * @return
     * @throws
     */
    public boolean verify() {
        Long count = 100L;
        if (count.equals(registerAmount)) {
            System.out.println("系统当前用户数已达到最大用户注册限制数【" + registerAmount + "】,无法再注册新用户。如需扩充用户注册的数量,请联系我们重新购买License!");
        }
        return true;
    }
}