修改密码更新逻辑.

This commit is contained in:
lijiahang
2023-09-20 18:23:28 +08:00
parent d29cdac130
commit 6c8ccb3864
16 changed files with 176 additions and 41 deletions

View File

@@ -58,7 +58,7 @@ public class HostKeyController {
@GetMapping("/get")
@Operation(summary = "查询主机秘钥详情")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:detail')")
@PreAuthorize("@ss.hasAnyPermission('asset:host-key:detail', 'asset:host-key:update')")
public HostKeyVO getHostKey(@RequestParam("id") Long id) {
return hostKeyService.getHostKeyById(id);
}

View File

@@ -47,4 +47,7 @@ public class HostKeyUpdateRequest implements Serializable {
@Schema(description = "密码")
private String password;
@Schema(description = "是否使用新密码")
private Boolean useNewPassword;
}

View File

@@ -3,6 +3,7 @@ package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Booleans;
import com.orion.lang.utils.Strings;
import com.orion.ops.framework.common.constant.Const;
import com.orion.ops.framework.common.constant.ErrorMessage;
@@ -72,9 +73,16 @@ public class HostKeyServiceImpl implements HostKeyService {
HostKeyDO updateRecord = HostKeyConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkHostKeyPresent(updateRecord);
String password = updateRecord.getPassword();
if (!Strings.isBlank(password)) {
updateRecord.setPassword(CryptoUtils.encryptAsString(password));
if (Booleans.isTrue(request.getUseNewPassword())) {
// 使用新密码
String password = updateRecord.getPassword();
if (Strings.isBlank(password)) {
updateRecord.setPassword(Const.EMPTY);
} else {
updateRecord.setPassword(CryptoUtils.encryptAsString(password));
}
} else {
updateRecord.setPassword(null);
}
// 更新
int effect = hostKeyDAO.updateById(updateRecord);
@@ -101,7 +109,7 @@ public class HostKeyServiceImpl implements HostKeyService {
HostKeyDO record = hostKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
String password = record.getPassword();
if (password != null) {
if (!Strings.isBlank(password)) {
record.setPassword(CryptoUtils.decryptAsString(password));
}
return record;