Merge branch 'dev'
This commit is contained in:
@@ -21,8 +21,8 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
ext {
|
||||
version '0.2.1'
|
||||
gaea_version = '0.5.1'
|
||||
version '0.5.0'
|
||||
gaea_version = '0.6.0'
|
||||
spring_version = "2.3.0.RELEASE"
|
||||
}
|
||||
|
||||
|
||||
@@ -17,32 +17,19 @@ import org.springframework.data.mongodb.core.MongoTemplate
|
||||
|
||||
@Configuration
|
||||
open class ZeusBeans {
|
||||
@Primary
|
||||
@Bean
|
||||
@Primary
|
||||
open fun <T : IAggregateRoot<String>> repository(template: MongoTemplate)
|
||||
: IRepository = MongoRepository(template)
|
||||
|
||||
@Primary
|
||||
@Bean
|
||||
@Primary
|
||||
open fun <T> query(template: MongoTemplate, logger: ILogger? = null)
|
||||
: IQuery = MongoQuery(template, logger)
|
||||
|
||||
@Bean
|
||||
open fun gson(): Gson = Gson()
|
||||
|
||||
@Bean
|
||||
open fun userNotifier(): IUserNotifier {
|
||||
return object : IUserNotifier {
|
||||
override fun added(id: String, name: String, token: String) {
|
||||
|
||||
}
|
||||
|
||||
override fun forgot(id: String, name: String, token: String) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun serializer(gson: Gson): IJsonSerializer {
|
||||
return object : IJsonSerializer {
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.domain.service.cmd.rbac.GroupCmd
|
||||
import com.synebula.zeus.domain.service.contr.rbac.IGroupService
|
||||
import com.synebula.zeus.query.view.GroupView
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.domain.service.cmd.rbac.RoleCmd
|
||||
import com.synebula.zeus.domain.service.contr.rbac.IRoleService
|
||||
import com.synebula.zeus.query.view.RoleView
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
|
||||
@@ -10,14 +10,13 @@ import com.synebula.zeus.domain.service.cmd.rbac.UserCmd
|
||||
import com.synebula.zeus.domain.service.contr.rbac.IUserService
|
||||
import com.synebula.zeus.query.view.UserView
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
class UserApp(
|
||||
service: IUserService,
|
||||
@Qualifier("query") query: IQuery,
|
||||
query: IQuery,
|
||||
logger: ILogger
|
||||
) : Application<UserCmd, UserView, String>(
|
||||
"用户信息", UserView::class.java,
|
||||
|
||||
@@ -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<InterfaceCmd, InterfaceView, String>(
|
||||
"接口信息", InterfaceView::class.java,
|
||||
service, query, logger
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,40 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@RequestMapping("/pages")
|
||||
class PageApp(
|
||||
service: IPageService,
|
||||
query: IPageQuery,
|
||||
logger: ILogger
|
||||
logger: ILogger,
|
||||
var pageQuery: IPageQuery
|
||||
) : Application<PageCmd, PageView, String>(
|
||||
"页面信息", PageView::class.java,
|
||||
service, query, logger
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/authentication/{role}")
|
||||
fun uriAuthentication(@PathVariable role: String, uri: String): HttpMessage {
|
||||
return this.safeExecute("获取权限信息失败") { msg ->
|
||||
msg.data = this.pageQuery.uriAuthentication(uri, role)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,13 +2,9 @@ package com.synebula.zeus.app.controller.rbac.resource
|
||||
|
||||
import com.synebula.gaea.app.Application
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.zeus.domain.service.cmd.rbac.resource.PageCmd
|
||||
import com.synebula.zeus.domain.service.cmd.rbac.resource.PermissionCmd
|
||||
import com.synebula.zeus.domain.service.contr.rbac.resource.IPageService
|
||||
import com.synebula.zeus.domain.service.contr.rbac.resource.IPermissionService
|
||||
import com.synebula.zeus.query.contr.resouce.IPageQuery
|
||||
import com.synebula.zeus.query.contr.resouce.IPermissionQuery
|
||||
import com.synebula.zeus.query.view.resource.PageView
|
||||
import com.synebula.zeus.query.view.resource.PermissionView
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@@ -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<SystemCmd, SystemView, String>(
|
||||
"系统信息", SystemView::class.java,
|
||||
service, query, logger
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@ package com.synebula.zeus.domain.model.rbac.resource
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
|
||||
class Interface : Resource(), IAggregateRoot<String> {
|
||||
var system = ""
|
||||
override var alive = true
|
||||
}
|
||||
@@ -5,16 +5,16 @@ import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
class Page : Resource(), IAggregateRoot<String> {
|
||||
|
||||
// 上级页面
|
||||
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
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import com.synebula.gaea.domain.model.AggregateRoot
|
||||
import com.synebula.zeus.env.PermissionType
|
||||
import com.synebula.zeus.env.ResourceType
|
||||
|
||||
class Permission(override var id: String?) : AggregateRoot<String>() {
|
||||
class Permission(override var id: String? = null) : AggregateRoot<String>() {
|
||||
var role = ""
|
||||
var resource = ""
|
||||
var type: ResourceType? = null
|
||||
var authorization = PermissionType.Allow
|
||||
var authority = PermissionType.Allow
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import com.synebula.gaea.domain.model.Entity
|
||||
|
||||
abstract class Resource(override var id: String? = null) : Entity<String>() {
|
||||
var name = ""
|
||||
var signature = ""
|
||||
val uri: String? = null
|
||||
//资源定位符,唯一标识。可以是uil,也可以是别名
|
||||
var uri = ""
|
||||
var order = 0
|
||||
var desc = ""
|
||||
var desc: String? = null
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.synebula.zeus.domain.service.cmd.rbac.resource
|
||||
|
||||
class InterfaceCmd : ResourceCmd() {
|
||||
var system = ""
|
||||
var alive = true
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ import com.synebula.zeus.env.ResourceType
|
||||
|
||||
class PermissionCmd : Command() {
|
||||
var id: String? = null
|
||||
var role = ""
|
||||
var resource = ""
|
||||
var type: ResourceType? = null
|
||||
var authorization = PermissionType.Allow
|
||||
var authority = PermissionType.Allow
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.synebula.zeus.domain.service.impl.rbac.resource
|
||||
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import com.synebula.gaea.domain.repository.IRepository
|
||||
import com.synebula.gaea.domain.service.Service
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import com.synebula.zeus.domain.model.rbac.resource.Permission
|
||||
import com.synebula.zeus.domain.service.contr.rbac.resource.IPermissionService
|
||||
|
||||
class PermissionService(
|
||||
repository: IRepository,
|
||||
converter: IObjectConverter, logger: ILogger
|
||||
) : Service<Permission, String>(Permission::class.java, repository, converter, logger), IPermissionService
|
||||
@@ -1,6 +1,14 @@
|
||||
package com.synebula.zeus.query.contr.resouce
|
||||
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.env.PermissionType
|
||||
import com.synebula.zeus.query.view.resource.InterfaceView
|
||||
|
||||
interface IInterfaceQuery : IQuery {
|
||||
|
||||
fun withPermission(role: String): List<InterfaceView>
|
||||
|
||||
fun withPermission(role: String, system: String?): List<InterfaceView>
|
||||
|
||||
fun authentication(resource: String, role: String): PermissionType?
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
package com.synebula.zeus.query.contr.resouce
|
||||
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.env.PermissionType
|
||||
import com.synebula.zeus.query.view.resource.PageView
|
||||
|
||||
interface IPageQuery : IQuery {
|
||||
|
||||
fun withPermission(role: String): List<PageView>
|
||||
|
||||
fun withPermission(role: String, system: String? ): List<PageView>
|
||||
|
||||
fun authentication(resource: String, role: String): PermissionType?
|
||||
|
||||
fun uriAuthentication(path: String, role: String): PermissionType?
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
package com.synebula.zeus.query.contr.resouce
|
||||
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.env.PermissionType
|
||||
import com.synebula.zeus.env.ResourceType
|
||||
import com.synebula.zeus.query.view.resource.PermissionView
|
||||
|
||||
interface IPermissionQuery : IQuery {
|
||||
|
||||
fun resourcePermissions(resourceType: ResourceType, role: String): List<PermissionView>
|
||||
|
||||
fun authentication(resourceType: ResourceType, resource: String, role: String): PermissionType?
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
package com.synebula.zeus.query.contr.resouce
|
||||
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.zeus.env.PermissionType
|
||||
import com.synebula.zeus.query.view.resource.SystemView
|
||||
|
||||
interface ISystemQuery : IQuery {
|
||||
|
||||
fun withPermission(role: String): List<SystemView>
|
||||
|
||||
fun authentication(resource: String, role: String): PermissionType?
|
||||
}
|
||||
@@ -1,8 +1,42 @@
|
||||
package com.synebula.zeus.query.impl.resouce
|
||||
|
||||
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) : 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<InterfaceView> {
|
||||
return this.withPermission(role, null)
|
||||
|
||||
}
|
||||
|
||||
override fun withPermission(role: String, system: String?): List<InterfaceView> {
|
||||
if (system != null) {
|
||||
val permission = this.systemQuery.authentication(system, role)
|
||||
if (permission == PermissionType.Deny)
|
||||
return listOf()
|
||||
}
|
||||
val params = mutableMapOf<String, Any>()
|
||||
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 ->
|
||||
val permission = permissions.find { p -> i.id == p.resource }
|
||||
permission == null || permission.authority == PermissionType.Allow
|
||||
}
|
||||
}
|
||||
|
||||
override fun authentication(resource: String, role: String): PermissionType? {
|
||||
return this.permissionQuery.authentication(ResourceType.Interface, resource, role)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,47 @@
|
||||
package com.synebula.zeus.query.impl.resouce
|
||||
|
||||
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
|
||||
import org.springframework.data.mongodb.core.query.Criteria
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
|
||||
class PageQuery(template: MongoTemplate) : 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<PageView> {
|
||||
return this.withPermission(role, null)
|
||||
}
|
||||
|
||||
override fun withPermission(role: String, system: String?): List<PageView> {
|
||||
if (system != null) {
|
||||
val permission = this.systemQuery.authentication(system, role)
|
||||
if (permission == PermissionType.Deny)
|
||||
return listOf()
|
||||
}
|
||||
val params = mutableMapOf<String, Any>()
|
||||
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 ->
|
||||
val permission = permissions.find { p -> i.id == p.resource }
|
||||
permission == null || permission.authority == PermissionType.Allow
|
||||
}
|
||||
}
|
||||
|
||||
override fun authentication(resource: String, role: String): PermissionType? {
|
||||
return this.permissionQuery.authentication(ResourceType.Page, resource, role)
|
||||
}
|
||||
|
||||
override fun uriAuthentication(path: String, role: String): PermissionType? {
|
||||
val page = this.template.findOne(Query.query(Criteria.where("uri").`is`(path)),
|
||||
this.clazz, this.collection(this.clazz)) ?: return null
|
||||
return this.authentication(page.id!!, role)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,33 @@
|
||||
package com.synebula.zeus.query.impl.resouce
|
||||
|
||||
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.IPermissionQuery
|
||||
import com.synebula.zeus.query.contr.resouce.ISystemQuery
|
||||
import com.synebula.zeus.query.view.resource.PermissionView
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.query.Criteria
|
||||
import org.springframework.data.mongodb.core.query.Query
|
||||
|
||||
class PermissionQuery(template: MongoTemplate) : MongoQuery(template), IPermissionQuery
|
||||
class PermissionQuery(template: MongoTemplate) : MongoQuery(template), IPermissionQuery {
|
||||
var clazz = PermissionView::class.java
|
||||
var collection = this.collection(this.clazz)
|
||||
|
||||
override fun resourcePermissions(resourceType: ResourceType, role: String): List<PermissionView> {
|
||||
return this.template.find(
|
||||
Query.query(
|
||||
Criteria.where("type").`is`(resourceType)
|
||||
.and("role").`is`(role)
|
||||
), this.clazz, this.collection)
|
||||
}
|
||||
|
||||
override fun authentication(resourceType: ResourceType, resource: String, role: String): PermissionType? {
|
||||
val permission = this.template.findOne(
|
||||
Query.query(
|
||||
Criteria.where("type").`is`(resourceType)
|
||||
.and("resource").`is`(resource)
|
||||
.and("role").`is`(role)
|
||||
), this.clazz, this.collection)
|
||||
return permission?.authority
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,22 @@
|
||||
package com.synebula.zeus.query.impl.resouce
|
||||
|
||||
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.ISystemQuery
|
||||
import com.synebula.zeus.query.view.resource.SystemView
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
|
||||
class SystemQuery(template: MongoTemplate) : MongoQuery(template), ISystemQuery
|
||||
class SystemQuery(template: MongoTemplate, var permissionQuery: PermissionQuery) : MongoQuery(template), ISystemQuery {
|
||||
private val clazz = SystemView::class.java
|
||||
|
||||
override fun withPermission(role: String): List<SystemView> {
|
||||
val systems = this.list(mapOf(), this.clazz)
|
||||
val permissions = this.permissionQuery.resourcePermissions(ResourceType.System, role)
|
||||
return systems.filter { i -> permissions.find { p -> i.id == p.resource }?.authority == PermissionType.Allow }
|
||||
}
|
||||
|
||||
override fun authentication(resource: String, role: String): PermissionType? {
|
||||
return this.permissionQuery.authentication(ResourceType.System, resource, role)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.synebula.zeus.query.view.resource
|
||||
|
||||
class InterfaceView : ResourceView() {
|
||||
var system = ""
|
||||
var alive = true
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import com.synebula.zeus.env.ResourceType
|
||||
|
||||
class PermissionView() {
|
||||
var id: String? = null
|
||||
var role = ""
|
||||
var resource = ""
|
||||
var type: ResourceType? = null
|
||||
var authorization = PermissionType.Allow
|
||||
var authority = PermissionType.Allow
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user