📝 修改密钥.

This commit is contained in:
lijiahang
2024-05-17 12:26:01 +08:00
parent c85ab97cc5
commit a9dd8f2f36
75 changed files with 163 additions and 163 deletions

View File

@@ -36,7 +36,7 @@ cd orion-visor
# MYSQL_PASSWORD mysql 用户密码
# MYSQL_ROOT_PASSWORD mysql root 密码
# REDIS_PASSWORD redis 密码
# SECRET_KEY 加密
# SECRET_KEY 加密
# 构建
docker compose build
```

View File

@@ -21,14 +21,14 @@
修改 `application.yaml` `app.exec-log.append-ansi``false`
> ##### 6. 为什么使用钥认证还是无法连接机器?
> ##### 6. 为什么使用钥认证还是无法连接机器?
```
# 升级 openssh
yum update openssh
sshd -v (我的版本: OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017)
# 生成钥时添加参数 -m PEM
# 生成钥时添加参数 -m PEM
ssh-keygen -t rsa -m PEM
chmod 700 ~/.ssh
chmod 700 ~/.ssh/authorized_keys

View File

@@ -14,7 +14,7 @@
<url>https://github.com/lijiahangmax/orion-visor</url>
<properties>
<revision>1.1.0</revision>
<revision>2.0.0</revision>
<spring.boot.version>2.7.17</spring.boot.version>
<spring.boot.admin.version>2.7.15</spring.boot.admin.version>
<flatten.maven.plugin.version>1.5.0</flatten.maven.plugin.version>

View File

