完善权限认证功能
This commit is contained in:
@@ -8,5 +8,7 @@ interface IInterfaceQuery : IQuery {
|
||||
|
||||
fun withPermission(role: String): List<InterfaceView>
|
||||
|
||||
fun withPermission(role: String, system: String?): List<InterfaceView>
|
||||
|
||||
fun authentication(resource: String, role: String): PermissionType
|
||||
}
|
||||
@@ -8,5 +8,7 @@ interface IPageQuery : IQuery {
|
||||
|
||||
fun withPermission(role: String): List<PageView>
|
||||
|
||||
fun withPermission(role: String, system: String? ): List<PageView>
|
||||
|
||||
fun authentication(resource: String, role: String): PermissionType
|
||||
}
|
||||
@@ -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<InterfaceView> {
|
||||
val interfaces = this.list(mapOf(), this.clazz)
|
||||
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 -> 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 {
|
||||
|
||||
@@ -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<PageView> {
|
||||
val pages = this.list(mapOf(), this.clazz)
|
||||
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 -> 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 {
|
||||
|
||||
@@ -16,7 +16,7 @@ class PermissionQuery(template: MongoTemplate) : MongoQuery(template), IPermissi
|
||||
override fun resourcePermissions(resourceType: ResourceType, role: String): List<PermissionView> {
|
||||
return this.template.find(
|
||||
Query.query(
|
||||
Criteria.where("resourceType").`is`(resourceType)
|
||||
Criteria.where("type").`is`(resourceType)
|
||||
.and("role").`is`(role)
|
||||
), this.clazz, this.collection)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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