From 27a070cb36420acef11d45ad0e60818f643b4572 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 2 Nov 2020 00:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9D=83=E9=99=90=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/rbac/resource/InterfaceApp.kt | 35 ++++++++++++++++--- .../app/controller/rbac/resource/PageApp.kt | 33 ++++++++++++++--- .../app/controller/rbac/resource/SystemApp.kt | 25 ++++++++++--- .../domain/model/rbac/resource/Interface.kt | 1 + .../zeus/domain/model/rbac/resource/Page.kt | 8 ++--- .../domain/model/rbac/resource/Resource.kt | 6 ++-- .../service/cmd/rbac/resource/InterfaceCmd.kt | 1 + .../service/cmd/rbac/resource/PageCmd.kt | 8 ++--- .../service/cmd/rbac/resource/ResourceCmd.kt | 6 ++-- .../query/contr/resouce/IInterfaceQuery.kt | 2 ++ .../zeus/query/contr/resouce/IPageQuery.kt | 2 ++ .../zeus/query/impl/resouce/InterfaceQuery.kt | 25 +++++++++++-- .../zeus/query/impl/resouce/PageQuery.kt | 23 ++++++++++-- .../query/impl/resouce/PermissionQuery.kt | 2 +- .../zeus/query/view/resource/InterfaceView.kt | 1 + .../zeus/query/view/resource/PageView.kt | 8 ++--- .../zeus/query/view/resource/ResourceView.kt | 6 ++-- 17 files changed, 151 insertions(+), 41 deletions(-) diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/InterfaceApp.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/InterfaceApp.kt index 6cfa2ba..a20835a 100644 --- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/InterfaceApp.kt +++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/InterfaceApp.kt @@ -1,11 +1,14 @@ package com.synebula.zeus.app.controller.rbac.resource import com.synebula.gaea.app.Application +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.log.ILogger import com.synebula.zeus.domain.service.cmd.rbac.resource.InterfaceCmd import com.synebula.zeus.domain.service.contr.rbac.resource.IInterfaceService -import com.synebula.zeus.query.impl.resouce.InterfaceQuery +import com.synebula.zeus.query.contr.resouce.IInterfaceQuery import com.synebula.zeus.query.view.resource.InterfaceView +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @@ -13,9 +16,31 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/interfaces") class InterfaceApp( service: IInterfaceService, - query: InterfaceQuery, - logger: ILogger + logger: ILogger, + var interfaceQuery: IInterfaceQuery ) : Application( "接口信息", InterfaceView::class.java, - service, query, logger -) \ No newline at end of file + service, interfaceQuery, logger +) { + + @GetMapping("/in-system/{system}/permission/{role}") + fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage { + return this.safeExecute("获取有权资源列表失败") { msg -> + msg.data = this.interfaceQuery.withPermission(role, system) + } + } + + @GetMapping("/permission/{role}") + fun withPermission(@PathVariable role: String): HttpMessage { + return this.safeExecute("获取有权资源列表失败") { msg -> + msg.data = this.interfaceQuery.withPermission(role) + } + } + + @GetMapping("/{api}/authentication/{role}") + fun authentication(@PathVariable api: String, @PathVariable role: String): HttpMessage { + return this.safeExecute("获取权限信息失败") { msg -> + msg.data = this.interfaceQuery.authentication(api, role) + } + } +} \ No newline at end of file diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/PageApp.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/PageApp.kt index 2acb911..68f3d56 100644 --- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/PageApp.kt +++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/PageApp.kt @@ -1,11 +1,14 @@ package com.synebula.zeus.app.controller.rbac.resource import com.synebula.gaea.app.Application +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.log.ILogger import com.synebula.zeus.domain.service.cmd.rbac.resource.PageCmd import com.synebula.zeus.domain.service.contr.rbac.resource.IPageService import com.synebula.zeus.query.contr.resouce.IPageQuery import com.synebula.zeus.query.view.resource.PageView +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @@ -13,9 +16,31 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/pages") class PageApp( service: IPageService, - query: IPageQuery, - logger: ILogger + logger: ILogger, + var pageQuery: IPageQuery ) : Application( "页面信息", PageView::class.java, - service, query, logger -) \ No newline at end of file + service, pageQuery, logger +) { + + @GetMapping("/in-system/{system}/permission/{role}") + fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage { + return this.safeExecute("获取有权资源列表失败") { msg -> + msg.data = this.pageQuery.withPermission(role, system) + } + } + + @GetMapping("/permission/{role}") + fun withPermission(@PathVariable role: String): HttpMessage { + return this.safeExecute("获取有权资源列表失败") { msg -> + msg.data = this.pageQuery.withPermission(role) + } + } + + @GetMapping("/{page}/authentication/{role}") + fun authentication(@PathVariable page: String, @PathVariable role: String): HttpMessage { + return this.safeExecute("获取权限信息失败") { msg -> + msg.data = this.pageQuery.authentication(page, role) + } + } +} \ No newline at end of file diff --git a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/SystemApp.kt b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/SystemApp.kt index 5112a24..f49ea66 100644 --- a/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/SystemApp.kt +++ b/src/zeus.app/src/main/kotlin/com/synebula/zeus/app/controller/rbac/resource/SystemApp.kt @@ -1,11 +1,14 @@ package com.synebula.zeus.app.controller.rbac.resource import com.synebula.gaea.app.Application +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.log.ILogger import com.synebula.zeus.domain.service.cmd.rbac.resource.SystemCmd import com.synebula.zeus.domain.service.contr.rbac.resource.ISystemService import com.synebula.zeus.query.contr.resouce.ISystemQuery import com.synebula.zeus.query.view.resource.SystemView +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @@ -13,9 +16,23 @@ import org.springframework.web.bind.annotation.RestController @RequestMapping("/systems") class SystemApp( service: ISystemService, - query: ISystemQuery, - logger: ILogger + logger: ILogger, + var systemQuery: ISystemQuery ) : Application( "系统信息", SystemView::class.java, - service, query, logger -) \ No newline at end of file + service, systemQuery, logger +) { + @GetMapping("/permission/{role}") + fun withPermission(@PathVariable role: String): HttpMessage { + return this.safeExecute("获取有权资源列表失败") { msg -> + msg.data = this.systemQuery.withPermission(role) + } + } + + @GetMapping("/{system}/authentication/{role}") + fun authentication(@PathVariable system: String, @PathVariable role: String): HttpMessage { + return this.safeExecute("获取权限信息失败") { msg -> + msg.data = this.systemQuery.authentication(system, role) + } + } +} \ No newline at end of file diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Interface.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Interface.kt index 2f4af14..67716a2 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Interface.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Interface.kt @@ -3,5 +3,6 @@ package com.synebula.zeus.domain.model.rbac.resource import com.synebula.gaea.domain.model.IAggregateRoot class Interface : Resource(), IAggregateRoot { + var system = "" override var alive = true } \ No newline at end of file diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Page.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Page.kt index 002dd4a..02325bc 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Page.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Page.kt @@ -5,16 +5,16 @@ import com.synebula.gaea.domain.model.IAggregateRoot class Page : Resource(), IAggregateRoot { // 上级页面 - val supPage = 0 + var parent = "" // 页面图标 - val icon: String? = null + var icon: String? = null // 附加参数 - val params: String? = null + var params: String? = null // 所属系统 - val system = 0 + var system = "" override var alive = true diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Resource.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Resource.kt index 93641d3..02bb513 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Resource.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/model/rbac/resource/Resource.kt @@ -4,8 +4,8 @@ import com.synebula.gaea.domain.model.Entity abstract class Resource(override var id: String? = null) : Entity() { var name = "" - var signature = "" - val uri: String? = null + //资源定位符,唯一标识。可以是uil,也可以是别名 + var uri = "" var order = 0 - var desc = "" + var desc: String? = null } \ No newline at end of file diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/InterfaceCmd.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/InterfaceCmd.kt index feea2db..05af0c2 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/InterfaceCmd.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/InterfaceCmd.kt @@ -1,5 +1,6 @@ package com.synebula.zeus.domain.service.cmd.rbac.resource class InterfaceCmd : ResourceCmd() { + var system = "" var alive = true } \ No newline at end of file diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/PageCmd.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/PageCmd.kt index ca87f9f..6e644b1 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/PageCmd.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/PageCmd.kt @@ -3,16 +3,16 @@ package com.synebula.zeus.domain.service.cmd.rbac.resource class PageCmd : ResourceCmd() { // 上级页面 - val supPage = 0 + var parent = "" // 页面图标 - val icon: String? = null + var icon: String? = null // 附加参数 - val params: String? = null + var params: String? = null // 所属系统 - val system = 0 + var system = "" var alive = true diff --git a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/ResourceCmd.kt b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/ResourceCmd.kt index 0d54519..22c3fd8 100644 --- a/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/ResourceCmd.kt +++ b/src/zeus.domain/src/main/kotlin/com/synebula/zeus/domain/service/cmd/rbac/resource/ResourceCmd.kt @@ -5,8 +5,8 @@ import com.synebula.gaea.domain.service.Command abstract class ResourceCmd(var id: String? = null) : Command() { var name = "" - var signature = "" - val uri: String? = null + //资源定位符,唯一标识。可以是uil,也可以是别名 + var uri = "" var order = 0 - var desc = "" + var desc: String? = null } \ No newline at end of file diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IInterfaceQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IInterfaceQuery.kt index ed97915..4e37bb8 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IInterfaceQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IInterfaceQuery.kt @@ -8,5 +8,7 @@ interface IInterfaceQuery : IQuery { fun withPermission(role: String): List + fun withPermission(role: String, system: String?): List + fun authentication(resource: String, role: String): PermissionType } \ No newline at end of file diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IPageQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IPageQuery.kt index 7d9c990..2866df8 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IPageQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/contr/resouce/IPageQuery.kt @@ -8,5 +8,7 @@ interface IPageQuery : IQuery { fun withPermission(role: String): List + fun withPermission(role: String, system: String? ): List + fun authentication(resource: String, role: String): PermissionType } \ No newline at end of file diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/InterfaceQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/InterfaceQuery.kt index 7d8c3aa..6b692ed 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/InterfaceQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/InterfaceQuery.kt @@ -4,17 +4,36 @@ import com.synebula.gaea.mongo.query.MongoQuery import com.synebula.zeus.env.PermissionType import com.synebula.zeus.env.ResourceType import com.synebula.zeus.query.contr.resouce.IInterfaceQuery +import com.synebula.zeus.query.contr.resouce.IPermissionQuery +import com.synebula.zeus.query.contr.resouce.ISystemQuery import com.synebula.zeus.query.view.resource.InterfaceView import org.springframework.data.mongodb.core.MongoTemplate -class InterfaceQuery(template: MongoTemplate, var permissionQuery: PermissionQuery) : MongoQuery(template), IInterfaceQuery { +class InterfaceQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery, var systemQuery: ISystemQuery) : + MongoQuery(template), + IInterfaceQuery { private val clazz = InterfaceView::class.java override fun withPermission(role: String): List { - val interfaces = this.list(mapOf(), this.clazz) + return this.withPermission(role, null) + + } + + override fun withPermission(role: String, system: String?): List { + if (system != null) { + val permission = this.systemQuery.authentication(system, role) + if (permission == PermissionType.Deny) + return listOf() + } + val params = mutableMapOf() + if (system != null) params["system"] = system + val interfaces = this.list(params, this.clazz) val permissions = this.permissionQuery.resourcePermissions(ResourceType.Interface, role) - return interfaces.filter { i -> permissions.find { p -> i.id == p.resource }?.authorization == PermissionType.Allow } + return interfaces.filter { i -> + val permission = permissions.find { p -> i.id == p.resource } + permission == null || permission.authorization == PermissionType.Allow + } } override fun authentication(resource: String, role: String): PermissionType { diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PageQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PageQuery.kt index 1540a10..1ea68a2 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PageQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PageQuery.kt @@ -4,16 +4,33 @@ import com.synebula.gaea.mongo.query.MongoQuery import com.synebula.zeus.env.PermissionType import com.synebula.zeus.env.ResourceType import com.synebula.zeus.query.contr.resouce.IPageQuery +import com.synebula.zeus.query.contr.resouce.IPermissionQuery +import com.synebula.zeus.query.contr.resouce.ISystemQuery import com.synebula.zeus.query.view.resource.PageView import org.springframework.data.mongodb.core.MongoTemplate -class PageQuery(template: MongoTemplate, var permissionQuery: PermissionQuery) : MongoQuery(template), IPageQuery { +class PageQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery, var systemQuery: ISystemQuery) : + MongoQuery(template), IPageQuery { private val clazz = PageView::class.java override fun withPermission(role: String): List { - val pages = this.list(mapOf(), this.clazz) + return this.withPermission(role, null) + } + + override fun withPermission(role: String, system: String?): List { + if (system != null) { + val permission = this.systemQuery.authentication(system, role) + if (permission == PermissionType.Deny) + return listOf() + } + val params = mutableMapOf() + if (system != null) params["system"] = system + val pages = this.list(params, this.clazz) val permissions = this.permissionQuery.resourcePermissions(ResourceType.Page, role) - return pages.filter { i -> permissions.find { p -> i.id == p.resource }?.authorization == PermissionType.Allow } + return pages.filter { i -> + val permission = permissions.find { p -> i.id == p.resource } + permission == null || permission.authorization == PermissionType.Allow + } } override fun authentication(resource: String, role: String): PermissionType { diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PermissionQuery.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PermissionQuery.kt index f85c483..b50d040 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PermissionQuery.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/impl/resouce/PermissionQuery.kt @@ -16,7 +16,7 @@ class PermissionQuery(template: MongoTemplate) : MongoQuery(template), IPermissi override fun resourcePermissions(resourceType: ResourceType, role: String): List { return this.template.find( Query.query( - Criteria.where("resourceType").`is`(resourceType) + Criteria.where("type").`is`(resourceType) .and("role").`is`(role) ), this.clazz, this.collection) } diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/InterfaceView.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/InterfaceView.kt index 09ad1ed..3153305 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/InterfaceView.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/InterfaceView.kt @@ -1,5 +1,6 @@ package com.synebula.zeus.query.view.resource class InterfaceView : ResourceView() { + var system = "" var alive = true } \ No newline at end of file diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/PageView.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/PageView.kt index 513a87e..43c27d6 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/PageView.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/PageView.kt @@ -3,16 +3,16 @@ package com.synebula.zeus.query.view.resource class PageView : ResourceView() { // 上级页面 - val supPage = 0 + var parent = "" // 页面图标 - val icon: String? = null + var icon: String? = null // 附加参数 - val params: String? = null + var params: String? = null // 所属系统 - val system = 0 + var system = "" var alive = true diff --git a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/ResourceView.kt b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/ResourceView.kt index 57d512d..f6a65c6 100644 --- a/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/ResourceView.kt +++ b/src/zeus.query/src/main/kotlin/com/synebula/zeus/query/view/resource/ResourceView.kt @@ -3,8 +3,8 @@ package com.synebula.zeus.query.view.resource abstract class ResourceView(var id: String? = null) { var name = "" - var signature = "" - val uri: String? = null + //资源定位符,唯一标识。可以是uil,也可以是别名 + var uri = "" var order = 0 - var desc = "" + var desc: String? = null } \ No newline at end of file