@@ -14,7 +14,7 @@ public interface AppConst extends OrionConst {
/**
* 同 ${orion.version} 迭代时候需要手动更改
*/
String VERSION = "1.1.0";
String VERSION = "2.0.0";
String ORION_VISOR = "orion-visor";

View File

@@ -23,7 +23,7 @@ public interface ErrorMessage {
String DATA_ABSENT = "数据不存在";
String KEY_ABSENT = "主机钥不存在";
String KEY_ABSENT = "主机钥不存在";
String IDENTITY_ABSENT = "主机身份不存在";

View File

@@ -24,7 +24,7 @@ public abstract class CryptoProcessor<Config extends CryptoConfig> implements Va
}
/**
* 初始化
* 初始化
*/
protected abstract void initSecretKey();

View File

@@ -29,17 +29,17 @@ public class AesCryptoConfig extends CryptoConfig {
private PaddingMode paddingMode = PaddingMode.PKCS5_PADDING;
/**
* 加密
* 加密
*/
private String secretKey;
/**
* 是否生成
* 是否生成
*/
private boolean useGeneratorKey = true;
/**
* 生成的钥长度 128 192 256bytes
* 生成的钥长度 128 192 256bytes
*/
private int generatorKeyLength = CryptoConst.AES_KEY_LENGTH;

View File

@@ -40,7 +40,7 @@ public class AesCryptoProcessor extends CryptoProcessor<AesCryptoConfig> {
this.builder = SymmetricBuilder.aes()
.workingMode(config.getWorkingMode())
.paddingMode(config.getPaddingMode());
// 初始化
// 初始化
this.initSecretKey();
// 初始化参数规格
this.initParamSpec();
@@ -52,10 +52,10 @@ public class AesCryptoProcessor extends CryptoProcessor<AesCryptoConfig> {
protected void initSecretKey() {
SecretKey secretKey;
if (config.isUseGeneratorKey()) {
// 生成
// 生成
secretKey = Keys.generatorKey(config.getSecretKey(), config.getGeneratorKeyLength(), CipherAlgorithm.AES);
} else {
// 获取
// 获取
secretKey = Keys.getSecretKey(config.getSecretKey(), CipherAlgorithm.AES);
}
builder.secretKey(secretKey);

View File

@@ -55,18 +55,18 @@
{
"name": "orion.crypto.aes.secret-key",
"type": "java.lang.String",
"description": "加密钥."
"description": "加密钥."
},
{
"name": "orion.crypto.aes.use-generator-key",
"type": "java.lang.Boolean",
"description": "是否生成钥.",
"description": "是否生成钥.",
"defaultValue": "true"
},
{
"name": "orion.crypto.aes.generator-key-length",
"type": "java.lang.Integer",
"description": "生成的钥长度 128 192 256bytes.",
"description": "生成的钥长度 128 192 256bytes.",
"defaultValue": "128"
},
{

View File

@@ -46,7 +46,7 @@ orion:
mode: ROW
crypto:
aes:
# 加密
# 加密
secret-key: ${SECRET_KEY:uQeacXV8b3isvKLK}
async:
executor:

View File

@@ -263,7 +263,7 @@ orion:
enabled: true
working-mode: ECB
padding-mode: PKCS5_PADDING
# 加密
# 加密
secret-key: I66AndrKWrwXjtBL
use-generator-key: true
generator-key-length: 128

View File

@@ -2,7 +2,7 @@
GET {{baseUrl}}/asset/authorized-data/current-host
Authorization: {{token}}
### 查询当前用户已授权的主机
### 查询当前用户已授权的主机
GET {{baseUrl}}/asset/authorized-data/current-host-key
Authorization: {{token}}

View File

@@ -47,7 +47,7 @@ public class AssetAuthorizedDataServiceController {
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/current-host-key")
@Operation(summary = "查询当前用户已授权的主机")
@Operation(summary = "查询当前用户已授权的主机")
public List<HostKeyVO> getCurrentAuthorizedHostKey() {
return assetAuthorizedDataService.getUserAuthorizedHostKey(SecurityUtils.getLoginUserId());
}

View File

@@ -15,7 +15,7 @@ Authorization: {{token}}
GET {{baseUrl}}/asset/data-grant/get-host-group?userId=10
Authorization: {{token}}
### 主机钥授权
### 主机钥授权
PUT {{baseUrl}}/asset/data-grant/grant-host-key
Content-Type: application/json
Authorization: {{token}}
@@ -28,7 +28,7 @@ Authorization: {{token}}
]
}
### 获取已授权的主机
### 获取已授权的主机
GET {{baseUrl}}/asset/data-grant/get-host-key?userId=10
Authorization: {{token}}

View File

@@ -62,7 +62,7 @@ public class AssetDataGrantServiceController {
@OperatorLog(HostKeyOperatorType.GRANT)
@PutMapping("/grant-host-key")
@Operation(summary = "主机钥授权")
@Operation(summary = "主机钥授权")
@PreAuthorize("@ss.hasPermission('asset:host-key:grant')")
public Boolean grantHostKey(@RequestBody AssetDataGrantRequest request) {
assetDataGrantService.grantHostKey(request);
@@ -71,7 +71,7 @@ public class AssetDataGrantServiceController {
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get-host-key")
@Operation(summary = "获取已授权的主机")
@Operation(summary = "获取已授权的主机")
@PreAuthorize("@ss.hasPermission('asset:host-key:grant')")
public List<Long> getAuthorizedHostKey(AssetAuthorizedDataQueryRequest request) {
return assetAuthorizedDataService.getAuthorizedDataRelId(DataPermissionTypeEnum.HOST_KEY, request);

View File

@@ -1,4 +1,4 @@
### 创建主机
### 创建主机
POST {{baseUrl}}/asset/host-key/create
Content-Type: application/json
Authorization: {{token}}
@@ -11,7 +11,7 @@ Authorization: {{token}}
}
### 通过 id 更新主机
### 通过 id 更新主机
PUT {{baseUrl}}/asset/host-key/update
Content-Type: application/json
Authorization: {{token}}
@@ -25,11 +25,11 @@ Authorization: {{token}}
}
### 通过 id 查询主机
### 通过 id 查询主机
GET {{baseUrl}}/asset/host-key/get?id=1
Authorization: {{token}}
### 查询主机
### 查询主机
POST {{baseUrl}}/asset/host-key/list
Content-Type: application/json
Authorization: {{token}}
@@ -43,7 +43,7 @@ Authorization: {{token}}
}
### 分页查询主机
### 分页查询主机
POST {{baseUrl}}/asset/host-key/query
Content-Type: application/json
Authorization: {{token}}
@@ -59,7 +59,7 @@ Authorization: {{token}}
}
### 通过 id 删除主机
### 通过 id 删除主机
DELETE {{baseUrl}}/asset/host-key/delete?id=1
Authorization: {{token}}

View File

@@ -24,13 +24,13 @@ import javax.annotation.Resource;
import java.util.List;
/**
* 主机钥 api
* 主机钥 api
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023-9-20 11:55
*/
@Tag(name = "asset - 主机钥服务")
@Tag(name = "asset - 主机钥服务")
@Slf4j
@Validated
@RestWrapper
@@ -44,7 +44,7 @@ public class HostKeyController {
@OperatorLog(HostKeyOperatorType.CREATE)
@PostMapping("/create")
@Operation(summary = "创建主机")
@Operation(summary = "创建主机")
@PreAuthorize("@ss.hasPermission('asset:host-key:create')")
public Long createHostKey(@Validated @RequestBody HostKeyCreateRequest request) {
return hostKeyService.createHostKey(request);
@@ -52,7 +52,7 @@ public class HostKeyController {
@OperatorLog(HostKeyOperatorType.UPDATE)
@PutMapping("/update")
@Operation(summary = "通过 id 更新主机")
@Operation(summary = "通过 id 更新主机")
@PreAuthorize("@ss.hasPermission('asset:host-key:update')")
public Integer updateHostKey(@Validated @RequestBody HostKeyUpdateRequest request) {
return hostKeyService.updateHostKeyById(request);
@@ -60,7 +60,7 @@ public class HostKeyController {
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "查询主机钥详情")
@Operation(summary = "查询主机钥详情")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasAnyPermission('asset:host-key:query-detail', 'asset:host-key:update')")
public HostKeyVO getHostKey(@RequestParam("id") Long id) {
@@ -69,7 +69,7 @@ public class HostKeyController {
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/list")
@Operation(summary = "查询主机")
@Operation(summary = "查询主机")
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public List<HostKeyVO> getHostKeyList() {
return hostKeyService.getHostKeyList();
@@ -77,7 +77,7 @@ public class HostKeyController {
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询主机")
@Operation(summary = "分页查询主机")
@PreAuthorize("@ss.hasPermission('asset:host-key:query')")
public DataGrid<HostKeyVO> getHostKeyPage(@Validated(Page.class) @RequestBody HostKeyQueryRequest request) {
return hostKeyService.getHostKeyPage(request);
@@ -85,7 +85,7 @@ public class HostKeyController {
@OperatorLog(HostKeyOperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "通过 id 删除主机")
@Operation(summary = "通过 id 删除主机")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:host-key:delete')")
public Integer deleteHostKey(@RequestParam("id") Long id) {

View File

@@ -12,7 +12,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 主机钥 内部对象转换器
* 主机钥 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.0

View File

@@ -5,7 +5,7 @@ import com.orion.visor.module.asset.entity.domain.HostKeyDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 主机钥 Mapper 接口
* 主机钥 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.0

View File

@@ -28,7 +28,7 @@ public interface HostCacheKeyDefine {
CacheKeyDefine HOST_KEY = new CacheKeyBuilder()
.key("host:key:list")
.desc("主机钥列表")
.desc("主机钥列表")
.type(HostKeyCacheDTO.class)
.struct(RedisCacheStruct.HASH)
.timeout(8, TimeUnit.HOURS)

View File

@@ -8,7 +8,7 @@ import static com.orion.visor.framework.biz.operator.log.core.enums.OperatorRisk
import static com.orion.visor.framework.biz.operator.log.core.enums.OperatorRiskLevel.L;
/**
* 主机钥 操作日志类型
* 主机钥 操作日志类型
*
* @author Jiahang Li
* @version 1.0.0
@@ -28,10 +28,10 @@ public class HostKeyOperatorType extends InitializingOperatorTypes {
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(L, CREATE, "创建主机钥 <sb>${name}</sb>"),
new OperatorType(L, UPDATE, "修改主机钥 <sb>${name}</sb>"),
new OperatorType(H, DELETE, "删除主机钥 <sb>${name}</sb>"),
new OperatorType(H, GRANT, "将主机钥权限授予 <sb>${grantType}</sb> <sb>${grantName}</sb>"),
new OperatorType(L, CREATE, "创建主机钥 <sb>${name}</sb>"),
new OperatorType(L, UPDATE, "修改主机钥 <sb>${name}</sb>"),
new OperatorType(H, DELETE, "删除主机钥 <sb>${name}</sb>"),
new OperatorType(H, GRANT, "将主机钥权限授予 <sb>${grantType}</sb> <sb>${grantName}</sb>"),
};
}

View File

@@ -46,7 +46,7 @@ public class HostIdentityDO extends BaseDO {
@TableField("password")
private String password;
@Schema(description = "钥id")
@Schema(description = "钥id")
@TableField("key_id")
private Long keyId;

View File

@@ -9,7 +9,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 主机钥 实体对象
* 主机钥 实体对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -21,7 +21,7 @@ import lombok.*;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "host_key", autoResultMap = true)
@Schema(name = "HostKeyDO", description = "主机钥 实体对象")
@Schema(name = "HostKeyDO", description = "主机钥 实体对象")
public class HostKeyDO extends BaseDO {
private static final long serialVersionUID = 1L;

View File

@@ -35,7 +35,7 @@ public class HostIdentityCacheDTO implements LongCacheIdModel, Serializable {
@Schema(description = "用户名")
private String username;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
}

View File

@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 主机钥缓存
* 主机钥缓存
*
* @author Jiahang Li
* @version 1.0.0
@@ -20,7 +20,7 @@ import java.io.Serializable;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyCacheDTO", description = "主机钥缓存")
@Schema(name = "HostKeyCacheDTO", description = "主机钥缓存")
public class HostKeyCacheDTO implements LongCacheIdModel, Serializable {
@Schema(description = "id")

View File

@@ -63,7 +63,7 @@ public class HostTerminalConnectDTO {
@Schema(description = "密码")
private String password;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
@Desensitize(toEmpty = true)

View File

@@ -43,7 +43,7 @@ public class HostIdentityCreateRequest implements Serializable {
@Schema(description = "用户密码")
private String password;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
}

View File

@@ -43,7 +43,7 @@ public class HostIdentityQueryRequest extends PageRequest {
@Schema(description = "用户密码")
private String password;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
}

View File

@@ -48,7 +48,7 @@ public class HostIdentityUpdateRequest implements UpdatePasswordAction {
@Schema(description = "用户密码")
private String password;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
@Schema(description = "是否使用新密码")

View File

@@ -11,7 +11,7 @@ import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 主机钥 创建请求对象
* 主机钥 创建请求对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -21,7 +21,7 @@ import java.io.Serializable;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyCreateRequest", description = "主机钥 创建请求对象")
@Schema(name = "HostKeyCreateRequest", description = "主机钥 创建请求对象")
public class HostKeyCreateRequest implements Serializable {
@NotBlank

View File

@@ -7,7 +7,7 @@ import lombok.*;
import javax.validation.constraints.Size;
/**
* 主机钥 查询请求对象
* 主机钥 查询请求对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -18,7 +18,7 @@ import javax.validation.constraints.Size;
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "HostKeyQueryRequest", description = "主机钥 查询请求对象")
@Schema(name = "HostKeyQueryRequest", description = "主机钥 查询请求对象")
public class HostKeyQueryRequest extends PageRequest {
@Schema(description = "搜索")

View File

@@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* 主机钥 更新请求对象
* 主机钥 更新请求对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -22,7 +22,7 @@ import javax.validation.constraints.Size;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyUpdateRequest", description = "主机钥 更新请求对象")
@Schema(name = "HostKeyUpdateRequest", description = "主机钥 更新请求对象")
public class HostKeyUpdateRequest implements UpdatePasswordAction {
@NotNull

View File

@@ -12,7 +12,7 @@ import java.io.Serializable;
import java.util.List;
/**
* 主机钥 视图响应对象
* 主机钥 视图响应对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -22,7 +22,7 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostGroupTreeVO", description = "主机钥 视图响应对象")
@Schema(name = "HostGroupTreeVO", description = "主机钥 视图响应对象")
public class HostGroupTreeVO implements TreeNode<HostGroupTreeVO>, Serializable {
private static final long serialVersionUID = 1L;

View File

@@ -37,10 +37,10 @@ public class HostIdentityVO implements Serializable {
@Schema(description = "用户名")
private String username;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
@Schema(description = "钥名称")
@Schema(description = "钥名称")
private String keyName;
@Schema(description = "创建时间")

View File

@@ -10,7 +10,7 @@ import java.io.Serializable;
import java.util.Date;
/**
* 主机钥 视图响应对象
* 主机钥 视图响应对象
*
* @author Jiahang Li
* @version 1.0.0
@@ -20,7 +20,7 @@ import java.util.Date;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "HostKeyVO", description = "主机钥 视图响应对象")
@Schema(name = "HostKeyVO", description = "主机钥 视图响应对象")
public class HostKeyVO implements Serializable {
private static final long serialVersionUID = 1L;

View File

@@ -15,7 +15,7 @@ public enum HostExtraSshAuthTypeEnum {
DEFAULT,
/**
* 自定义钥验证
* 自定义钥验证
*/
CUSTOM_KEY,

View File

@@ -15,7 +15,7 @@ public enum HostIdentityTypeEnum {
PASSWORD,
/**
*
*
*/
KEY,

View File

@@ -15,7 +15,7 @@ public enum HostSshAuthTypeEnum {
PASSWORD,
/**
* 钥验证
* 钥验证
*/
KEY,

View File

@@ -52,7 +52,7 @@ public class HostSshConfigModel implements GenericsDataModel, UpdatePasswordActi
@Schema(description = "身份id")
private Long identityId;
@Schema(description = "钥id")
@Schema(description = "钥id")
private Long keyId;
@NotNull

View File

@@ -64,7 +64,7 @@ public class HostSshConfigStrategy implements MapDataStrategy<HostSshConfigModel
this.validCharset(model.getCharset());
this.validCharset(model.getFileNameCharset());
this.validCharset(model.getFileContentCharset());
// 检查主机钥是否存在
// 检查主机钥是否存在
Long keyId = model.getKeyId();
if (keyId != null) {
Valid.notNull(hostKeyDAO.selectById(keyId), ErrorMessage.KEY_ABSENT);

View File

@@ -27,7 +27,7 @@ public class HostSshExtraModel implements GenericsDataModel {
@Schema(description = "认证方式")
private String username;
@Schema(description = "主机")
@Schema(description = "主机")
private Long keyId;
@Schema(description = "主机身份")

View File

@@ -56,7 +56,7 @@ public class HostSshExtraStrategy implements MapDataStrategy<HostSshExtraModel>
} else if (HostExtraSshAuthTypeEnum.CUSTOM_IDENTITY.equals(authType)) {
Valid.notNull(identityId);
}
// 验证主机钥是否存在
// 验证主机钥是否存在
if (keyId != null) {
Valid.notNull(hostKeyDAO.selectById(keyId), ErrorMessage.KEY_ABSENT);
}
@@ -65,7 +65,7 @@ public class HostSshExtraStrategy implements MapDataStrategy<HostSshExtraModel>
Valid.notNull(hostIdentityDAO.selectById(identityId), ErrorMessage.IDENTITY_ABSENT);
}
Long userId = SecurityUtils.getLoginUserId();
// 验证主机钥是否有权限
// 验证主机钥是否有权限
if (keyId != null) {
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_KEY, userId, keyId),
ErrorMessage.ANY_NO_PERMISSION,

View File

@@ -54,7 +54,7 @@ public interface AssetAuthorizedDataService {
AuthorizedHostWrapperVO getUserAuthorizedHost(Long userId, String type);
/**
* 查询用户已授权的主机
* 查询用户已授权的主机
*
* @param userId userId
* @return key

View File

@@ -20,7 +20,7 @@ public interface AssetDataGrantService {
void grantHostGroup(AssetDataGrantRequest request);
/**
* 主机钥授权
* 主机钥授权
*
* @param request request
*/

View File

@@ -10,7 +10,7 @@ import com.orion.visor.module.asset.entity.vo.HostKeyVO;
import java.util.List;
/**
* 主机钥 服务类
* 主机钥 服务类
*
* @author Jiahang Li
* @version 1.0.0
@@ -19,7 +19,7 @@ import java.util.List;
public interface HostKeyService {
/**
* 创建主机
* 创建主机
*
* @param request request
* @return id
@@ -27,7 +27,7 @@ public interface HostKeyService {
Long createHostKey(HostKeyCreateRequest request);
/**
* 通过 id 更新主机
* 通过 id 更新主机
*
* @param request request
* @return effect
@@ -35,7 +35,7 @@ public interface HostKeyService {
Integer updateHostKeyById(HostKeyUpdateRequest request);
/**
* 通过 id 查询主机
* 通过 id 查询主机
*
* @param id id
* @return row
@@ -43,7 +43,7 @@ public interface HostKeyService {
HostKeyVO getHostKeyById(Long id);
/**
* 通过 id 查询主机
* 通过 id 查询主机
*
* @param id id
* @return row
@@ -51,14 +51,14 @@ public interface HostKeyService {
HostKeyDO getHostKey(Long id);
/**
* 查询主机
* 查询主机
*
* @return rows
*/
List<HostKeyVO> getHostKeyList();
/**
* 分页查询主机
* 分页查询主机
*
* @param request request
* @return rows
@@ -66,7 +66,7 @@ public interface HostKeyService {
DataGrid<HostKeyVO> getHostKeyPage(HostKeyQueryRequest request);
/**
* 通过 id 删除主机
* 通过 id 删除主机
*
* @param id id
* @return effect

View File

@@ -69,7 +69,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
@Override
public Long createHostIdentity(HostIdentityCreateRequest request) {
log.info("HostIdentityService-createHostIdentity request: {}", JSON.toJSONString(request));
// 检查钥是否存在
// 检查钥是否存在
this.checkCreateParams(request);
// 转换
HostIdentityDO record = HostIdentityConvert.MAPPER.to(request);
@@ -95,7 +95,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
HostIdentityTypeEnum type = Valid.valid(HostIdentityTypeEnum::of, request.getType());
if (HostIdentityTypeEnum.KEY.equals(type)) {
// 钥认证
// 钥认证
this.checkKeyId(request.getKeyId());
}
// 查询主机身份
@@ -162,7 +162,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
if (dataGrid.isEmpty()) {
return dataGrid;
}
// 设置钥名称
// 设置钥名称
List<Long> keyIdList = dataGrid.stream()
.filter(s -> HostIdentityTypeEnum.KEY.name().equals(s.getType()))
.map(HostIdentityVO::getKeyId)
@@ -170,7 +170,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
.distinct()
.collect(Collectors.toList());
if (!keyIdList.isEmpty()) {
// 查询钥名称
// 查询钥名称
Map<Long, String> keyNameMap = hostKeyDAO.selectBatchIds(keyIdList)
.stream()
.collect(Collectors.toMap(HostKeyDO::getId, HostKeyDO::getName));
@@ -234,7 +234,7 @@ public class HostIdentityServiceImpl implements HostIdentityService {
// 密码认证
Valid.notBlank(request.getPassword(), ErrorMessage.PARAM_MISSING);
} else if (HostIdentityTypeEnum.KEY.equals(type)) {
// 钥认证
// 钥认证
this.checkKeyId(request.getKeyId());
}
}

View File

@@ -36,7 +36,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* 主机钥 服务实现类
* 主机钥 服务实现类
*
* @author Jiahang Li
* @version 1.0.0
@@ -114,7 +114,7 @@ public class HostKeyServiceImpl implements HostKeyService {
// 查询
HostKeyDO record = hostKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 解密
// 解密
this.decryptKey(record);
// 转换
return HostKeyConvert.MAPPER.to(record);
@@ -124,7 +124,7 @@ public class HostKeyServiceImpl implements HostKeyService {
public HostKeyDO getHostKey(Long id) {
HostKeyDO record = hostKeyDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 解密
// 解密
this.decryptKey(record);
// 解密密码
String password = record.getPassword();
@@ -182,7 +182,7 @@ public class HostKeyServiceImpl implements HostKeyService {
hostIdentityDAO.setKeyWithNull(id);
// 删除主机配置
hostConfigDAO.setKeyIdWithNull(id);
// 删除主机钥额外配置
// 删除主机钥额外配置
dataExtraApi.deleteHostKeyExtra(id);
// 删除数据权限
dataPermissionApi.deleteByRelId(DataPermissionTypeEnum.HOST_KEY, id);

View File

@@ -150,7 +150,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
if (extra != null) {
HostExtraSshAuthTypeEnum extraAuthType = HostExtraSshAuthTypeEnum.of(extra.getAuthType());
if (HostExtraSshAuthTypeEnum.CUSTOM_KEY.equals(extraAuthType)) {
// 验证主机钥是否有权限
// 验证主机钥是否有权限
Valid.isTrue(dataPermissionApi.hasPermission(DataPermissionTypeEnum.HOST_KEY, userId, extra.getKeyId()),
ErrorMessage.ANY_NO_PERMISSION,
DataPermissionTypeEnum.HOST_KEY.getPermissionName());
@@ -183,9 +183,9 @@ public class HostTerminalServiceImpl implements HostTerminalService {
try {
SessionHolder sessionHolder = new SessionHolder();
final boolean useKey = conn.getKeyId() != null;
// 使用钥认证
// 使用钥认证
if (useKey) {
// 加载
// 加载
String publicKey = Optional.ofNullable(conn.getPublicKey())
.map(CryptoUtils::decryptAsString)
.orElse(null);
@@ -254,7 +254,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
.map(HostExtraSshAuthTypeEnum::of)
.orElse(null);
if (HostExtraSshAuthTypeEnum.CUSTOM_KEY.equals(extraAuthType)) {
// 自定义
// 自定义
config.setAuthType(HostSshAuthTypeEnum.KEY.name());
config.setKeyId(extra.getKeyId());
if (extra.getUsername() != null) {
@@ -279,7 +279,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
authType = HostSshAuthTypeEnum.PASSWORD;
config.setPassword(identity.getPassword());
} else if (HostIdentityTypeEnum.KEY.equals(identityType)) {
// 钥类型
// 钥类型
authType = HostSshAuthTypeEnum.KEY;
config.setKeyId(identity.getKeyId());
}
@@ -291,7 +291,7 @@ public class HostTerminalServiceImpl implements HostTerminalService {
// 密码认证
conn.setPassword(config.getPassword());
} else if (HostSshAuthTypeEnum.KEY.equals(authType)) {
// 钥认证
// 钥认证
Long keyId = config.getKeyId();
HostKeyDO key = hostKeyDAO.selectById(keyId);
Valid.notNull(key, ErrorMessage.KEY_ABSENT);

View File

@@ -139,7 +139,7 @@ public interface DataExtraApi {
Integer deleteByRelId(DataExtraTypeEnum type, Long relId);
/**
* 删除主机
* 删除主机
*
* @param keyId keyId
* @return effect

View File

@@ -20,9 +20,9 @@ public enum DataPermissionTypeEnum {
HOST_GROUP(true, "主机分组"),
/**
* 主机
* 主机
*/
HOST_KEY(true, "主机"),
HOST_KEY(true, "主机"),
/**
* 主机身份

View File

@@ -43,7 +43,7 @@ public interface DataExtraDAO extends IMapper<DataExtraDO> {
}
/**
* 删除主机
* 删除主机
*
* @param keyId keyId
* @return effect

View File

@@ -22,7 +22,7 @@ export function getCurrentAuthorizedHost(type: string) {
}
/**
* 查询当前用户已授权的主机
* 查询当前用户已授权的主机
*/
export function getCurrentAuthorizedHostKey() {
return axios.get<Array<HostKeyQueryResponse>>('/asset/authorized-data/current-host-key');

View File

@@ -32,14 +32,14 @@ export function getAuthorizedHostGroup(params: AssetAuthorizedDataQueryRequest)
}
/**
* 主机钥授权
* 主机钥授权
*/
export function grantHostKey(request: AssetDataGrantRequest) {
return axios.put('/asset/data-grant/grant-host-key', request);
}
/**
* 获取已授权的主机
* 获取已授权的主机
*/
export function getAuthorizedHostKey(params: AssetAuthorizedDataQueryRequest) {
return axios.get<Array<number>>('/asset/data-grant/get-host-key', { params });

View File

@@ -3,7 +3,7 @@ import type { TableData } from '@arco-design/web-vue/es/table/interface';
import axios from 'axios';
/**
* 主机钥创建请求
* 主机钥创建请求
*/
export interface HostKeyCreateRequest {
name?: string;
@@ -13,7 +13,7 @@ export interface HostKeyCreateRequest {
}
/**
* 主机钥更新请求
* 主机钥更新请求
*/
export interface HostKeyUpdateRequest extends HostKeyCreateRequest {
id?: number;
@@ -21,7 +21,7 @@ export interface HostKeyUpdateRequest extends HostKeyCreateRequest {
}
/**
* 主机钥查询请求
* 主机钥查询请求
*/
export interface HostKeyQueryRequest extends Pagination {
searchValue?: string;
@@ -32,7 +32,7 @@ export interface HostKeyQueryRequest extends Pagination {
}
/**
* 主机钥查询响应
* 主机钥查询响应
*/
export interface HostKeyQueryResponse extends TableData {
id: number;
@@ -45,42 +45,42 @@ export interface HostKeyQueryResponse extends TableData {
}
/**
* 创建主机
* 创建主机
*/
export function createHostKey(request: HostKeyCreateRequest) {
return axios.post('/asset/host-key/create', request);
}
/**
* 通过 id 更新主机
* 通过 id 更新主机
*/
export function updateHostKey(request: HostKeyUpdateRequest) {
return axios.put('/asset/host-key/update', request);
}
/**
* 通过 id 查询主机
* 通过 id 查询主机
*/
export function getHostKey(id: number) {
return axios.get<HostKeyQueryResponse>('/asset/host-key/get', { params: { id } });
}
/**
* 查询主机
* 查询主机
*/
export function getHostKeyList() {
return axios.get<Array<HostKeyQueryResponse>>('/asset/host-key/list');
}
/**
* 分页查询主机
* 分页查询主机
*/
export function getHostKeyPage(request: HostKeyQueryRequest) {
return axios.post<DataGrid<HostKeyQueryResponse>>('/asset/host-key/query', request);
}
/**
* 通过 id 删除主机
* 通过 id 删除主机
*/
export function deleteHostKey(id: number) {
return axios.delete('/asset/host-key/delete', { params: { id } });

View File

@@ -123,7 +123,7 @@
options: [{ value: 'table', label: '表格' }, { value: 'card', label: '卡片' }]
},
{
name: '主机钥',
name: '主机钥',
key: 'hostKeyView',
type: 'radio-group',
margin: '0 0 4px 0',

View File

@@ -2,7 +2,7 @@
<a-select v-model:model-value="value"
:options="optionData"
:loading="loading"
placeholder="请选择主机钥"
placeholder="请选择主机钥"
allow-clear />
</template>

View File

@@ -86,7 +86,7 @@ export default defineStore('cache', {
return await this.load('hosts', getHostList, force);
},
// 获取主机钥列表
// 获取主机钥列表
async loadHostKeys(force = false) {
return await this.load('hostKeys', getHostKeyList, force);
},
@@ -106,7 +106,7 @@ export default defineStore('cache', {
return await this.load(`${type}_Tags`, () => getTagList(type), force);
},
// 获取已授权的主机钥列表
// 获取已授权的主机钥列表
async loadAuthorizedHostKeys(force = false) {
return await this.load('authorizedHostKeys', getCurrentAuthorizedHostKey, force);
},

View File

@@ -23,15 +23,15 @@
{{ getDictValue(identityTypeKey, record.type) }}
</a-tag>
</template>
<!-- 钥名称 -->
<!-- 钥名称 -->
<template #keyId="{ record }">
<!-- -->
<!-- -->
<template v-if="record.keyId && record.type === 'KEY'">
<a-tag color="arcoblue" v-if="record.keyId">
{{ hostKeys.find(s => s.id === record.keyId)?.name }}
</a-tag>
</template>
<!-- -->
<!-- -->
<template v-else>
<span>-</span>
</template>
@@ -137,9 +137,9 @@
}
});
// 初始化钥数据
// 初始化钥数据
onMounted(async () => {
// 加载主机
// 加载主机
hostKeys.value = await cacheStore.loadHostKeys();
});

View File

@@ -5,7 +5,7 @@
@grant="doGrant"
@select-all="selectAll"
@reverse="reverseSelect">
<!-- 主机钥表格 -->
<!-- 主机钥表格 -->
<a-table row-key="id"
class="host-key-main-table"
:columns="hostKeyColumns"

View File

@@ -11,9 +11,9 @@ export const GrantKey = {
HOST_GROUP_ROLE: 1,
// 主机分组-用户
HOST_GROUP_USER: 2,
// 主机钥-角色
// 主机钥-角色
HOST_KEY_ROLE: 3,
// 主机钥-用户
// 主机钥-用户
HOST_KEY_USER: 4,
// 主机身份-角色
HOST_IDENTITY_ROLE: 5,
@@ -46,14 +46,14 @@ export const GrantTabs = [
}, {
key: GrantKey.HOST_KEY_ROLE,
permission: ['asset:host-key:grant'],
title: '主机钥授权 - 角色',
title: '主机钥授权 - 角色',
icon: 'icon-lock',
type: GrantType.ROLE,
component: HostKeyGrant
}, {
key: GrantKey.HOST_KEY_USER,
permission: ['asset:host-key:grant'],
title: '主机钥授权 - 用户',
title: '主机钥授权 - 用户',
icon: 'icon-lock',
type: GrantType.USER,
component: HostKeyGrant

View File

@@ -1,7 +1,7 @@
import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
import { dateFormat } from '@/utils';
// 主机钥列
// 主机钥列
export const hostKeyColumns = [
{
title: 'id',
@@ -64,7 +64,7 @@ export const hostIdentityColumns = [
ellipsis: true,
tooltip: true
}, {
title: '主机钥',
title: '主机钥',
dataIndex: 'keyId',
slotName: 'keyId',
}, {

View File

@@ -64,8 +64,8 @@
<a-form-item field="username" label="用户名">
<a-input v-model="formModel.username" placeholder="请输入用户名" allow-clear />
</a-form-item>
<!-- -->
<a-form-item field="keyId" label="钥">
<!-- -->
<a-form-item field="keyId" label="钥">
<host-key-selector v-model="formModel.keyId" allow-clear />
</a-form-item>
</a-form>
@@ -86,9 +86,9 @@
{{ record.username }}
</span>
</template>
<!-- 钥名称 -->
<!-- 钥名称 -->
<template #keyId="{ record }">
<!-- -->
<!-- -->
<template v-if="record.keyId && record.type === IdentityType.KEY">
<!-- 可查看详情 -->
<a-tooltip v-if="hasAnyPermission(['asset:host-key:detail', 'asset:host-key:update'])"
@@ -104,7 +104,7 @@
{{ record.keyName }}
</a-tag>
</template>
<!-- -->
<!-- -->
<template v-else>
<span>-</span>
</template>

View File

@@ -49,10 +49,10 @@
checked-text="使用新密码"
unchecked-text="使用原密码" />
</a-form-item>
<!-- 主机 -->
<!-- 主机 -->
<a-form-item v-if="formModel.type === IdentityType.KEY"
field="keyId"
label="主机钥">
label="主机钥">
<host-key-selector v-model="formModel.keyId" />
</a-form-item>
</a-form>

View File

@@ -28,8 +28,8 @@
<a-form-item field="username" label="用户名">
<a-input v-model="formModel.username" placeholder="请输入用户名" allow-clear />
</a-form-item>
<!-- 主机 -->
<a-form-item field="keyId" label="主机钥">
<!-- 主机 -->
<a-form-item field="keyId" label="主机钥">
<host-key-selector v-model="formModel.keyId" allow-clear />
</a-form-item>
</query-header>
@@ -99,9 +99,9 @@
{{ record.username }}
</span>
</template>
<!-- 钥名称 -->
<!-- 钥名称 -->
<template #keyId="{ record }">
<!-- 有钥 -->
<!-- 有钥 -->
<template v-if="record.keyId && record.type === IdentityType.KEY">
<!-- 可查看详情 -->
<a-tooltip v-if="hasAnyPermission(['asset:host-key:detail', 'asset:host-key:update'])"
@@ -117,7 +117,7 @@
{{ record.keyName }}
</a-tag>
</template>
<!-- 无钥 -->
<!-- 无钥 -->
<template v-else>
<span>-</span>
</template>

View File

@@ -16,7 +16,7 @@
<host-identity-form-modal ref="modal"
@added="modalAddCallback"
@updated="modalUpdateCallback" />
<!-- 主机钥抽屉 -->
<!-- 主机钥抽屉 -->
<host-key-form-drawer ref="keyDrawer" />
</div>
</template>

View File

@@ -19,7 +19,7 @@ const fieldConfig = {
slotName: 'username',
ellipsis: true,
}, {
label: '主机钥',
label: '主机钥',
dataIndex: 'keyId',
slotName: 'keyId',
height: '24px',

View File

@@ -15,7 +15,7 @@ export const type = [{
export const keyId = [{
required: true,
message: '请选择钥'
message: '请选择钥'
}] as FieldRule[];
export const username = [{

View File

@@ -25,7 +25,7 @@ const columns = [
dataIndex: 'username',
slotName: 'username',
}, {
title: '主机钥',
title: '主机钥',
dataIndex: 'keyId',
slotName: 'keyId',
}, {

View File

@@ -10,7 +10,7 @@
@cancel="handleClose">
<a-spin class="full modal-form-small" :loading="loading">
<a-alert class="keygen-alert">
请使用 ssh-keygen -m PEM -t rsa 生成
请使用 ssh-keygen -m PEM -t rsa 生成
</a-alert>
<a-form :model="formModel"
ref="formRef"
@@ -119,7 +119,7 @@
// 打开新增
const openAdd = () => {
title.value = '添加主机钥';
title.value = '添加主机钥';
isAddHandle.value = true;
isViewHandler.value = false;
renderForm({ ...defaultForm() });
@@ -128,7 +128,7 @@
// 打开修改
const openUpdate = async (record: any) => {
title.value = '修改主机钥';
title.value = '修改主机钥';
isAddHandle.value = false;
isViewHandler.value = false;
await render(record.id);
@@ -136,7 +136,7 @@
// 打开查看
const openView = async (record: any) => {
title.value = '主机钥';
title.value = '主机钥';
isAddHandle.value = false;
isViewHandler.value = true;
await render(record.id);

View File

@@ -26,7 +26,7 @@
<div class="table-left-bar-handle">
<!-- 标题 -->
<div class="table-title">
钥列表
钥列表
</div>
</div>
<!-- 右侧操作 -->

View File

@@ -69,10 +69,10 @@
checked-text="使用新密码"
unchecked-text="使用原密码" />
</a-form-item>
<!-- 主机钥 -->
<!-- 主机钥 -->
<a-form-item v-if="SshAuthType.KEY === formModel.authType"
field="keyId"
label="主机"
label="主机"
:hide-asterisk="true">
<host-key-selector v-model="formModel.keyId" />
</a-form-item>

View File

@@ -19,7 +19,7 @@ export interface HostSshConfig {
export const SshAuthType = {
// 密码验证
PASSWORD: 'PASSWORD',
// 钥验证
// 钥验证
KEY: 'KEY',
// 身份验证
IDENTITY: 'IDENTITY'

View File

@@ -22,7 +22,7 @@ export const authType = [{
export const keyId = [{
required: true,
message: '请选择主机钥'
message: '请选择主机钥'
}] as FieldRule[];
export const identityId = [{

View File

@@ -16,11 +16,11 @@
label="用户名">
<a-input v-model="formModel.username" placeholder="请输入用户名" />
</a-form-item>
<!-- 主机 -->
<!-- 主机 -->
<a-form-item v-if="formModel.authType === ExtraSshAuthType.CUSTOM_KEY"
field="keyId"
label="主机钥"
:rules="{ required: true, message: '请选择主机钥' }">
label="主机钥"
:rules="{ required: true, message: '请选择主机钥' }">
<host-key-selector v-model="formModel.keyId"
:authorized="true" />
</a-form-item>

View File

@@ -64,7 +64,7 @@ export const ExtraSettingItems = {
export const ExtraSshAuthType = {
// 使用默认认证方式
DEFAULT: 'DEFAULT',
// 自定义
// 自定义
CUSTOM_KEY: 'CUSTOM_KEY',
// 自定义身份
CUSTOM_IDENTITY: 'CUSTOM_IDENTITY',