Browse Source

fixed encryption

zero 1 năm trước cách đây
mục cha
commit
52d497dc22

+ 2 - 0
PCS/src/main/java/cn/cslg/permission/common/model/dto/EncryptionFunctionDTO.java

@@ -22,5 +22,7 @@ public class EncryptionFunctionDTO {
      */
     private Long currentTimeMillis;
 
+    private String version;
+
     private List<String> permissions;
 }

+ 2 - 1
PCS/src/main/java/cn/cslg/permission/common/utils/ResponseEnum.java

@@ -29,7 +29,8 @@ public enum ResponseEnum {
     THE_REQUEST_TIME_OVERTIME(500, "请求时间超时"),
     THE_SIGN_IS_NOT_SAME(500, "请求SIGN不一致,重新检查"),
     THE_MACHINE_CODE_IS_NULL(500, "机器码不可为空"),
-    DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT(500, "同一账号新机登录不可超过两个");
+    DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT(500, "同一账号新机登录不可超过两个"),
+    THE_VERSION_IS_NULL(500, "版本号不可为空");
 
 
     private Integer code;

+ 6 - 0
PCS/src/main/java/cn/cslg/permission/domain/associate/AssoFunctionModule.java

@@ -36,4 +36,10 @@ public class AssoFunctionModule extends BaseEntity<AssoFunctionModule> {
      */
     @TableField(value = "AUTH_TYPE")
     private Integer authType;
+
+    /**
+     * 版本号
+     */
+    @TableField(value = "VERSION")
+    private String version;
 }

+ 9 - 4
PCS/src/main/java/cn/cslg/permission/service/LoginService.java

@@ -455,6 +455,10 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
     public String functionByEncryption(EncryptionFunctionDTO vo) throws Exception {
         String sign = vo.getSign();
         String appKey = vo.getAppKey();
+        String version = vo.getVersion();
+        if (Boolean.TRUE.equals(StringUtils.isEmpty(version))){
+            return Response.error(ResponseEnum.THE_VERSION_IS_NULL);
+        }
         long currentTimeMillis = vo.getCurrentTimeMillis() / 1000;
         long currentTimeSecond = System.currentTimeMillis() / 1000;
         long second = currentTimeSecond - currentTimeMillis;
@@ -487,7 +491,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
                 permissions.add(i.getFunctionPath());
             });
         }
-        List<EncryptionFunctionVO> list = this.loadFunctionVOS(permissions, 2, symmetryKey);
+        List<EncryptionFunctionVO> list = this.loadFunctionVOS(permissions, 2, symmetryKey,version);
         functionVOS.addAll(list);
 
         List<String> permissions1 = new ArrayList<>();
@@ -498,7 +502,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
             permissions1.add(i.getFunctionPath());
         });
         permissions1.removeAll(permissions);
-        List<EncryptionFunctionVO> list1 = this.loadFunctionVOS(permissions1, 1, symmetryKey);
+        List<EncryptionFunctionVO> list1 = this.loadFunctionVOS(permissions1, 1, symmetryKey,version);
         functionVOS.addAll(list1);
         finalVO.setFunctionVOS(functionVOS);
         String key = RSAUtils.encryptByPublicKey(symmetryKey, publicKey);
@@ -506,7 +510,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
         return Response.success(finalVO);
     }
 
-    private List<EncryptionFunctionVO> loadFunctionVOS(List<String> permissions, Integer type, String symmetryKey) throws Exception {
+    private List<EncryptionFunctionVO> loadFunctionVOS(List<String> permissions, Integer type, String symmetryKey, String version) throws Exception {
         List<EncryptionFunctionVO> functionVOS = new ArrayList<>();
         List<Function> functions = functionMapper.selectList(new LambdaQueryWrapper<Function>()
                 .in(Function::getFunctionPath, permissions));
@@ -515,7 +519,8 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
             String functionPath = function.getFunctionPath();
             AssoFunctionModule functionModule = assoFunctionModuleMapper.selectOne(new LambdaQueryWrapper<AssoFunctionModule>()
                     .eq(AssoFunctionModule::getFunctionId, functionId)
-                    .eq(AssoFunctionModule::getAuthType, type));
+                    .eq(AssoFunctionModule::getAuthType, type)
+                    .eq(AssoFunctionModule::getVersion, version));
             if (ObjectUtils.isNotEmpty(functionModule) && StringUtils.isNotEmpty(functionModule.getCode())) {
                 String moduleCode = functionModule.getCode();
                 String encryptInfo = AESUtils.encrypt(moduleCode, symmetryKey);

+ 3 - 1
PCS/src/test/java/cn/cslg/permission/EncryptionPersonTest.java

@@ -29,7 +29,8 @@ public class EncryptionPersonTest {
         vo.setUsername("gaochangkui-qy");
         vo.setPassword("Xiaoshi221101*");
         vo.setAppKey("4e95e3d926a2a4befa5d913acc0aa9f5");
-        vo.setMachineCode("BDACEARQ1241241");
+//        vo.setMachineCode("BDACEARQ1241241");
+        vo.setMachineCode("BFEBFBFF000A0654");
         final long timeMillis = System.currentTimeMillis();
         vo.setCurrentTimeMillis(timeMillis);
         String appSecret = vo.getAppKey() + timeMillis / 1000;
@@ -48,6 +49,7 @@ public class EncryptionPersonTest {
         functionDTO.setAppKey("4e95e3d926a2a4befa5d913acc0aa9f5");
         functionDTO.setCurrentTimeMillis(timeMillis);
         functionDTO.setSign(md5Sign);
+        functionDTO.setVersion("1");
         final String function = loginService.functionByEncryption(functionDTO);
         System.out.println(function);
     }