移除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 {
ext {
version '0.6.0'
gaea_version = '0.7.0'
version '0.6.1'
gaea_version = '0.9.0'
spring_version = "2.3.0.RELEASE"
}

View File

@@ -1,10 +1,12 @@
buildscript {
dependencies {
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: 'kotlin-spring'
jar.enabled = true //jar SKIPPED问题,不设置可能会无法打jar
@@ -14,7 +16,6 @@ dependencies {
compile "com.synebula:gaea.app:$gaea_version"
compile "com.synebula:gaea.mongo:$gaea_version"
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
}
publishing {

View File

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

View File

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

View File

@@ -1,26 +1,54 @@
package com.synebula.zeus.app.controller
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.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.impl.UserQuery
import org.springframework.data.mongodb.core.MongoTemplate
import com.synebula.zeus.query.view.UserView
import org.springframework.beans.factory.annotation.Autowired
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.RestController
@RestController
@RequestMapping("/sign")
open class SignInOutApp(template: MongoTemplate, override var logger: ILogger?) : IApplication {
var query: IUserQuery = UserQuery(template)
class SignInOutApp(override var logger: ILogger?) : IApplication {
@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 = "用户登录管理"
@PostMapping("/in")
fun signIn(name: String, password: String): HttpMessage {
fun signIn(name: String, password: String, remember: Boolean?): HttpMessage {
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 {
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
@RequestMapping("/groups")
open class GroupApp(
class GroupApp(
service: IGroupService,
query: IQuery,
logger: ILogger

View File

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

View File

@@ -1,7 +1,7 @@
package com.synebula.zeus.app.controller.rbac
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.serialization.json.IJsonSerializer
import com.synebula.gaea.log.ILogger
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*
@RestController
@RequestMapping("/users")
open class UserApp(
class UserApp(
service: IUserService,
query: IQuery,
logger: ILogger

View File

@@ -1,7 +1,7 @@
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.app.struct.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
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/interfaces")
open class InterfaceApp(
class InterfaceApp(
service: IInterfaceService,
logger: ILogger,
var interfaceQuery: IInterfaceQuery
@@ -23,24 +23,24 @@ open class InterfaceApp(
service, interfaceQuery, logger
) {
@GetMapping("/in-system/{system}/permission/{role}")
fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage {
@GetMapping("/in-system/{system}/authorized/{role}")
fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.interfaceQuery.withPermission(role, system)
msg.data = this.interfaceQuery.authorized(role, system)
}
}
@GetMapping("/permission/{role}")
fun withPermission(@PathVariable role: String): HttpMessage {
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.interfaceQuery.withPermission(role)
msg.data = this.interfaceQuery.authorized(role)
}
}
@GetMapping("/{api}/authentication/{role}")
fun authentication(@PathVariable api: String, @PathVariable role: String): HttpMessage {
@GetMapping("/{api}/authorize/{role}")
fun authorize(@PathVariable api: String, @PathVariable role: String): HttpMessage {
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
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.struct.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
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/pages")
@ModuleName("页面")
open class PageApp(
class PageApp(
service: IPageService,
logger: ILogger,
var pageQuery: IPageQuery
@@ -25,35 +25,31 @@ open class PageApp(
service, pageQuery, logger
) {
override fun list(params: LinkedHashMap<String, Any>): HttpMessage {
return super.list(params)
}
@GetMapping("/in-system/{system}/permission/{role}")
fun withSystemPermission(@PathVariable system: String, @PathVariable role: String): HttpMessage {
@GetMapping("/in-system/{system}/authorized/{role}")
fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
val msg = HttpMessage()
msg.data = this.pageQuery.withPermission(role, system)
msg.data = this.pageQuery.authorized(role, system)
return msg
}
@GetMapping("/permission/{role}")
fun withPermission(@PathVariable role: String): HttpMessage {
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.pageQuery.withPermission(role)
msg.data = this.pageQuery.authorized(role)
}
}
@GetMapping("/{page}/authentication/{role}")
fun authentication(@PathVariable page: String, @PathVariable role: String): HttpMessage {
@GetMapping("/{page}/authorize/{role}")
fun authorize(@PathVariable page: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg ->
msg.data = this.pageQuery.authentication(page, role)
msg.data = this.pageQuery.authorize(page, role)
}
}
@GetMapping("/authentication/{role}")
fun uriAuthentication(@PathVariable role: String, uri: String): HttpMessage {
@GetMapping("/authorize/{role}")
fun uriAuthorize(@PathVariable role: String, uri: String): HttpMessage {
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
@RequestMapping("/permissions")
open class PermissionApp(
service: IPermissionService,
query: IPermissionQuery,
logger: ILogger
class PermissionApp(
service: IPermissionService,
query: IPermissionQuery,
logger: ILogger
) : Application<PermissionCmd, PermissionView, String>(
"权限信息", PermissionView::class.java,
service, query, logger
"权限信息", PermissionView::class.java,
service, query, logger
)

View File

@@ -1,7 +1,7 @@
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.app.struct.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
@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/systems")
open class SystemApp(
class SystemApp(
service: ISystemService,
logger: ILogger,
var systemQuery: ISystemQuery
@@ -22,17 +22,17 @@ open class SystemApp(
"系统信息", SystemView::class.java,
service, systemQuery, logger
) {
@GetMapping("/permission/{role}")
fun withPermission(@PathVariable role: String): HttpMessage {
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
msg.data = this.systemQuery.withPermission(role)
msg.data = this.systemQuery.authorized(role)
}
}
@GetMapping("/{system}/authentication/{role}")
fun authentication(@PathVariable system: String, @PathVariable role: String): HttpMessage {
@GetMapping("/{system}/authorize/{role}")
fun authorize(@PathVariable system: String, @PathVariable role: String): HttpMessage {
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 {
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 {
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 {
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")
DataMessage(
SignUserView(
user.id, user.name, user.realName ?: "",
user.id, user.realName ?: "",
user.role ?: "", role?.name ?: "",
user.group ?: "", group?.name ?: ""
)

View File

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

View File

@@ -12,16 +12,16 @@ import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
class PageQuery(template: MongoTemplate, var permissionQuery: IPermissionQuery, var systemQuery: ISystemQuery) :
MongoQuery(template), IPageQuery {
MongoQuery(template), IPageQuery {
private val clazz = PageView::class.java
override fun withPermission(role: String): List<PageView> {
return this.withPermission(role, null)
override fun authorized(role: String): List<PageView> {
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) {
val permission = this.systemQuery.authentication(system, role)
val permission = this.systemQuery.authorize(system, role)
if (permission == PermissionType.Deny)
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)
}
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)
override fun uriAuthorize(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.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 {
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 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? {
override fun authorize(resource: String, role: String): PermissionType {
return this.permissionQuery.authentication(ResourceType.System, resource, role)
}
}

View File

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