diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/PermissionConfig.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/PermissionConfig.java new file mode 100644 index 0000000000..78dcd2fd3e --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/config/PermissionConfig.java @@ -0,0 +1,39 @@ +package io.metersphere.sdk.config; + +import io.metersphere.sdk.dto.UserRoleJson; +import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.LogUtils; +import io.metersphere.sdk.util.PermissionCache; +import org.apache.commons.io.IOUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Enumeration; + +@Configuration +public class PermissionConfig { + @Bean + public PermissionCache permissionCache() throws Exception { + LogUtils.info("load permission form permission.json file"); + UserRoleJson userRoleJson = null; + Enumeration urls = this.getClass().getClassLoader().getResources("permission.json"); + while (urls.hasMoreElements()) { + URL url = urls.nextElement(); + String content = IOUtils.toString(url.openStream(), StandardCharsets.UTF_8); + UserRoleJson temp = JSON.parseObject(content, UserRoleJson.class); + if (userRoleJson == null) { + userRoleJson = temp; + } else { + userRoleJson.getResource().addAll(temp.getResource()); + userRoleJson.getPermissions().addAll(temp.getPermissions()); + } + + } + PermissionCache permissionCache = new PermissionCache(); + permissionCache.setUserRoleJson(userRoleJson); + + return permissionCache; + } +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleJson.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleJson.java new file mode 100644 index 0000000000..6b854f38c4 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleJson.java @@ -0,0 +1,16 @@ +package io.metersphere.sdk.dto; + + +import io.metersphere.system.domain.UserRolePermission; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class UserRoleJson implements Serializable { + private static final long serialVersionUID = 1L; + + private List resource; + private List permissions; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/GroupResource.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResource.java similarity index 87% rename from backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/GroupResource.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResource.java index 23911dc3ad..85602fa204 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/GroupResource.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResource.java @@ -5,7 +5,7 @@ import lombok.Data; import java.io.Serializable; @Data -public class GroupResource implements Serializable { +public class UserRoleResource implements Serializable { private static final long serialVersionUID = 1L; private String id; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResourceDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResourceDTO.java index 2acae05ca4..1f0c5f49a8 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResourceDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/UserRoleResourceDTO.java @@ -11,7 +11,7 @@ import java.util.List; public class UserRoleResourceDTO implements Serializable { private static final long serialVersionUID = 1L; - private GroupResource resource; + private UserRoleResource resource; private List permissions; private String type; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/PermissionCache.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/PermissionCache.java new file mode 100644 index 0000000000..5d8b85af17 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/PermissionCache.java @@ -0,0 +1,9 @@ +package io.metersphere.sdk.util; + +import io.metersphere.sdk.dto.UserRoleJson; +import lombok.Data; + +@Data +public class PermissionCache { + private UserRoleJson userRoleJson; +} diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json new file mode 100644 index 0000000000..d8b80e7e36 --- /dev/null +++ b/backend/services/project-management/src/main/resources/permission.json @@ -0,0 +1,316 @@ +{ + "permissions": [ + { + "id": "PROJECT_USER:READ", + "name": "permission.project_user.read", + "resourceId": "PROJECT_USER" + }, + { + "id": "PROJECT_USER:READ+ADD", + "name": "permission.project_user.add", + "resourceId": "PROJECT_USER" + }, + { + "id": "PROJECT_USER:READ+UPDATE", + "name": "permission.project_user.update", + "resourceId": "PROJECT_USER" + }, + { + "id": "PROJECT_USER:READ+DELETE", + "name": "permission.project_user.delete", + "resourceId": "PROJECT_USER" + }, + { + "id": "PROJECT_GROUP:READ", + "name": "permission.project_group.read", + "resourceId": "PROJECT_GROUP" + }, + { + "id": "PROJECT_GROUP:READ+ADD", + "name": "permission.project_group.add", + "resourceId": "PROJECT_GROUP" + }, + { + "id": "PROJECT_GROUP:READ+UPDATE", + "name": "permission.project_group.update", + "resourceId": "PROJECT_GROUP" + }, + { + "id": "PROJECT_GROUP:READ+DELETE", + "name": "permission.project_group.delete", + "resourceId": "PROJECT_GROUP" + }, + { + "id": "PROJECT_GROUP:READ+SETTING_PERMISSION", + "name": "permission.project_group.setting_permission", + "resourceId": "PROJECT_GROUP" + }, + { + "id": "PROJECT_MANAGER:READ", + "name": "permission.project_manager.read", + "resourceId": "PROJECT_MANAGER" + }, + { + "id": "PROJECT_MANAGER:READ+UPDATE", + "name": "permission.project_manager.update", + "resourceId": "PROJECT_MANAGER" + }, + { + "id": "PROJECT_APP_MANAGER:READ+UPDATE", + "name": "permission.project_app_manager.update", + "resourceId": "PROJECT_APP_MANAGER" + }, + { + "id": "PROJECT_ENVIRONMENT:READ", + "name": "permission.project_environment.read", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+ADD", + "name": "permission.project_environment.add", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+UPDATE", + "name": "permission.project_environment.update", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+DELETE", + "name": "permission.project_environment.delete", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+COPY", + "name": "permission.project_environment.copy", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+IMPORT", + "name": "permission.project_environment.import", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_ENVIRONMENT:READ+EXPORT", + "name": "permission.project_environment.export", + "resourceId": "PROJECT_ENVIRONMENT" + }, + { + "id": "PROJECT_OPERATING_LOG:READ", + "name": "permission.project_operation_log.read", + "resourceId": "PROJECT_OPERATING_LOG" + }, + { + "id": "PROJECT_FILE:READ", + "name": "permission.project_file.jar", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+UPLOAD+JAR", + "name": "permission.project_file.upload_jar", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+DOWNLOAD+JAR", + "name": "permission.project_file.file_download", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+DELETE+JAR", + "name": "permission.project_file.delete_jar", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+BATCH+DELETE", + "name": "permission.project_file.batch_delete", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+BATCH+DOWNLOAD", + "name": "permission.project_file.batch_download", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_FILE:READ+BATCH+MOVE", + "name": "permission.project_file.batch_move", + "resourceId": "PROJECT_FILE" + }, + { + "id": "PROJECT_TEMPLATE:READ", + "name": "permission.project_template.read", + "resourceId": "PROJECT_TEMPLATE" + }, + { + "id": "PROJECT_TEMPLATE:READ+CASE_TEMPLATE", + "name": "permission.project_template.case_template", + "resourceId": "PROJECT_TEMPLATE" + }, + { + "id": "PROJECT_TEMPLATE:READ+ISSUE_TEMPLATE", + "name": "permission.project_template.issue_template", + "resourceId": "PROJECT_TEMPLATE" + }, + { + "id": "PROJECT_TEMPLATE:READ+API_TEMPLATE", + "name": "permission.project_template.api_template", + "resourceId": "PROJECT_TEMPLATE" + }, + { + "id": "PROJECT_TEMPLATE:READ+CUSTOM", + "name": "permission.project_template.custom", + "resourceId": "PROJECT_TEMPLATE" + }, + { + "id": "PROJECT_MESSAGE:READ", + "name": "permission.project_message.read", + "resourceId": "PROJECT_MESSAGE" + }, + { + "id": "PROJECT_MESSAGE:READ+UPDATE", + "name": "permission.project_message.update", + "resourceId": "PROJECT_MESSAGE" + }, + { + "id": "PROJECT_MESSAGE:READ+DELETE", + "name": "permission.project_message.delete", + "resourceId": "PROJECT_MESSAGE" + }, + { + "id": "PROJECT_CUSTOM_CODE:READ", + "name": "permission.project_custom_code.read", + "resourceId": "PROJECT_CUSTOM_CODE" + }, + { + "id": "PROJECT_CUSTOM_CODE:READ+ADD", + "name": "permission.project_custom_code.add", + "resourceId": "PROJECT_CUSTOM_CODE" + }, + { + "id": "PROJECT_CUSTOM_CODE:READ+UPDATE", + "name": "permission.project_custom_code.update", + "resourceId": "PROJECT_CUSTOM_CODE" + }, + { + "id": "PROJECT_CUSTOM_CODE:READ+DELETE", + "name": "permission.project_custom_code.delete", + "resourceId": "PROJECT_CUSTOM_CODE" + }, + { + "id": "PROJECT_CUSTOM_CODE:READ+COPY", + "name": "permission.project_custom_code.copy", + "resourceId": "PROJECT_CUSTOM_CODE" + }, + { + "id": "PROJECT_VERSION:READ", + "name": "project.version.read", + "resourceId": "PROJECT_VERSION", + "license": true + }, + { + "id": "PROJECT_VERSION:READ+ADD", + "name": "project.version.add_version", + "resourceId": "PROJECT_VERSION", + "license": true + }, + { + "id": "PROJECT_VERSION:READ+UPDATE", + "name": "project.version.update_version", + "resourceId": "PROJECT_VERSION", + "license": true + }, + { + "id": "PROJECT_VERSION:READ+DELETE", + "name": "project.version.delete_version", + "resourceId": "PROJECT_VERSION", + "license": true + }, + { + "id": "PROJECT_VERSION:READ+ENABLE", + "name": "project.version.enable", + "resourceId": "PROJECT_VERSION", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY:READ", + "name": "permission.project_error_report_library.read", + "resourceId": "PROJECT_ERROR_REPORT_LIBRARY", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY:READ+ADD", + "name": "permission.project_error_report_library.add", + "resourceId": "PROJECT_ERROR_REPORT_LIBRARY", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY:READ+UPDATE", + "name": "permission.project_error_report_library.update", + "resourceId": "PROJECT_ERROR_REPORT_LIBRARY", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY:READ+DELETE", + "name": "permission.project_error_report_library.delete", + "resourceId": "PROJECT_ERROR_REPORT_LIBRARY", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY:READ+BATCH_DELETE", + "name": "permission.project_error_report_library.batch_delete", + "resourceId": "PROJECT_ERROR_REPORT_LIBRARY", + "license": true + } + ], + "resource": [ + { + "id": "PROJECT_USER", + "name": "permission.project_user.name" + }, + { + "id": "PROJECT_MANAGER", + "name": "permission.project_manager.name" + }, + { + "id": "PROJECT_GROUP", + "name": "permission.project_group.name" + }, + { + "id": "PROJECT_ENVIRONMENT", + "name": "permission.project_environment.name" + }, + { + "id": "PROJECT_OPERATING_LOG", + "name": "permission.project_operation_log.name" + }, + { + "id": "PROJECT_CUSTOM_CODE", + "name": "permission.project_custom_code.name" + }, + { + "id": "PROJECT_FILE", + "name": "permission.project_file.name" + }, + { + "id": "PROJECT_TEMPLATE", + "name": "permission.project_template.name" + }, + { + "id": "PROJECT_MESSAGE", + "name": "permission.project_message.name" + }, + { + "id": "PROJECT_VERSION", + "name": "project.version_manage", + "license": true + }, + { + "id": "PROJECT_ERROR_REPORT_LIBRARY", + "name": "permission.project_error_report_library.name", + "license": true + }, + { + "id": "PROJECT_APP_MANAGER", + "name": "permission.project_app_manager.name" + } + ] +} \ No newline at end of file diff --git a/backend/services/system-setting/src/main/resources/permission.json b/backend/services/system-setting/src/main/resources/permission.json index 390b4c87d2..734221da5b 100644 --- a/backend/services/system-setting/src/main/resources/permission.json +++ b/backend/services/system-setting/src/main/resources/permission.json @@ -6,8 +6,8 @@ "resourceId": "SYSTEM_USER" }, { - "id": "SYSTEM_USER:READ+CREATE", - "name": "permission.system_user.create", + "id": "SYSTEM_USER:READ+ADD", + "name": "permission.system_user.add", "resourceId": "SYSTEM_USER" }, { @@ -36,8 +36,8 @@ "resourceId": "SYSTEM_WORKSPACE" }, { - "id": "SYSTEM_WORKSPACE:READ+CREATE", - "name": "permission.system_workspace.create", + "id": "SYSTEM_WORKSPACE:READ+ADD", + "name": "permission.system_workspace.add", "resourceId": "SYSTEM_WORKSPACE" }, { @@ -56,8 +56,8 @@ "resourceId": "SYSTEM_ROLE" }, { - "id": "SYSTEM_ROLE:READ+CREATE", - "name": "permission.system_role.create", + "id": "SYSTEM_ROLE:READ+ADD", + "name": "permission.system_role.add", "resourceId": "SYSTEM_ROLE" }, { @@ -81,8 +81,8 @@ "resourceId": "SYSTEM_TEST_POOL" }, { - "id": "SYSTEM_TEST_POOL:READ+CREATE", - "name": "permission.system_test_pool.create", + "id": "SYSTEM_TEST_POOL:READ+ADD", + "name": "permission.system_test_pool.add", "resourceId": "SYSTEM_TEST_POOL" }, { @@ -146,8 +146,8 @@ "resourceId": "WORKSPACE_USER" }, { - "id": "WORKSPACE_USER:READ+CREATE", - "name": "permission.workspace_user.create", + "id": "WORKSPACE_USER:READ+ADD", + "name": "permission.workspace_user.add", "resourceId": "WORKSPACE_USER" }, { @@ -166,8 +166,8 @@ "resourceId": "WORKSPACE_PROJECT_MANAGER" }, { - "id": "WORKSPACE_PROJECT_MANAGER:READ+CREATE", - "name": "permission.workspace_project_manager.create", + "id": "WORKSPACE_PROJECT_MANAGER:READ+ADD", + "name": "permission.workspace_project_manager.add", "resourceId": "WORKSPACE_PROJECT_MANAGER" }, { @@ -187,7 +187,7 @@ }, { "id": "WORKSPACE_PROJECT_MANAGER:READ+ADD_USER", - "name": "permission.workspace_user.create", + "name": "permission.workspace_user.add", "resourceId": "WORKSPACE_PROJECT_MANAGER" }, { @@ -206,8 +206,8 @@ "resourceId": "WORKSPACE_PROJECT_ENVIRONMENT" }, { - "id": "WORKSPACE_PROJECT_ENVIRONMENT:READ+CREATE", - "name": "permission.workspace_project_environment.create", + "id": "WORKSPACE_PROJECT_ENVIRONMENT:READ+ADD", + "name": "permission.workspace_project_environment.add", "resourceId": "WORKSPACE_PROJECT_ENVIRONMENT" }, { @@ -236,8 +236,8 @@ "resourceId": "WORKSPACE_PROJECT_ENVIRONMENT" }, { - "id": "WORKSPACE_PROJECT_ENVIRONMENT:READ+CREATE_GROUP", - "name": "permission.workspace_project_environment.create_group", + "id": "WORKSPACE_PROJECT_ENVIRONMENT:READ+ADD_GROUP", + "name": "permission.workspace_project_environment.add_group", "resourceId": "WORKSPACE_PROJECT_ENVIRONMENT" }, {