yin преди 6 месеца
родител
ревизия
19302b6b9d

+ 13 - 13
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/service/impl/SystemCache.java

@@ -77,11 +77,7 @@ public class SystemCache {
             JSONObject json = AppLicenseUtil.parseLicense(ByteArray.fromBase64(s.getDescription()).value());
             this.parseJson(json);
         } else {
-            Auth = false;
-            doubleTrack = false;
-            groupDeleteWarn = false;
-            yjsObjectiveEnable = false;
-            trialMode = TrialMode.SHARE;
+            this.reset();
         }
         fileServer = configService.findByType(ConfigType.FILE_SERVER);
         markTime = Long.parseLong(configService.findByType(ConfigType.MARK_TIME));
@@ -200,8 +196,8 @@ public class SystemCache {
             if (json.has("control") && json.getJSONObject("control").has("custom")
                     && json.getJSONObject("control").getJSONObject("custom").has("trial_mode")) {
                 try {
-                    this.trialMode = TrialMode.findByName(json.getJSONObject("control").getJSONObject("custom")
-                            .getString("trial_mode"));
+                    this.trialMode = TrialMode
+                            .findByName(json.getJSONObject("control").getJSONObject("custom").getString("trial_mode"));
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
@@ -218,13 +214,17 @@ public class SystemCache {
                 }
             }
         } else {
-            Auth = false;
-            doubleTrack = false;
-            groupDeleteWarn = false;
-            yjsObjectiveEnable = false;
-            expireTime = null;
-            trialMode = TrialMode.SHARE;
+            this.reset();
         }
     }
 
+    public void reset() {
+        Auth = false;
+        doubleTrack = false;
+        groupDeleteWarn = false;
+        yjsObjectiveEnable = false;
+        expireTime = null;
+        trialMode = TrialMode.SHARE;
+    }
+
 }

+ 65 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/ukey/DeviceInfo.java

