移除open等多余代码;重命名授权api名称

This commit is contained in:
2021-04-06 20:58:05 +08:00
parent de43b82f24
commit 7f97a1d9a3
20 changed files with 161 additions and 97 deletions

View File

@@ -21,8 +21,8 @@ allprojects {
subprojects { subprojects {
ext { ext {
version '0.6.0' version '0.6.1'
gaea_version = '0.7.0' gaea_version = '0.9.0'
spring_version = "2.3.0.RELEASE" spring_version = "2.3.0.RELEASE"
} }

View File

@@ -1,10 +1,12 @@
buildscript { buildscript {
dependencies { dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$spring_version") classpath("org.springframework.boot:spring-boot-gradle-plugin:$spring_version")
classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version")
} }
} }
apply plugin: 'org.springframework.boot' apply plugin: 'org.springframework.boot'
apply plugin: 'kotlin-spring'
jar.enabled = true //jar SKIPPED问题,不设置可能会无法打jar jar.enabled = true //jar SKIPPED问题,不设置可能会无法打jar
@@ -14,7 +16,6 @@ dependencies {
compile "com.synebula:gaea.app:$gaea_version" compile "com.synebula:gaea.app:$gaea_version"
compile "com.synebula:gaea.mongo:$gaea_version" compile "com.synebula:gaea.mongo:$gaea_version"
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
} }
publishing { publishing {

View File

@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component
@Component @Component
class ZeusAspect : AppAspect() { class ZeusAspect : AppAspect() {
@Pointcut("execution(* com.synebula.zeus.app.controller..*(..))") @Pointcut("target(com.synebula.gaea.app.IApplication)")
override fun func() { override fun func() {
} }
} }

View File

@@ -22,22 +22,22 @@ import org.springframework.data.mongodb.core.MongoTemplate
"com.synebula.gaea.app.component" "com.synebula.gaea.app.component"
] ]
) )
open class ZeusBeans { class ZeusBeans {
@Bean @Bean
@Primary @Primary
open fun <T : IAggregateRoot<String>> repository(template: MongoTemplate) fun <T : IAggregateRoot<String>> repository(template: MongoTemplate)
: IRepository = MongoRepository(template) : IRepository = MongoRepository(template)
@Bean @Bean
@Primary @Primary
open fun <T> query(template: MongoTemplate, logger: ILogger? = null) fun <T> query(template: MongoTemplate, logger: ILogger? = null)
: IQuery = MongoQuery(template, logger) : IQuery = MongoQuery(template, logger)
@Bean @Bean
open fun gson(): Gson = Gson() fun gson(): Gson = Gson()
@Bean @Bean
open fun serializer(gson: Gson): IJsonSerializer { fun serializer(gson: Gson): IJsonSerializer {
return object : IJsonSerializer { return object : IJsonSerializer {
override fun <S> serialize(src: S): String { override fun <S> serialize(src: S): String {
return gson.toJson(src) return gson.toJson(src)

View File

@@ -1,26 +1,54 @@
package com.synebula.zeus.app.controller package com.synebula.zeus.app.controller
import com.synebula.gaea.app.IApplication import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.app.component.security.TokenManager
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.data.serialization.json.IJsonSerializer
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.IQuery
import com.synebula.zeus.domain.service.cmd.rbac.UserCmd
import com.synebula.zeus.domain.service.contr.rbac.IUserService
import com.synebula.zeus.query.contr.IUserQuery import com.synebula.zeus.query.contr.IUserQuery
import com.synebula.zeus.query.impl.UserQuery import com.synebula.zeus.query.view.UserView
import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/sign") @RequestMapping("/sign")
open class SignInOutApp(template: MongoTemplate, override var logger: ILogger?) : IApplication { class SignInOutApp(override var logger: ILogger?) : IApplication {
var query: IUserQuery = UserQuery(template) @Autowired
lateinit var query: IQuery
@Autowired
lateinit var userQuery: IUserQuery
@Autowired
lateinit var userService: IUserService
@Autowired
lateinit var tokenHelper: TokenManager
@Autowired
lateinit var serializer: IJsonSerializer
override var name: String = "用户登录管理" override var name: String = "用户登录管理"
@PostMapping("/in") @PostMapping("/in")
fun signIn(name: String, password: String): HttpMessage { fun signIn(name: String, password: String, remember: Boolean?): HttpMessage {
return this.safeExecute("用户登录出现异常") { return this.safeExecute("用户登录出现异常") {
it.load(this.query.signIn(name, password)) val message = this.userQuery.signIn(name, password)
if (message.data != null) {
val user = message.data
user!!.remember = remember ?: false
val token = tokenHelper.sign(message.data!!)
it.data = token
} else {
it.load(message)
}
} }
} }
@@ -28,4 +56,18 @@ open class SignInOutApp(template: MongoTemplate, override var logger: ILogger?)
fun signOut(user: String): HttpMessage { fun signOut(user: String): HttpMessage {
return HttpMessage(user) return HttpMessage(user)
} }
@PostMapping("/up")
fun signUp(@RequestBody command: UserCmd): HttpMessage {
return this.safeExecute("用户注册出错, 用户信息: ${serializer.serialize(command)}") {
val list = this.query.list(mapOf(Pair("name", command.name)), UserView::class.java)
if (list.count() == 0) {
val message = userService.add(command)
it.data = message.data
} else {
it.status = Status.Failure
it.message = "系统中已存在该用户"
}
}
}
} }

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/groups") @RequestMapping("/groups")
open class GroupApp( class GroupApp(
service: IGroupService, service: IGroupService,
query: IQuery, query: IQuery,
logger: ILogger logger: ILogger

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/roles") @RequestMapping("/roles")
open class RoleApp( class RoleApp(
service: IRoleService, service: IRoleService,
query: IQuery, query: IQuery,
logger: ILogger logger: ILogger

View File

@@ -1,7 +1,7 @@
package com.synebula.zeus.app.controller.rbac package com.synebula.zeus.app.controller.rbac
import com.synebula.gaea.app.Application import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Status
import com.synebula.gaea.data.serialization.json.IJsonSerializer import com.synebula.gaea.data.serialization.json.IJsonSerializer
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*
@RestController @RestController
@RequestMapping("/users") @RequestMapping("/users")
open class UserApp( class UserApp(
service: IUserService, service: IUserService,
query: IQuery, query: IQuery,
logger: ILogger logger: ILogger

View File

@@ -1,7 +1,7 @@
package com.synebula.zeus.app.controller.rbac.resource package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.service.cmd.rbac.resource.InterfaceCmd import com.synebula.zeus.domain.service.cmd.rbac.resource.InterfaceCmd
import com.synebula.zeus.domain.service.contr.rbac.resource.IInterfaceService import com.synebula.zeus.domain.service.contr.rbac.resource.IInterfaceService
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/interfaces") @RequestMapping("/interfaces")
open class InterfaceApp( class InterfaceApp(
service: IInterfaceService, service: IInterfaceService,
logger: ILogger, logger: ILogger,
var interfaceQuery: IInterfaceQuery var interfaceQuery: IInterfaceQuery
@@ -23,24 +23,24 @@ open class InterfaceApp(
service, interfaceQuery, logger service, interfaceQuery, logger
) { ) {
@GetMapping("/in-system/{system}/permission/{role}") @GetMapping("/in-system/{system}/authorized/{role}")
fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage { fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg -> return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.interfaceQuery.withPermission(role, system) msg.data = this.interfaceQuery.authorized(role, system)
} }
} }
@GetMapping("/permission/{role}") @GetMapping("/authorized/{role}")
fun withPermission(@PathVariable role: String): HttpMessage { fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg -> return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.interfaceQuery.withPermission(role) msg.data = this.interfaceQuery.authorized(role)
} }
} }
@GetMapping("/{api}/authentication/{role}") @GetMapping("/{api}/authorize/{role}")
fun authentication(@PathVariable api: String, @PathVariable role: String): HttpMessage { fun authorize(@PathVariable api: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg -> return this.safeExecute("获取权限信息失败") { msg ->
msg.data = this.interfaceQuery.authentication(api, role) msg.data = this.interfaceQuery.authorize(api, role)
} }
} }
} }

View File

@@ -1,8 +1,8 @@
package com.synebula.zeus.app.controller.rbac.resource package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.HttpMessage
import com.synebula.gaea.app.component.aop.annotation.ModuleName import com.synebula.gaea.app.component.aop.annotation.ModuleName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.log.ILogger 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.PageCmd
import com.synebula.zeus.domain.service.contr.rbac.resource.IPageService import com.synebula.zeus.domain.service.contr.rbac.resource.IPageService
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/pages") @RequestMapping("/pages")
@ModuleName("页面") @ModuleName("页面")
open class PageApp( class PageApp(
service: IPageService, service: IPageService,
logger: ILogger, logger: ILogger,
var pageQuery: IPageQuery var pageQuery: IPageQuery
@@ -25,35 +25,31 @@ open class PageApp(
service, pageQuery, logger service, pageQuery, logger
) { ) {
override fun list(params: LinkedHashMap<String, Any>): HttpMessage { @GetMapping("/in-system/{system}/authorized/{role}")
return super.list(params) fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
}
@GetMapping("/in-system/{system}/permission/{role}")
fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage {
val msg = HttpMessage() val msg = HttpMessage()
msg.data = this.pageQuery.withPermission(role, system) msg.data = this.pageQuery.authorized(role, system)
return msg return msg
} }
@GetMapping("/permission/{role}") @GetMapping("/authorized/{role}")
fun withPermission(@PathVariable role: String): HttpMessage { fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg -> return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.pageQuery.withPermission(role) msg.data = this.pageQuery.authorized(role)
} }
} }
@GetMapping("/{page}/authentication/{role}") @GetMapping("/{page}/authorize/{role}")
fun authentication(@PathVariable page: String, @PathVariable role: String): HttpMessage { fun authorize(@PathVariable page: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg -> return this.safeExecute("获取权限信息失败") { msg ->
msg.data = this.pageQuery.authentication(page, role) msg.data = this.pageQuery.authorize(page, role)
} }
} }
@GetMapping("/authentication/{role}") @GetMapping("/authorize/{role}")
fun uriAuthentication(@PathVariable role: String, uri: String): HttpMessage { fun uriAuthorize(@PathVariable role: String, uri: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg -> return this.safeExecute("获取权限信息失败") { msg ->
msg.data = this.pageQuery.uriAuthentication(uri, role) msg.data = this.pageQuery.uriAuthorize(uri, role)
} }
} }

View File

@@ -11,11 +11,11 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/permissions") @RequestMapping("/permissions")
open class PermissionApp( class PermissionApp(
service: IPermissionService, service: IPermissionService,
query: IPermissionQuery, query: IPermissionQuery,
logger: ILogger logger: ILogger
) : Application<PermissionCmd, PermissionView, String>( ) : Application<PermissionCmd, PermissionView, String>(
"权限信息", PermissionView::class.java, "权限信息", PermissionView::class.java,
service, query, logger service, query, logger
) )

View File

@@ -1,7 +1,7 @@
package com.synebula.zeus.app.controller.rbac.resource package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.log.ILogger import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.service.cmd.rbac.resource.SystemCmd import com.synebula.zeus.domain.service.cmd.rbac.resource.SystemCmd
import com.synebula.zeus.domain.service.contr.rbac.resource.ISystemService import com.synebula.zeus.domain.service.contr.rbac.resource.ISystemService
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@RequestMapping("/systems") @RequestMapping("/systems")
open class SystemApp( class SystemApp(
service: ISystemService, service: ISystemService,
logger: ILogger, logger: ILogger,
var systemQuery: ISystemQuery var systemQuery: ISystemQuery
@@ -22,17 +22,17 @@ open class SystemApp(
"系统信息", SystemView::class.java, "系统信息", SystemView::class.java,
service, systemQuery, logger service, systemQuery, logger
) { ) {
@GetMapping("/permission/{role}") @GetMapping("/authorized/{role}")
fun withPermission(@PathVariable role: String): HttpMessage { fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg -> return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.systemQuery.withPermission(role) msg.data = this.systemQuery.authorized(role)
} }
} }
@GetMapping("/{system}/authentication/{role}") @GetMapping("/{system}/authorize/{role}")
fun authentication(@PathVariable system: String, @PathVariable role: String): HttpMessage { fun authorize(@PathVariable system: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg -> return this.safeExecute("获取权限信息失败") { msg ->
msg.data = this.systemQuery.authentication(system, role) msg.data = this.systemQuery.authorize(system, role)
} }
} }
} }

View File

@@ -6,9 +6,9 @@ import com.synebula.zeus.query.view.resource.InterfaceView
interface IInterfaceQuery : IQuery { interface IInterfaceQuery : IQuery {
fun withPermission(role: String): List<InterfaceView> fun authorized(role: String): List<InterfaceView>
fun withPermission(role: String, system: String?): List<InterfaceView> fun authorized(role: String, system: String?): List<InterfaceView>
fun authentication(resource: String, role: String): PermissionType? fun authorize(resource: String, role: String): PermissionType?
} }

View File

@@ -6,11 +6,11 @@ import com.synebula.zeus.query.view.resource.PageView
interface IPageQuery : IQuery { interface IPageQuery : IQuery {
fun withPermission(role: String): List<PageView> fun authorized(role: String): List<PageView>
fun withPermission(role: String, system: String? ): List<PageView> fun authorized(role: String, system: String? ): List<PageView>
fun authentication(resource: String, role: String): PermissionType? fun authorize(resource: String, role: String): PermissionType?
fun uriAuthentication(path: String, role: String): PermissionType? fun uriAuthorize(path: String, role: String): PermissionType?
} }

View File

@@ -6,7 +6,7 @@ import com.synebula.zeus.query.view.resource.SystemView
interface ISystemQuery : IQuery { interface ISystemQuery : IQuery {
fun withPermission(role: String): List<SystemView> fun authorized(role: String): List<SystemView>
fun authentication(resource: String, role: String): PermissionType? fun authorize(resource: String, role: String): PermissionType?
} }

View File

@@ -29,7 +29,7 @@ class UserQuery(var template: MongoTemplate) : IUserQuery {
val group = this.template.findOne(whereId(user.group), GroupView::class.java, "group") val group = this.template.findOne(whereId(user.group), GroupView::class.java, "group")
DataMessage( DataMessage(
SignUserView( SignUserView(
user.id, user.name, user.realName ?: "", user.id, user.realName ?: "",
user.role ?: "", role?.name ?: "", user.role ?: "", role?.name ?: "",
user.group ?: "", group?.name ?: "" user.group ?: "", group?.name ?: ""
) )

View File

@@ -15,14 +15,14 @@ class InterfaceQuery(template: MongoTemplate, var permissionQuery: IPermissionQu
private val clazz = InterfaceView::class.java private val clazz = InterfaceView::class.java
override fun withPermission(role: String): List<InterfaceView> { override fun authorized(role: String): List<InterfaceView> {
return this.withPermission(role, null) return this.authorized(role, null)
} }
override fun withPermission(role: String, system: String?): List<InterfaceView> { override fun authorized(role: String, system: String?): List<InterfaceView> {
if (system != null) { if (system != null) {
val permission = this.systemQuery.authentication(system, role) val permission = this.systemQuery.authorize(system, role)
if (permission == PermissionType.Deny) if (permission == PermissionType.Deny)
return listOf() return listOf()
} }
@@ -36,7 +36,7 @@ class InterfaceQuery(template: MongoTemplate, var permissionQuery: IPermissionQu
} }
} }
override fun authentication(resource: String, role: String): PermissionType? { override fun authorize(resource: String, role: String): PermissionType {
return this.permissionQuery.authentication(ResourceType.Interface, resource, role) return this.permissionQuery.authentication(ResourceType.Interface, resource, role)
} }
} }

View File

@@ -12,16 +12,16 @@ import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.Query
class PageQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery, var systemQuery: ISystemQuery) : class PageQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery, var systemQuery: ISystemQuery) :
MongoQuery(template), IPageQuery { MongoQuery(template), IPageQuery {
private val clazz = PageView::class.java private val clazz = PageView::class.java
override fun withPermission(role: String): List<PageView> { override fun authorized(role: String): List<PageView> {
return this.withPermission(role, null) return this.authorized(role, null)
} }
override fun withPermission(role: String, system: String?): List<PageView> { override fun authorized(role: String, system: String?): List<PageView> {
if (system != null) { if (system != null) {
val permission = this.systemQuery.authentication(system, role) val permission = this.systemQuery.authorize(system, role)
if (permission == PermissionType.Deny) if (permission == PermissionType.Deny)
return listOf() return listOf()
} }
@@ -35,13 +35,15 @@ class PageQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery,
} }
} }
override fun authentication(resource: String, role: String): PermissionType? { override fun authorize(resource: String, role: String): PermissionType {
return this.permissionQuery.authentication(ResourceType.Page, resource, role) return this.permissionQuery.authentication(ResourceType.Page, resource, role)
} }
override fun uriAuthentication(path: String, role: String): PermissionType? { override fun uriAuthorize(path: String, role: String): PermissionType? {
val page = this.template.findOne(Query.query(Criteria.where("uri").`is`(path)), val page = this.template.findOne(
this.clazz, this.collection(this.clazz)) ?: return null Query.query(Criteria.where("uri").`is`(path)),
return this.authentication(page.id!!, role) this.clazz, this.collection(this.clazz)
) ?: return null
return this.authorize(page.id!!, role)
} }
} }

