diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/CnConst.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/CnConst.java new file mode 100644 index 00000000..2b920765 --- /dev/null +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/CnConst.java @@ -0,0 +1,16 @@ +package com.orion.ops.framework.common.constant; + +/** + * 常量 - 中文 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/11/30 21:00 + */ +public interface CnConst { + + String CN_USER = "用户"; + + String CN_ROLE = "角色"; + +} diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java index e558e140..310b86ff 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/constant/Const.java @@ -7,7 +7,7 @@ package com.orion.ops.framework.common.constant; * @version 1.0.0 * @since 2023/6/23 18:49 */ -public interface Const extends com.orion.lang.constant.Const, FieldConst { +public interface Const extends com.orion.lang.constant.Const, FieldConst, CnConst { Integer NOT_DELETE = 0; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java b/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java index 3e753b0b..bba01da4 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-biz-operator-log/src/main/java/com/orion/ops/framework/biz/operator/log/core/constant/OperatorLogKeys.java @@ -23,4 +23,8 @@ public interface OperatorLogKeys extends FieldConst { String POSITION_NAME = "positionName"; + String GRANT_TYPE = "grantType"; + + String GRANT_NAME = "grantName"; + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.http index e1a9e1f1..a5661043 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.http +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.http @@ -1,9 +1,12 @@ -### 查询已授权的主机分组 -GET {{baseUrl}}/asset/authorized-data/host-group +### 查询当前用户已授权的主机分组及主机 +GET {{baseUrl}}/asset/authorized-data/current-host-group Authorization: {{token}} - -### 获取已授权的分组 -GET {{baseUrl}}/asset/authorized-data/get-authorized-group?userId=1 +### 查询当前用户已授权的主机秘钥 +GET {{baseUrl}}/asset/authorized-data/current-host-key +Authorization: {{token}} + +### 查询当前用户已授权的主机身份 +GET {{baseUrl}}/asset/authorized-data/current-host-identity Authorization: {{token}} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.java index e61c2ac1..635ba537 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetAuthorizedDataServiceController.java @@ -4,13 +4,13 @@ import com.orion.ops.framework.log.core.annotation.IgnoreLog; import com.orion.ops.framework.log.core.enums.IgnoreLogMode; import com.orion.ops.framework.security.core.utils.SecurityUtils; import com.orion.ops.framework.web.core.annotation.RestWrapper; -import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataRequest; -import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO; +import com.orion.ops.module.asset.entity.vo.AuthorizedHostGroupWrapperVO; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; +import com.orion.ops.module.asset.entity.vo.HostKeyVO; import com.orion.ops.module.asset.service.AssetAuthorizedDataService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,26 +34,28 @@ import java.util.List; @RequestMapping("/asset/authorized-data") public class AssetAuthorizedDataServiceController { - // FIXME 字典 菜单 http api - - @Resource private AssetAuthorizedDataService assetAuthorizedDataService; @IgnoreLog(IgnoreLogMode.RET) - @GetMapping("/host-group") - @Operation(summary = "查询已授权的主机分组") - public List getAuthorizedHostGroup() { + @GetMapping("/current-host-group") + @Operation(summary = "查询当前用户已授权的主机分组及主机") + public AuthorizedHostGroupWrapperVO getCurrentAuthorizedHostGroup() { return assetAuthorizedDataService.getUserAuthorizedHostGroup(SecurityUtils.getLoginUserId()); } @IgnoreLog(IgnoreLogMode.RET) - @GetMapping("/get-host-group") - @Operation(summary = "获取已授权的分组") - @PreAuthorize("@ss.hasPermission('asset:host-group:grant')") - public List getAuthorizedHostGroup(AssetAuthorizedDataRequest request) { - return assetAuthorizedDataService.getAuthorizedData(request); + @GetMapping("/current-host-key") + @Operation(summary = "查询当前用户已授权的主机秘钥") + public List getCurrentAuthorizedHostKey() { + return assetAuthorizedDataService.getUserAuthorizedHostKey(SecurityUtils.getLoginUserId()); } + @IgnoreLog(IgnoreLogMode.RET) + @GetMapping("/current-host-identity") + @Operation(summary = "查询当前用户已授权的主机身份") + public List getCurrentAuthorizedHostIdentity() { + return assetAuthorizedDataService.getUserAuthorizedHostIdentity(SecurityUtils.getLoginUserId()); + } } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.http index b7312ec0..08ebeadf 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.http +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.http @@ -1,5 +1,5 @@ ### 主机分组授权 -PUT {{baseUrl}}/asset/data-grant/host-group +PUT {{baseUrl}}/asset/data-grant/grant-host-group Content-Type: application/json Authorization: {{token}} @@ -11,21 +11,29 @@ Authorization: {{token}} ] } +### 获取已授权的主机分组 +GET {{baseUrl}}/asset/data-grant/get-host-group?userId=10 +Authorization: {{token}} + ### 主机秘钥授权 -PUT {{baseUrl}}/asset/data-grant/host-key +PUT {{baseUrl}}/asset/data-grant/grant-host-key Content-Type: application/json Authorization: {{token}} { "userId": 10, "idList": [ - 3, - 5 + 2, + 3 ] } +### 获取已授权的主机秘钥 +GET {{baseUrl}}/asset/data-grant/get-host-key?userId=10 +Authorization: {{token}} + ### 主机身份授权 -PUT {{baseUrl}}/asset/data-grant/host-identity +PUT {{baseUrl}}/asset/data-grant/grant-host-identity Content-Type: application/json Authorization: {{token}} @@ -36,3 +44,7 @@ Authorization: {{token}} 5 ] } + +### 获取已授权的主机身份 +GET {{baseUrl}}/asset/data-grant/get-host-identity?userId=10 +Authorization: {{token}} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.java index ae913862..456f596a 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/AssetDataGrantServiceController.java @@ -2,23 +2,26 @@ package com.orion.ops.module.asset.controller; import com.orion.lang.define.wrapper.HttpWrapper; import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog; +import com.orion.ops.framework.log.core.annotation.IgnoreLog; +import com.orion.ops.framework.log.core.enums.IgnoreLogMode; import com.orion.ops.framework.web.core.annotation.RestWrapper; import com.orion.ops.module.asset.define.operator.HostGroupOperatorType; import com.orion.ops.module.asset.define.operator.HostIdentityOperatorType; import com.orion.ops.module.asset.define.operator.HostKeyOperatorType; +import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataQueryRequest; import com.orion.ops.module.asset.entity.request.asset.AssetDataGrantRequest; +import com.orion.ops.module.asset.service.AssetAuthorizedDataService; import com.orion.ops.module.asset.service.AssetDataGrantService; +import com.orion.ops.module.infra.enums.DataPermissionTypeEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; /** * 资产模块 授权数据服务 @@ -35,13 +38,14 @@ import javax.annotation.Resource; @RequestMapping("/asset/data-grant") public class AssetDataGrantServiceController { - // FIXME 字典 菜单 http 前端api - @Resource private AssetDataGrantService assetDataGrantService; + @Resource + private AssetAuthorizedDataService assetAuthorizedDataService; + @OperatorLog(HostGroupOperatorType.GRANT) - @PutMapping("/host-group") + @PutMapping("/grant-host-group") @Operation(summary = "主机分组授权") @PreAuthorize("@ss.hasPermission('asset:host-group:grant')") public HttpWrapper grantHostGroup(@RequestBody AssetDataGrantRequest request) { @@ -49,8 +53,16 @@ public class AssetDataGrantServiceController { return HttpWrapper.ok(); } + @IgnoreLog(IgnoreLogMode.RET) + @GetMapping("/get-host-group") + @Operation(summary = "获取已授权的主机分组") + @PreAuthorize("@ss.hasPermission('asset:host-group:grant')") + public List getAuthorizedHostGroup(AssetAuthorizedDataQueryRequest request) { + return assetAuthorizedDataService.getAuthorizedDataRelId(DataPermissionTypeEnum.HOST_GROUP, request); + } + @OperatorLog(HostKeyOperatorType.GRANT) - @PutMapping("/host-key") + @PutMapping("/grant-host-key") @Operation(summary = "主机秘钥授权") @PreAuthorize("@ss.hasPermission('asset:host-key:grant')") public HttpWrapper grantHostKey(@RequestBody AssetDataGrantRequest request) { @@ -58,8 +70,16 @@ public class AssetDataGrantServiceController { return HttpWrapper.ok(); } + @IgnoreLog(IgnoreLogMode.RET) + @GetMapping("/get-host-key") + @Operation(summary = "获取已授权的主机秘钥") + @PreAuthorize("@ss.hasPermission('asset:host-key:grant')") + public List getAuthorizedHostKey(AssetAuthorizedDataQueryRequest request) { + return assetAuthorizedDataService.getAuthorizedDataRelId(DataPermissionTypeEnum.HOST_KEY, request); + } + @OperatorLog(HostIdentityOperatorType.GRANT) - @PutMapping("/host-identity") + @PutMapping("/grant-host-identity") @Operation(summary = "主机身份授权") @PreAuthorize("@ss.hasPermission('asset:host-identity:grant')") public HttpWrapper grantHostIdentity(@RequestBody AssetDataGrantRequest request) { @@ -67,4 +87,12 @@ public class AssetDataGrantServiceController { return HttpWrapper.ok(); } + @IgnoreLog(IgnoreLogMode.RET) + @GetMapping("/get-host-identity") + @Operation(summary = "获取已授权的主机身份") + @PreAuthorize("@ss.hasPermission('asset:host-identity:grant')") + public List getAuthorizedHostIdentity(AssetAuthorizedDataQueryRequest request) { + return assetAuthorizedDataService.getAuthorizedDataRelId(DataPermissionTypeEnum.HOST_IDENTITY, request); + } + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostGroupOperatorType.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostGroupOperatorType.java index e9f201bb..26538b45 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostGroupOperatorType.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostGroupOperatorType.java @@ -36,7 +36,7 @@ public class HostGroupOperatorType extends InitializingOperatorTypes { new OperatorType(L, MOVE, "移动主机分组 ${source}${target}(${position})"), new OperatorType(H, DELETE, "删除主机分组 ${groupName}"), new OperatorType(M, UPDATE_REL, "修改分组内主机 ${groupName}"), - new OperatorType(H, GRANT, "将主机分组权限授予 ${type} ${name}"), + new OperatorType(H, GRANT, "将主机分组权限授予 ${grantType} ${grantName}"), }; } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostIdentityOperatorType.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostIdentityOperatorType.java index 169a34ae..a57f22f0 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostIdentityOperatorType.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostIdentityOperatorType.java @@ -31,7 +31,7 @@ public class HostIdentityOperatorType extends InitializingOperatorTypes { new OperatorType(L, CREATE, "创建主机身份 ${name}"), new OperatorType(L, UPDATE, "修改主机身份 ${name}"), new OperatorType(H, DELETE, "删除主机身份 ${name}"), - new OperatorType(H, GRANT, "将主机身份权限授予 ${type} ${name}"), + new OperatorType(H, GRANT, "将主机身份权限授予 ${grantType} ${grantName}"), }; } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostKeyOperatorType.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostKeyOperatorType.java index e1c75023..46b7e3e7 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostKeyOperatorType.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/operator/HostKeyOperatorType.java @@ -31,7 +31,7 @@ public class HostKeyOperatorType extends InitializingOperatorTypes { new OperatorType(L, CREATE, "创建主机秘钥 ${name}"), new OperatorType(L, UPDATE, "修改主机秘钥 ${name}"), new OperatorType(H, DELETE, "删除主机秘钥 ${name}"), - new OperatorType(H, GRANT, "将主机秘钥权限授予 ${type} ${name}"), + new OperatorType(H, GRANT, "将主机秘钥权限授予 ${grantType} ${grantName}"), }; } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataQueryRequest.java similarity index 75% rename from orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataRequest.java rename to orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataQueryRequest.java index 886b6c79..3d75b182 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/asset/AssetAuthorizedDataQueryRequest.java @@ -19,8 +19,8 @@ import java.io.Serializable; @Builder @NoArgsConstructor @AllArgsConstructor -@Schema(name = "AssetAuthorizedDataRequest", description = "授权资产数据 查询请求对象") -public class AssetAuthorizedDataRequest implements Serializable { +@Schema(name = "AssetAuthorizedDataQueryRequest", description = "资产授权数据 查询请求对象") +public class AssetAuthorizedDataQueryRequest implements Serializable { @Schema(description = "用户id") private Long userId; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/AuthorizedHostGroupWrapperVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/AuthorizedHostGroupWrapperVO.java new file mode 100644 index 00000000..125da1e9 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/AuthorizedHostGroupWrapperVO.java @@ -0,0 +1,31 @@ +package com.orion.ops.module.asset.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 已授权的主机分组 视图响应对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/11/30 21:37 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "AuthorizedHostGroupWrapperVO", description = "已授权的主机分组 视图响应对象") +public class AuthorizedHostGroupWrapperVO { + + @Schema(description = "授权的主机分组") + private List groupTree; + + @Schema(description = "授权的主机列表") + private List hostList; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostGroupTreeVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostGroupTreeVO.java index 55895f54..4efee71b 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostGroupTreeVO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/HostGroupTreeVO.java @@ -9,7 +9,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; -import java.util.Collection; import java.util.List; /** @@ -45,7 +44,7 @@ public class HostGroupTreeVO implements TreeNode, Serializable @Schema(description = "子节点") private List children; - @Schema(description = "分组内主机id") - private Collection hosts; + @Schema(description = "分组内主机") + private List hostList; } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/AssetAuthorizedDataService.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/AssetAuthorizedDataService.java index 4eca6a8b..b713f12d 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/AssetAuthorizedDataService.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/AssetAuthorizedDataService.java @@ -1,7 +1,10 @@ package com.orion.ops.module.asset.service; -import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataRequest; -import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO; +import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataQueryRequest; +import com.orion.ops.module.asset.entity.vo.AuthorizedHostGroupWrapperVO; +import com.orion.ops.module.asset.entity.vo.HostIdentityVO; +import com.orion.ops.module.asset.entity.vo.HostKeyVO; +import com.orion.ops.module.infra.enums.DataPermissionTypeEnum; import java.util.List; @@ -15,12 +18,13 @@ import java.util.List; public interface AssetAuthorizedDataService { /** - * 获取已授权的数据 + * 获取已被授权的数据 id * * @param request request + * @param type type * @return dataId */ - List getAuthorizedData(AssetAuthorizedDataRequest request); + List getAuthorizedDataRelId(DataPermissionTypeEnum type, AssetAuthorizedDataQueryRequest request); /** * 查询用户已授权的主机分组和主机 @@ -28,6 +32,22 @@ public interface AssetAuthorizedDataService { * @param userId userId * @return group */ - List getUserAuthorizedHostGroup(Long userId); + AuthorizedHostGroupWrapperVO getUserAuthorizedHostGroup(Long userId); + + /** + * 查询用户已授权的主机秘钥 + * + * @param userId userId + * @return key + */ + List getUserAuthorizedHostKey(Long userId); + + /** + * 查询用户已授权的主机身份 + * + * @param userId userId + * @return identity + */ + List getUserAuthorizedHostIdentity(Long userId); } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetAuthorizedDataServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetAuthorizedDataServiceImpl.java index e47f5007..1a450c85 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetAuthorizedDataServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetAuthorizedDataServiceImpl.java @@ -1,13 +1,17 @@ package com.orion.ops.module.asset.service.impl; +import com.orion.lang.function.Functions; import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.utils.TreeUtils; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.module.asset.convert.HostGroupConvert; -import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataRequest; -import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO; +import com.orion.ops.module.asset.entity.request.asset.AssetAuthorizedDataQueryRequest; +import com.orion.ops.module.asset.entity.vo.*; import com.orion.ops.module.asset.service.AssetAuthorizedDataService; +import com.orion.ops.module.asset.service.HostIdentityService; +import com.orion.ops.module.asset.service.HostKeyService; +import com.orion.ops.module.asset.service.HostService; import com.orion.ops.module.infra.api.DataGroupApi; import com.orion.ops.module.infra.api.DataGroupRelApi; import com.orion.ops.module.infra.api.DataPermissionApi; @@ -20,6 +24,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 资产模块 授权数据服务实现类 @@ -44,32 +50,89 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic @Resource private SystemUserApi systemUserApi; + @Resource + private HostService hostService; + + @Resource + private HostKeyService hostKeyService; + + @Resource + private HostIdentityService hostIdentityService; + @Override - public List getAuthorizedData(AssetAuthorizedDataRequest request) { + public List getAuthorizedDataRelId(DataPermissionTypeEnum type, AssetAuthorizedDataQueryRequest request) { Long userId = request.getUserId(); Long roleId = request.getRoleId(); Valid.isTrue(userId != null || roleId != null); if (userId != null) { // 查询用户数据 - return dataPermissionApi.getRelIdListByUserId(DataPermissionTypeEnum.HOST_GROUP, userId); + return dataPermissionApi.getRelIdListByUserId(type, userId); } else { // 查询角色数据 - return dataPermissionApi.getRelIdListByRoleId(DataPermissionTypeEnum.HOST_GROUP, roleId); + return dataPermissionApi.getRelIdListByRoleId(type, roleId); } } @Override - public List getUserAuthorizedHostGroup(Long userId) { + public AuthorizedHostGroupWrapperVO getUserAuthorizedHostGroup(Long userId) { if (systemUserApi.isAdminUser(userId)) { // 管理员查询所有 return this.buildUserAuthorizedHostGroup(null); } else { - // 其他用户查询授权的分组 - List authorizedGroupIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_GROUP, userId); - if (authorizedGroupIdList.isEmpty()) { + // 其他用户 查询授权的数据 + List authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_GROUP, userId); + if (authorizedIdList.isEmpty()) { + // 无数据 + return AuthorizedHostGroupWrapperVO.builder() + .groupTree(Lists.empty()) + .hostList(Lists.empty()) + .build(); + } + return this.buildUserAuthorizedHostGroup(authorizedIdList); + } + } + + @Override + public List getUserAuthorizedHostKey(Long userId) { + if (systemUserApi.isAdminUser(userId)) { + // 管理员查询所有 + return hostKeyService.getHostKeyList(); + } else { + // 其他用户 查询授权的数据 + List authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_KEY, userId); + if (authorizedIdList.isEmpty()) { return Lists.empty(); } - return this.buildUserAuthorizedHostGroup(authorizedGroupIdList); + // 映射数据 + Map keys = hostKeyService.getHostKeyList() + .stream() + .collect(Collectors.toMap(HostKeyVO::getId, Function.identity(), Functions.right())); + return authorizedIdList.stream() + .map(keys::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + } + + @Override + public List getUserAuthorizedHostIdentity(Long userId) { + if (systemUserApi.isAdminUser(userId)) { + // 管理员查询所有 + return hostIdentityService.getHostIdentityList(); + } else { + // 其他用户 查询授权的数据 + List authorizedIdList = dataPermissionApi.getUserAuthorizedRelIdList(DataPermissionTypeEnum.HOST_IDENTITY, userId); + if (authorizedIdList.isEmpty()) { + return Lists.empty(); + } + // 映射数据 + Map identities = hostIdentityService.getHostIdentityList() + .stream() + .collect(Collectors.toMap(HostIdentityVO::getId, Function.identity(), Functions.right())); + return authorizedIdList.stream() + .map(identities::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); } } @@ -79,36 +142,60 @@ public class AssetAuthorizedDataServiceImpl implements AssetAuthorizedDataServic * @param authorizedGroupIdList authorizedGroupIdList * @return tree */ - private List buildUserAuthorizedHostGroup(List authorizedGroupIdList) { + private AuthorizedHostGroupWrapperVO buildUserAuthorizedHostGroup(List authorizedGroupIdList) { + final boolean allData = Lists.isEmpty(authorizedGroupIdList); + AuthorizedHostGroupWrapperVO wrapper = new AuthorizedHostGroupWrapperVO(); + // 查询主机列表 + List hosts = hostService.getHostListByCache(); + Map hostMap = hosts.stream() + .collect(Collectors.toMap(HostVO::getId, Function.identity(), Functions.right())); + // 查询分组引用 + Map> groupRel = dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST); // 查询分组 List dataGroup = dataGroupApi.getDataGroupList(DataGroupTypeEnum.HOST); // 过滤分组 - if (!Lists.isEmpty(authorizedGroupIdList)) { + if (!allData) { // 构建已授权的分组 List relNodes = new ArrayList<>(); TreeUtils.getAllNodes(dataGroup, authorizedGroupIdList, relNodes); dataGroup = new ArrayList<>(new HashSet<>(relNodes)); } - // 查询分组引用 - Map> groupRel = dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST); // 设置组内数据 List groupList = HostGroupConvert.MAPPER.toList(dataGroup); - if (Lists.isEmpty(authorizedGroupIdList)) { - // 设置全部数据 - groupList.forEach(s -> s.setHosts(groupRel.get(s.getId()))); - } else { - // 仅设置已授权的数据 - groupList.stream() - .filter(s -> authorizedGroupIdList.contains(s.getId())) - .forEach(s -> s.setHosts(groupRel.get(s.getId()))); - } - // 构建树 + groupList.stream() + // 因为可能父菜单没有授权 这里需要判断组 + .filter(s -> allData || authorizedGroupIdList.contains(s.getId())) + .forEach(s -> { + List groupHosts = Lists.stream(groupRel.get(s.getId())) + .map(hostMap::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + s.setHostList(groupHosts); + }); + // 构建主机树 HostGroupTreeVO rootNode = HostGroupTreeVO.builder() .id(Const.ROOT_PARENT_ID) .sort(Const.DEFAULT_SORT) .build(); TreeUtils.buildGroupTree(rootNode, groupList); - return rootNode.getChildren(); + wrapper.setGroupTree(rootNode.getChildren()); + // 设置授权的主机 + if (allData) { + // 设置全部数据 + wrapper.setHostList(hosts); + } else { + // 仅设置已授权的数据 + List groupHosts = groupList.stream() + .filter(s -> authorizedGroupIdList.contains(s.getId())) + .map(s -> groupRel.get(s.getId())) + .filter(Lists::isNoneEmpty) + .flatMap(Collection::stream) + .map(hostMap::get) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + wrapper.setHostList(groupHosts); + } + return wrapper; } } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetDataGrantServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetDataGrantServiceImpl.java index 52bb449e..44fde62c 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetDataGrantServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/AssetDataGrantServiceImpl.java @@ -1,6 +1,8 @@ package com.orion.ops.module.asset.service.impl; import com.orion.lang.utils.collect.Lists; +import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; +import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.module.asset.dao.HostIdentityDAO; @@ -128,14 +130,15 @@ public class AssetDataGrantServiceImpl implements AssetDataGrantService { // 检测用户是否存在 SystemUserDTO user = systemUserApi.getUserById(userId); Valid.notNull(user, ErrorMessage.USER_ABSENT); - // TODO 日志查看 type name + OperatorLogs.add(OperatorLogs.GRANT_TYPE, Const.CN_USER); + OperatorLogs.add(OperatorLogs.GRANT_NAME, user.getNickname() + "(" + user.getUsername() + ")"); } if (roleId != null) { // 检测角色是否存在 SystemRoleDTO role = systemRoleApi.getRoleById(roleId); Valid.notNull(role, ErrorMessage.ROLE_ABSENT); - // TODO 日志查看 type name - + OperatorLogs.add(OperatorLogs.GRANT_TYPE, Const.CN_ROLE); + OperatorLogs.add(OperatorLogs.GRANT_NAME, role.getName() + "(" + role.getCode() + ")"); } } diff --git a/orion-ops-ui/.env.development b/orion-ops-ui/.env.development index da770b29..fe87f179 100644 --- a/orion-ops-ui/.env.development +++ b/orion-ops-ui/.env.development @@ -1 +1,2 @@ VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-api' +VITE_APP_VERSION= '1.0.0' diff --git a/orion-ops-ui/.env.production b/orion-ops-ui/.env.production index da770b29..fe87f179 100644 --- a/orion-ops-ui/.env.production +++ b/orion-ops-ui/.env.production @@ -1 +1,2 @@ VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-api' +VITE_APP_VERSION= '1.0.0' diff --git a/orion-ops-ui/src/api/asset/asset-authorized-data.ts b/orion-ops-ui/src/api/asset/asset-authorized-data.ts new file mode 100644 index 00000000..7d7ef0f2 --- /dev/null +++ b/orion-ops-ui/src/api/asset/asset-authorized-data.ts @@ -0,0 +1,34 @@ +import type { HostGroupQueryResponse } from '@/api/asset/host-group'; +import type { HostQueryResponse } from './host'; +import type { HostKeyQueryResponse } from './host-key'; +import type { HostIdentityQueryResponse } from './host-identity'; +import axios from 'axios'; + +/** + * 已授权的主机分组 查询响应 + */ +export interface AuthorizedHostGroupQueryResponse { + groupTree: Array; + hostList: Array; +} + +/** + * 查询当前用户已授权的主机分组 + */ +export function getCurrentAuthorizedHostGroup() { + return axios.get('/asset/authorized-data/current-host-group'); +} + +/** + * 查询当前用户已授权的主机秘钥 + */ +export function getCurrentAuthorizedHostKey() { + return axios.get('/asset/authorized-data/current-host-key'); +} + +/** + * 查询当前用户已授权的主机身份 + */ +export function getCurrentAuthorizedHostIdentity() { + return axios.get('/asset/authorized-data/current-host-identity'); +} diff --git a/orion-ops-ui/src/api/asset/asset-data-grant.ts b/orion-ops-ui/src/api/asset/asset-data-grant.ts new file mode 100644 index 00000000..fd520220 --- /dev/null +++ b/orion-ops-ui/src/api/asset/asset-data-grant.ts @@ -0,0 +1,60 @@ +import axios from 'axios'; + +/** + * 数据授权 请求对象 + */ +export interface AssetDataGrantRequest { + userId?: number; + roleId?: number; + idList?: Array; +} + +/** + * 授权数据 查询请求对象 + */ +export interface AssetAuthorizedDataQueryRequest { + userId?: number; + roleId?: number; +} + +/** + * 主机分组授权 + */ +export function grantHostGroup(request: AssetDataGrantRequest) { + return axios.put('/asset/host-group/grant-host-group', request); +} + +/** + * 获取已授权的主机分组 + */ +export function getAuthorizedHostGroup(params: AssetAuthorizedDataQueryRequest) { + return axios.get>('/asset/data-grant/get-host-group', { params }); +} + +/** + * 主机秘钥授权 + */ +export function grantHostKey(request: AssetDataGrantRequest) { + return axios.put('/asset/host-group/grant-host-key', request); +} + +/** + * 获取已授权的主机秘钥 + */ +export function getAuthorizedHostKey(params: AssetAuthorizedDataQueryRequest) { + return axios.get>('/asset/data-grant/get-host-key', { params }); +} + +/** + * 主机身份授权 + */ +export function grantHostIdentity(request: AssetDataGrantRequest) { + return axios.put('/asset/host-group/grant-host-identity', request); +} + +/** + * 获取已授权的主机身份 + */ +export function getAuthorizedHostIdentity(params: AssetAuthorizedDataQueryRequest) { + return axios.get>('/asset/data-grant/get-host-identity', { params }); +} diff --git a/orion-ops-ui/src/api/asset/asset-data.ts b/orion-ops-ui/src/api/asset/asset-data.ts deleted file mode 100644 index bdd20fb3..00000000 --- a/orion-ops-ui/src/api/asset/asset-data.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { HostGroupQueryResponse } from '@/api/asset/host-group'; -import axios from 'axios'; - -/** - * 查询已授权的主机分组 - */ -export function getAuthorizedHostGroup() { - return axios.get>('/asset/authorized-data/host-group'); -} diff --git a/orion-ops-ui/src/api/asset/host-group.ts b/orion-ops-ui/src/api/asset/host-group.ts index 7e41d272..d2ad3e50 100644 --- a/orion-ops-ui/src/api/asset/host-group.ts +++ b/orion-ops-ui/src/api/asset/host-group.ts @@ -1,3 +1,4 @@ +import type { HostQueryResponse } from './host'; import axios from 'axios'; /** @@ -33,7 +34,7 @@ export interface HostGroupQueryResponse { parentId: number; title: string; children: Array; - hosts: Array; + hostList: Array; } /** @@ -44,21 +45,6 @@ export interface HostGroupRelUpdateRequest { hostIdList?: Array; } -/** - * 主机分组授权 查询请求对象 - */ -export interface HostGroupGrantQueryRequest { - userId?: number; - roleId?: number; -} - -/** - * 主机分组 授权请求对象 - */ -export interface HostGroupGrantRequest extends HostGroupGrantQueryRequest { - groupIdList?: Array; -} - /** * 创建主机分组 */ @@ -107,17 +93,3 @@ export function getHostGroupRelList(groupId: number) { export function updateHostGroupRel(request: HostGroupRelUpdateRequest) { return axios.put('/asset/host-group/update-rel', request); } - -/** - * 获取已授权的分组 - */ -export function getAuthorizedHostGroup(params: HostGroupGrantQueryRequest) { - return axios.get>('/asset/host-group/get-authorized-group', { params }); -} - -/** - * 主机分组授权 - */ -export function grantHostGroup(request: HostGroupGrantRequest) { - return axios.put('/asset/host-group/grant', request); -} diff --git a/orion-ops-ui/src/components/app/footer/index.vue b/orion-ops-ui/src/components/app/footer/index.vue index b67b7636..f2651dfd 100644 --- a/orion-ops-ui/src/components/app/footer/index.vue +++ b/orion-ops-ui/src/components/app/footer/index.vue @@ -7,6 +7,7 @@ 教程 github gitee + v{{ version }} Copyright 2023 By OrionOpsPro @@ -16,6 +17,7 @@