Browse Source

私有化部署:增加默认管理员检查序列码的逻辑

tangxiangan 1 year ago
parent
commit
71f334e431

+ 1 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppDeviceServiceImpl.java

@@ -361,6 +361,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
             LicenseCodesVO licenseCodesVO = licenseCodes.get(0);
             Products products = productService.getById(licenseCodesVO.getProductId());
             deviceResVO.setProduct_code(products.getCode());
+            deviceResVO.setCdkey(licenseCodesVO.getCdkey());
         }
         ActivationVO activationVO = new ActivationVO();
         activationVO.setDevice(deviceResVO);

+ 16 - 4
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/task/LicenseTask.java

@@ -10,6 +10,7 @@ import cn.kdan.pdf.tech.core.service.VppDeviceService;
 import cn.kdan.pdf.tech.core.service.VppLicenseCodeService;
 import com.alibaba.fastjson.JSON;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -19,20 +20,21 @@ import org.springframework.util.StringUtils;
 import java.util.ArrayList;
 import java.util.List;
 
+@Slf4j
 @Component
 @RequiredArgsConstructor
 public class LicenseTask {
     private  final VppLicenseCodeService licenseCodeService;
     private final VppDeviceService vppDeviceService;
     private final SubscriptionService subscriptionService;
-    @Scheduled(fixedRate = 3 * 60 * 60 * 1000) // 每3小时执行一次
+    @Scheduled(fixedRate = 3 * 60 * 1000) // 每3小时执行一次
     public void handleLicenseCode() {
         List<LicenseCodes> licenseCodes = licenseCodeService.listActive();
         //已处理过过期的订阅id
         List<String> list = new ArrayList<>();
         //验证序列码有效性
         //如果过期时间小于当前时间,则置为过期,并且修改订阅状态,序列码状态,设备状态
-        licenseCodes.stream().filter(licenseCode -> licenseCode.getAssignedDate() != null).forEach(licenseCode -> {
+        licenseCodes.stream().filter(licenseCode -> licenseCode.getEndUpAt() != null).forEach(licenseCode -> {
             verifySign(licenseCode);
             if (licenseCode.getEndUpAt().getTime() < System.currentTimeMillis()) {
                 //过期序列码置为过期
@@ -40,6 +42,7 @@ public class LicenseTask {
                 expiredLicenseCode.setId(licenseCode.getId());
                 expiredLicenseCode.setValidFlag(LicenseCodeStatusEnum.EXPIRED.code());
                 licenseCodeService.update(expiredLicenseCode);
+                log.error("序列码证时间过期,序列码id:{},过期", licenseCode.getId());
                 if (!StringUtils.isEmpty(licenseCode.getSubscriptionId()) && !list.contains(licenseCode.getSubscriptionId())) {
                     Subscriptions subscriptions = new Subscriptions();
                     subscriptions.setId(licenseCode.getSubscriptionId());
@@ -59,15 +62,24 @@ public class LicenseTask {
         String sign = licenseCode.getSign();
         VppPrivateDeployment deployment = new VppPrivateDeployment();
         BeanUtils.copyProperties(licenseCode, deployment);
-        //将对象转化为json
-        String deploymentJson = JSON.toJSONString(deployment) + "vpp_private_deployment";
+        String deploymentJson =  deployment.toJSON() + "vpp_private_deployment";
         //对上述json进行MD5加密并且和sign对比
         String signOriginal = DigestUtils.md5Hex(deploymentJson);
         if (!signOriginal.equals(sign)) {
+            log.error("序列码验证失败,序列码id:{},过期,json {}", licenseCode.getId(),deploymentJson);
             LicenseCodes expiredLicenseCode = new LicenseCodes();
             expiredLicenseCode.setId(licenseCode.getId());
             expiredLicenseCode.setValidFlag(LicenseCodeStatusEnum.EXPIRED.code());
             licenseCodeService.update(expiredLicenseCode);
         }
     }
+
+    public static void main(String[] args) {
+        String json = " {\"subscription_id\":\"25a14781-e096-3b04-95a5-558b90ed5d6c\",\"cdkey\":\"3AD4-C1BB-79FD-DED8\",\"times\":1,\"product_id\":15,\"end_up_at\":\"2024-01-26 03:12:29\"}vpp_private_deployment";
+        String signOriginal = DigestUtils.md5Hex(json);
+        String sign = "435fa3fb33eb0c24b433b51fcc072ead";
+        if (!signOriginal.equals(sign)) {
+
+        }
+    }
 }

+ 2 - 0
pdf-tech-core/src/main/resources/sqlmap/ext/ExtVppLicenseCodeMapper.xml

@@ -33,6 +33,7 @@
         <result column="assigned_date" jdbcType="TIMESTAMP" property="assignedDate" />
         <result column="activated_date" jdbcType="TIMESTAMP" property="activatedDate" />
         <result column="is_vpp" jdbcType="SMALLINT" property="isVpp" />
+        <result column="sign" jdbcType="VARCHAR" property="sign" />
     </resultMap>
     <resultMap id="InfoResultMap" type="cn.kdan.pdf.tech.core.pojo.vo.LicenseCodesVO">
         <id column="id" jdbcType="OTHER" property="id" />
@@ -176,6 +177,7 @@
         valid_flag,
         assigned_date,
         activated_date,
+        sign,
         is_vpp
         from license_codes
         WHERE valid_flag not in