View File

@@ -10,13 +10,13 @@ import org.springframework.data.mongodb.core.MongoTemplate
class SystemQuery(template: MongoTemplate, var permissionQuery: PermissionQuery) : MongoQuery(template), ISystemQuery { class SystemQuery(template: MongoTemplate, var permissionQuery: PermissionQuery) : MongoQuery(template), ISystemQuery {
private val clazz = SystemView::class.java private val clazz = SystemView::class.java
override fun withPermission(role: String): List<SystemView> { override fun authorized(role: String): List<SystemView> {
val systems = this.list(mapOf(), this.clazz) val systems = this.list(mapOf(), this.clazz)
val permissions = this.permissionQuery.resourcePermissions(ResourceType.System, role) val permissions = this.permissionQuery.resourcePermissions(ResourceType.System, role)
return systems.filter { i -> permissions.find { p -> i.id == p.resource }?.authority == PermissionType.Allow } return systems.filter { i -> permissions.find { p -> i.id == p.resource }?.authority == PermissionType.Allow }
} }
override fun authentication(resource: String, role: String): PermissionType? { override fun authorize(resource: String, role: String): PermissionType {
return this.permissionQuery.authentication(ResourceType.System, resource, role) return this.permissionQuery.authentication(ResourceType.System, resource, role)
} }
} }

View File

@@ -1,11 +1,34 @@
package com.synebula.zeus.query.view package com.synebula.zeus.query.view
class SignUserView( class SignUserView(
var id: String = "", /**
var name: String = "", * 用户id
var realName: String = "", */
var role: String = "", var uid: String = "",
var roleName: String = "",
var group: String = "", /**
var groupName: String = "" * 用户名称
*/
var uname: String = "",
/**
* 角色id
*/
var rid: String = "",
/**
* 角色名称
*/
var rname: String = "",
/**
* 组id
*/
var gid: String = "",
/**
* 组名称
*/
var gname: String = "",
var remember: Boolean = false
) )