@@ -0,0 +1,65 @@
+package cn.com.qmth.stmms.biz.config.ukey;
+
+public class DeviceInfo {
+
+    private String developer_id;
+
+    private String sn;
+
+    private String type;
+
+    private String host_name;
+
+    private String lm;
+
+    private LockInfo lock_info;
+
+    public String getDeveloper_id() {
+        return developer_id;
+    }
+
+    public void setDeveloper_id(String developer_id) {
+        this.developer_id = developer_id;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getHost_name() {
+        return host_name;
+    }
+
+    public void setHost_name(String host_name) {
+        this.host_name = host_name;
+    }
+
+    public String getLm() {
+        return lm;
+    }
+
+    public void setLm(String lm) {
+        this.lm = lm;
+    }
+
+    public LockInfo getLock_info() {
+        return lock_info;
+    }
+
+    public void setLock_info(LockInfo lock_info) {
+        this.lock_info = lock_info;
+    }
+
+}

+ 175 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/ukey/LicenseInfo.java

@@ -0,0 +1,175 @@
+package cn.com.qmth.stmms.biz.config.ukey;
+
+public class LicenseInfo {
+
+    private Long license_id;
+
+    private Boolean enable;
+
+    private String guid;
+
+    private Long start_time;
+
+    private Long end_time;
+
+    private String concurrent_type;
+
+    private Long concurrent;
+
+    private Long version;
+
+    private String module;
+
+    private Long last_update_timestamp;
+
+    private Long last_update_timesn;
+
+    private Long rom_size;
+
+    private Long raw_size;
+
+    private Long pub_size;
+
+    private String developer_id;
+
+    private String type;
+
+    private String sn;
+
+    public Long getLicense_id() {
+        return license_id;
+    }
+
+    public void setLicense_id(Long license_id) {
+        this.license_id = license_id;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getGuid() {
+        return guid;
+    }
+
+    public void setGuid(String guid) {
+        this.guid = guid;
+    }
+
+    public Long getStart_time() {
+        return start_time;
+    }
+
+    public void setStart_time(Long start_time) {
+        this.start_time = start_time;
+    }
+
+    public Long getEnd_time() {
+        return end_time;
+    }
+
+    public void setEnd_time(Long end_time) {
+        this.end_time = end_time;
+    }
+
+    public String getConcurrent_type() {
+        return concurrent_type;
+    }
+
+    public void setConcurrent_type(String concurrent_type) {
+        this.concurrent_type = concurrent_type;
+    }
+
+    public Long getConcurrent() {
+        return concurrent;
+    }
+
+    public void setConcurrent(Long concurrent) {
+        this.concurrent = concurrent;
+    }
+
+    public Long getVersion() {
+        return version;
+    }
+
+    public void setVersion(Long version) {
+        this.version = version;
+    }
+
+    public String getModule() {
+        return module;
+    }
+
+    public void setModule(String module) {
+        this.module = module;
+    }
+
+    public Long getLast_update_timestamp() {
+        return last_update_timestamp;
+    }
+
+    public void setLast_update_timestamp(Long last_update_timestamp) {
+        this.last_update_timestamp = last_update_timestamp;
+    }
+
+    public Long getLast_update_timesn() {
+        return last_update_timesn;
+    }
+
+    public void setLast_update_timesn(Long last_update_timesn) {
+        this.last_update_timesn = last_update_timesn;
+    }
+
+    public Long getRom_size() {
+        return rom_size;
+    }
+
+    public void setRom_size(Long rom_size) {
+        this.rom_size = rom_size;
+    }
+
+    public Long getRaw_size() {
+        return raw_size;
+    }
+
+    public void setRaw_size(Long raw_size) {
+        this.raw_size = raw_size;
+    }
+
+    public Long getPub_size() {
+        return pub_size;
+    }
+
+    public void setPub_size(Long pub_size) {
+        this.pub_size = pub_size;
+    }
+
+    public String getDeveloper_id() {
+        return developer_id;
+    }
+
+    public void setDeveloper_id(String developer_id) {
+        this.developer_id = developer_id;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getSn() {
+        return sn;
+    }
+
+    public void setSn(String sn) {
+        this.sn = sn;
+    }
+
+}

+ 165 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/ukey/LockInfo.java

@@ -0,0 +1,165 @@
+package cn.com.qmth.stmms.biz.config.ukey;
+
+public class LockInfo {
+
+    private Long clock;
+
+    private Long available_space;
+
+    private Long total_space;
+
+    private Long communication_protocol;
+
+    private String lock_firmware_version;
+
+    private String lm_firmware_version;
+
+    private Long h5_device_type;
+
+    private Long clock_type;
+
+    private String device_model;
+
+    private String hardware_version;
+
+    private String manufacture_date;
+
+    private String lock_sn;
+
+    private Long slave_addr;
+
+    private String shell_num;
+
+    private String user_info;
+
+    private String inner_info;
+
+    public Long getClock() {
+        return clock;
+    }
+
+    public void setClock(Long clock) {
+        this.clock = clock;
+    }
+
+    public Long getAvailable_space() {
+        return available_space;
+    }
+
+    public void setAvailable_space(Long available_space) {
+        this.available_space = available_space;
+    }
+
+    public Long getTotal_space() {
+        return total_space;
+    }
+
+    public void setTotal_space(Long total_space) {
+        this.total_space = total_space;
+    }
+
+    public Long getCommunication_protocol() {
+        return communication_protocol;
+    }
+
+    public void setCommunication_protocol(Long communication_protocol) {
+        this.communication_protocol = communication_protocol;
+    }
+
+    public String getLock_firmware_version() {
+        return lock_firmware_version;
+    }
+
+    public void setLock_firmware_version(String lock_firmware_version) {
+        this.lock_firmware_version = lock_firmware_version;
+    }
+
+    public String getLm_firmware_version() {
+        return lm_firmware_version;
+    }
+
+    public void setLm_firmware_version(String lm_firmware_version) {
+        this.lm_firmware_version = lm_firmware_version;
+    }
+
+    public Long getH5_device_type() {
+        return h5_device_type;
+    }
+
+    public void setH5_device_type(Long h5_device_type) {
+        this.h5_device_type = h5_device_type;
+    }
+
+    public Long getClock_type() {
+        return clock_type;
+    }
+
+    public void setClock_type(Long clock_type) {
+        this.clock_type = clock_type;
+    }
+
+    public String getDevice_model() {
+        return device_model;
+    }
+
+    public void setDevice_model(String device_model) {
+        this.device_model = device_model;
+    }
+
+    public String getHardware_version() {
+        return hardware_version;
+    }
+
+    public void setHardware_version(String hardware_version) {
+        this.hardware_version = hardware_version;
+    }
+
+    public String getManufacture_date() {
+        return manufacture_date;
+    }
+
+    public void setManufacture_date(String manufacture_date) {
+        this.manufacture_date = manufacture_date;
+    }
+
+    public String getLock_sn() {
+        return lock_sn;
+    }
+
+    public void setLock_sn(String lock_sn) {
+        this.lock_sn = lock_sn;
+    }
+
+    public Long getSlave_addr() {
+        return slave_addr;
+    }
+
+    public void setSlave_addr(Long slave_addr) {
+        this.slave_addr = slave_addr;
+    }
+
+    public String getShell_num() {
+        return shell_num;
+    }
+
+    public void setShell_num(String shell_num) {
+        this.shell_num = shell_num;
+    }
+
+    public String getUser_info() {
+        return user_info;
+    }
+
+    public void setUser_info(String user_info) {
+        this.user_info = user_info;
+    }
+
+    public String getInner_info() {
+        return inner_info;
+    }
+
+    public void setInner_info(String inner_info) {
+        this.inner_info = inner_info;
+    }
+
+}

+ 169 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/ukey/UKeyHelper.java

@@ -0,0 +1,169 @@
+package cn.com.qmth.stmms.biz.config.ukey;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import net.sf.json.JsonConfig;
+
+import com.senseyun.openapi.SSRuntimeEasyJava.ErrorCode;
+import com.senseyun.openapi.SSRuntimeEasyJava.SSRuntimeEasy;
+
+import java.util.List;
+
+/**
+ * U盾工具类
+ */
+public class UKeyHelper {
+
+    private final static long Language = 2;// 语言ID:中文=1、英语=2
+
+    public static boolean UKEY_STATUS = false;
+
+    public static String UKEY_MESSAGE = "U盾环境正在初始化";
+
+    /**
+     * U盾环境初始化
+     */
+    public static void slmInitEasy(String apiPsd) throws Exception {
+        long result = SSRuntimeEasy.SlmInitEasy(apiPsd);
+        if (result != ErrorCode.SS_OK) {
+            SSRuntimeEasy.SlmErrorFormatEasy(result, Language);
+            // log.warn("SlmInitEasy Fail! {}", msg);
+            throw new Exception("U盾环境初始化失败");
+        }
+
+        // log.info("SlmInitEasy Success!");
+    }
+
+    /**
+     * U盾环境清理释放
+     */
+    public static void slmCleanupEasy() {
+        long result = SSRuntimeEasy.SlmCleanupEasy();
+        SSRuntimeEasy.SlmErrorFormatEasy(result, Language);
+        // log.info("SlmCleanupEasy {}", msg);
+    }
+
+    /**
+     * 释放分配的堆区域
+     */
+    public static void slmFreeEasy(Object obj) {
+        SSRuntimeEasy.SlmFreeEasy(obj);
+    }
+
+    /**
+     * 获取到当前计算机上所有插入的加密锁
+     */
+    public static List<DeviceInfo> slmEnumDeviceEasy() throws Exception {
+        Object obj = SSRuntimeEasy.SlmEnumDeviceEasy();
+        long result = SSRuntimeEasy.SlmGetLastError();
+        if (result != ErrorCode.SS_OK) {
+            SSRuntimeEasy.SlmErrorFormatEasy(result, Language);
+            // log.warn("SlmEnumDeviceEasy Fail! {}", msg);
+            throw new Exception("获取U盾信息失败");
+        }
+        JSONArray array = JSONArray.fromObject(obj.toString());
+        List<DeviceInfo> list = JSONArray.toList(array, new DeviceInfo(), new JsonConfig());
+        return list;
+    }
+
+    /**
+     * 获取加密锁中的所有许可ID数组
+     */
+    public static List<Long> slmEnumLicenseIDEasy(String deviceInfo) throws Exception {
+        Object obj = SSRuntimeEasy.SlmEnumLicenseIDEasy(deviceInfo);
+        long result = SSRuntimeEasy.SlmGetLastError();
+        if (result != ErrorCode.SS_OK) {
+            SSRuntimeEasy.SlmErrorFormatEasy(result, Language);
+            // log.warn("SlmEnumLicenseIDEasy Fail! {}", msg);
+            throw new Exception("获取U盾许可信息失败");
+        }
+        JSONArray array = JSONArray.fromObject(obj.toString());
+        List<Long> list = JSONArray.toList(array,Long.class, new JsonConfig());
+        return list;
+    }
+
+    /**
+     * 获取许可的详细信息
+     */
+    public static LicenseInfo slmGetLicenseInfoEasy(String deviceInfo, Long licenseId) throws Exception {
+        Object obj = SSRuntimeEasy.SlmGetLicenseInfoEasy(deviceInfo, licenseId);
+        long result = SSRuntimeEasy.SlmGetLastError();
+        if (result != ErrorCode.SS_OK) {
+            SSRuntimeEasy.SlmErrorFormatEasy(result, Language);
+            // log.warn("SlmGetLicenseInfoEasy Fail! {}", msg);
+            throw new Exception("获取U盾许可信息失败");
+        }
+        JSONObject json = JSONObject.fromObject(obj.toString());
+        LicenseInfo list = (LicenseInfo) JSONObject.toBean(json,new JsonConfig());
+        return list;
+    }
+
+    /**
+     * U盾许可验证
+     */
+    public static boolean verifyUKey(Long curLicenseId) throws Exception {
+        List<DeviceInfo> devices = UKeyHelper.slmEnumDeviceEasy();
+        if (devices==null || devices.isEmpty()) {
+            throw new Exception("未检测到U盾设备");
+        }
+
+
+        // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        for (DeviceInfo device : devices) {
+            String deviceJson = JSONObject.fromObject(device).toString();
+            // System.out.println(deviceJson);
+
+            List<Long> licenseIds = slmEnumLicenseIDEasy(deviceJson);
+            if (licenseIds==null || licenseIds.isEmpty()) {
+                throw new Exception("获取U盾许可信息失败");
+            }
+
+            for (Long licenseId : licenseIds) {
+                // System.out.println("licenseId:" + licenseId);
+
+                if (!licenseId.equals(curLicenseId)) {
+                    // 跳过不匹配的许可信息
+                    continue;
+                }
+
+                LicenseInfo license = slmGetLicenseInfoEasy(deviceJson, licenseId);
+                // System.out.println(jsonMapper.toJson(license));
+
+                LockInfo lock = device.getLock_info();
+                if (lock == null || license.getStart_time() == null || license.getEnd_time() == null) {
+                    continue;
+                }
+
+                boolean status = lock.getClock() >= license.getStart_time() && lock.getClock() <= license.getEnd_time();
+                // Date startTime = new Date(license.getStart_time() * 1000L);
+                // Date endTime = new Date(license.getEnd_time() * 1000L);
+
+                // log.info("licenseId:{} 许可开始时间:{} 许可结束时间:{} 状态:{}",
+                // licenseId, sdf.format(startTime), sdf.format(endTime), status ? "正常可用" :
+                // "已过期");
+
+                slmFreeEasy(license);
+                return status;
+            }
+
+            slmFreeEasy(licenseIds);
+        }
+
+        slmFreeEasy(devices);
+        return false;
+    }
+
+    public static void main(String arg[]) throws Exception {
+        try {
+//            System.setProperty("java.library.path", "/Users/yin/Desktop/API/mac/Java/lib64/libSSRuntimeEasyJava.dylib");
+
+            UKeyHelper.slmInitEasy("3266297f8519bc7e8107ac0871dd4915");
+
+            UKeyHelper.verifyUKey(100000002L);
+        } finally {
+            UKeyHelper.slmCleanupEasy();
+        }
+    }
+
+}

+ 39 - 0
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/config/ukey/UKeyJob.java

@@ -0,0 +1,39 @@
+package cn.com.qmth.stmms.biz.config.ukey;
+
+import cn.com.qmth.stmms.biz.config.service.impl.SystemCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+@Component
+public class UKeyJob {
+
+	@Autowired
+	private SystemCache systemCache;
+
+	@Value("${qmth.ukey.api.psd}")
+	private String ukeyApiPsd;
+
+	@Value("${qmth.ukey.license.id}")
+	private Long ukeyLicenseId;
+
+	@Scheduled(fixedDelay = 1 * 1000, initialDelay = 5 * 1000)
+	public void run() {
+		try {
+			UKeyHelper.slmInitEasy(ukeyApiPsd);
+			UKeyHelper.UKEY_STATUS = UKeyHelper.verifyUKey(ukeyLicenseId);
+			UKeyHelper.UKEY_MESSAGE = UKeyHelper.UKEY_STATUS ? "U盾许可认证成功" : "U盾许可认证失败";
+			if(!UKeyHelper.UKEY_STATUS){
+				systemCache.reset();
+			}
+		} catch (Exception e) {
+			UKeyHelper.UKEY_STATUS = false;
+			UKeyHelper.UKEY_MESSAGE = "U盾许可认证异常";
+			systemCache.reset();
+		} finally {
+			UKeyHelper.slmCleanupEasy();
+		}
+	}
+
+}

BIN
stmms-biz/src/main/resources/SSRuntimeEasyJava.jar