|
@@ -342,7 +342,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
- public String loginByEncryption(EncryptionLoginDTO vo) {
|
|
|
+ public String loginByEncryption(EncryptionLoginDTO vo) throws Exception {
|
|
|
final String username = vo.getUsername();
|
|
|
final String password = vo.getPassword();
|
|
|
String machineCode = vo.getMachineCode();
|
|
@@ -379,7 +379,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
return Response.error(ResponseEnum.PASSWORD_ERROR);
|
|
|
}
|
|
|
//人员信息中私钥或公钥为空则添加进去
|
|
|
- updatePersonnel(personnel.getPrivateKey(), personnel.getPublicKey(), personId);
|
|
|
+ updatePersonnel(personnel.getPrivateKey(), personnel.getPublicKey(), personnel.getSymmetryKey(), personId);
|
|
|
|
|
|
personnel = personnelMapper.selectById(personnel.getId());
|
|
|
List<AssoPersonnelMachine> machineList = assoPersonnelMachineMapper.selectList(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
@@ -404,14 +404,16 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
return Response.success(loginVO);
|
|
|
}
|
|
|
|
|
|
- public void updatePersonnel(String privateKey, String publicKey, Integer personId) {
|
|
|
- if (StringUtils.isEmpty(privateKey) || StringUtils.isEmpty(publicKey)) {
|
|
|
+ public void updatePersonnel(String privateKey, String publicKey, String symmetryKey, Integer personId) throws Exception {
|
|
|
+ if (StringUtils.isEmpty(privateKey) || StringUtils.isEmpty(publicKey) || StringUtils.isEmpty(symmetryKey)) {
|
|
|
Map<String, String> map = RSAUtils.generateKey();
|
|
|
String publicKeyStr = map.get("publicKeyStr");
|
|
|
String privateKeyStr = map.get("privateKeyStr");
|
|
|
+ String generateKey = AESUtils.generateKey();
|
|
|
Personnel newPersonnel = personnelMapper.selectById(personId);
|
|
|
newPersonnel.setPrivateKey(privateKeyStr);
|
|
|
newPersonnel.setPublicKey(publicKeyStr);
|
|
|
+ newPersonnel.setSymmetryKey(generateKey);
|
|
|
newPersonnel.updateById();
|
|
|
}
|
|
|
}
|
|
@@ -470,6 +472,8 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
return Response.error(ResponseEnum.THE_TOKEN_IS_INVALID);
|
|
|
}
|
|
|
String publicKey = personnel.getPublicKey();
|
|
|
+ String symmetryKey = personnel.getSymmetryKey();
|
|
|
+ EncryptionFunctionFinalVO finalVO = new EncryptionFunctionFinalVO();
|
|
|
List<EncryptionFunctionVO> functionVOS = new ArrayList<>();
|
|
|
|
|
|
List<String> permissions = new ArrayList<>();
|
|
@@ -483,7 +487,7 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
permissions.add(i.getFunctionPath());
|
|
|
});
|
|
|
}
|
|
|
- List<EncryptionFunctionVO> list = this.loadFunctionVOS(permissions, 2, publicKey);
|
|
|
+ List<EncryptionFunctionVO> list = this.loadFunctionVOS(permissions, 2, symmetryKey);
|
|
|
functionVOS.addAll(list);
|
|
|
|
|
|
List<String> permissions1 = new ArrayList<>();
|
|
@@ -494,12 +498,15 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
permissions1.add(i.getFunctionPath());
|
|
|
});
|
|
|
permissions1.removeAll(permissions);
|
|
|
- List<EncryptionFunctionVO> list1 = this.loadFunctionVOS(permissions1, 1, publicKey);
|
|
|
+ List<EncryptionFunctionVO> list1 = this.loadFunctionVOS(permissions1, 1, symmetryKey);
|
|
|
functionVOS.addAll(list1);
|
|
|
- return Response.success(functionVOS);
|
|
|
+ finalVO.setFunctionVOS(functionVOS);
|
|
|
+ String key = RSAUtils.encryptByPublicKey(symmetryKey, publicKey);
|
|
|
+ finalVO.setKey(key);
|
|
|
+ return Response.success(finalVO);
|
|
|
}
|
|
|
|
|
|
- private List<EncryptionFunctionVO> loadFunctionVOS(List<String> permissions, Integer type, String publicKey) throws Exception {
|
|
|
+ private List<EncryptionFunctionVO> loadFunctionVOS(List<String> permissions, Integer type, String symmetryKey) throws Exception {
|
|
|
List<EncryptionFunctionVO> functionVOS = new ArrayList<>();
|
|
|
List<Function> functions = functionMapper.selectList(new LambdaQueryWrapper<Function>()
|
|
|
.in(Function::getFunctionPath, permissions));
|
|
@@ -511,7 +518,8 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
.eq(AssoFunctionModule::getAuthType, type));
|
|
|
if (ObjectUtils.isNotEmpty(functionModule) && StringUtils.isNotEmpty(functionModule.getCode())) {
|
|
|
String moduleCode = functionModule.getCode();
|
|
|
- String encryptInfo = RSAUtils.encryptByPublicKey(moduleCode, publicKey);
|
|
|
+// String encryptInfo = RSAUtils.encryptByPublicKey(moduleCode, publicKey);
|
|
|
+ String encryptInfo = AESUtils.encrypt(moduleCode, symmetryKey);
|
|
|
EncryptionFunctionVO functionVO = new EncryptionFunctionVO();
|
|
|
functionVO.setPermission(functionPath);
|
|
|
functionVO.setEncryptionModuleCode(encryptInfo);
|