Merge branch 'dev' of https://github.com/synebula/zeus into dev

# Conflicts:
#	build.gradle
This commit is contained in:
2022-09-22 21:38:06 +08:00
47 changed files with 224 additions and 300 deletions

View File

@@ -1,11 +1,11 @@
buildscript {
ext {
kotlin_version = '1.3.72'
kotlin_version = '1.6.10'
}
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
@@ -14,42 +14,39 @@ buildscript {
}
}
allprojects {
subprojects {
group 'com.synebula'
version version
}
subprojects {
ext {
version '0.7.1'
gaea_version = '0.13.1'
spring_version = "2.3.0.RELEASE"
version '0.9.0'
gaea_version = '1.4.0'
spring_version = "2.7.0"
}
buildscript {
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
}
repositories {
mavenLocal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
mavenCentral()
}
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'maven-publish'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testApi group: 'junit', name: 'junit', version: '4.12'
}
sourceCompatibility = 1.8

View File

@@ -11,11 +11,12 @@ apply plugin: 'kotlin-spring'
jar.enabled = true //jar SKIPPED问题,不设置可能会无法打jar
dependencies {
compile project(":src:zeus.domain")
compile project(":src:zeus.query")
compile project(":src:zeus.repository")
compile "com.synebula:gaea.app:$gaea_version"
compile "com.synebula:gaea.mongo:$gaea_version"
api project(":src:zeus.domain")
api project(":src:zeus.query")
api project(":src:zeus.repository")
api "com.synebula:gaea.app:$gaea_version"
api "com.synebula:gaea.spring:$gaea_version"
api "com.synebula:gaea.mongodb:$gaea_version"
}

View File

@@ -1,6 +1,6 @@
package com.synebula.zeus.app.component
import com.synebula.gaea.app.component.aop.AppAspect
import com.synebula.gaea.spring.aop.AppAspect
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Pointcut
import org.springframework.stereotype.Component

View File

@@ -1,37 +1,36 @@
package com.synebula.zeus.app.config
import com.google.gson.Gson
import com.synebula.gaea.app.component.security.WebSecurity
import com.synebula.gaea.data.serialization.json.IJsonSerializer
import com.synebula.gaea.domain.model.IAggregateRoot
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.mongo.query.MongoQuery
import com.synebula.gaea.mongo.repository.MongoRepository
import com.synebula.gaea.query.IQuery
import com.synebula.zeus.domain.service.contr.component.IUserNotifier
import com.synebula.gaea.domain.repository.IRepositoryFactory
import com.synebula.gaea.mongodb.query.MongodbQueryFactory
import com.synebula.gaea.mongodb.repository.MongodbRepositoryFactory
import com.synebula.gaea.query.IQueryFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.ComponentScan.Filter
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.context.annotation.FilterType
import org.springframework.data.mongodb.core.MongoTemplate
@Configuration
@ComponentScan(
basePackages = [
"com.synebula.gaea.app.component"
]
basePackages = ["com.synebula.gaea.app.component"],
excludeFilters = [Filter(type = FilterType.ASSIGNABLE_TYPE, classes = [WebSecurity::class])]
)
class ZeusBeans {
@Bean
@Primary
fun <T : IAggregateRoot<String>> repository(template: MongoTemplate)
: IRepository = MongoRepository(template)
@Bean
@Primary
fun <T> query(template: MongoTemplate, logger: ILogger? = null)
: IQuery = MongoQuery(template, logger)
fun repoFactory(template: MongoTemplate): IRepositoryFactory {
return MongodbRepositoryFactory(template)
}
@Bean
fun queryFactory(template: MongoTemplate): IQueryFactory {
return MongodbQueryFactory(template)
}
@Bean
fun gson(): Gson = Gson()

View File

@@ -1,18 +1,10 @@
package com.synebula.zeus.app.config
import com.synebula.gaea.app.component.AllTypeFilter
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.ComponentScan.Filter
import org.springframework.context.annotation.FilterType
import com.synebula.gaea.app.autoconfig.service.ServiceScan
import com.synebula.gaea.mongodb.autoconfig.MongodbRepositoryScan
import org.springframework.stereotype.Component
@Component
@ComponentScan(
basePackages = [
"com.synebula.zeus.domain.service.impl",
"com.synebula.zeus.query.impl",
"com.synebula.zeus.repository"
],
includeFilters = [Filter(type = FilterType.CUSTOM, classes = [AllTypeFilter::class])]
)
@ServiceScan(basePackages = ["com.synebula.zeus.domain.service"])
@MongodbRepositoryScan(basePackages = ["com.synebula.zeus.domain.repository", "com.synebula.zeus.repository", "com.synebula.zeus.query"])
class ZeusServices

View File

@@ -1,17 +1,15 @@
package com.synebula.zeus.app.controller
import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.component.security.TokenManager
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.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.gaea.spring.aop.annotation.Method
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.view.UserView
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
@@ -20,9 +18,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/sign")
class SignInOutApp(override var logger: ILogger?) : IApplication {
@Autowired
lateinit var query: IQuery
class SignInOutApp(override var logger: ILogger) : IApplication {
@Autowired
lateinit var userQuery: IUserQuery
@@ -38,7 +34,7 @@ class SignInOutApp(override var logger: ILogger?) : IApplication {
override var name: String = "用户登录管理"
@MethodName("用户登录")
@Method("用户登录")
@PostMapping("/in")
fun signIn(name: String, password: String, remember: Boolean?): HttpMessage {
return this.safeExecute("用户登录出现异常") {
@@ -54,18 +50,18 @@ class SignInOutApp(override var logger: ILogger?) : IApplication {
}
}
@MethodName("用户登出")
@Method("用户登出")
@PostMapping("/out")
fun signOut(user: String): HttpMessage {
return HttpMessage(user)
}
@MethodName("用户注册")
@Method("用户注册")
@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 list = this.userQuery.list(mapOf(Pair("name", command.name)))
if (list.isEmpty()) {
val message = userService.add(command)
it.data = message.data
} else {

View File

@@ -1,9 +1,9 @@
package com.synebula.zeus.app.controller.rbac
import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.spring.aop.annotation.Method
import com.synebula.zeus.domain.service.cmd.rbac.AuthorityBatchAddCmd
import com.synebula.zeus.domain.service.cmd.rbac.AuthorityCmd
import com.synebula.zeus.domain.service.contr.rbac.IAuthorityService
@@ -19,17 +19,16 @@ class AuthorityApp(
logger: ILogger,
private var authorityService: IAuthorityService
) : Application<AuthorityCmd, AuthorityView, String>(
"权限信息", AuthorityView::class.java,
authorityService, query, logger
"权限信息", authorityService, query, logger
) {
@MethodName("批量添加权限信息")
@Method("批量添加权限信息")
@PostMapping("/batch")
fun add(@RequestBody cmd: AuthorityBatchAddCmd): HttpMessage {
this.authorityService.add(cmd)
return HttpMessage()
}
@MethodName("根据资源和角色删除权限")
@Method("根据资源和角色删除权限")
@DeleteMapping("/{type}/role/{role}")
fun removeByResourceRole(
@PathVariable type: ResourceType,

View File

@@ -2,7 +2,7 @@ package com.synebula.zeus.app.controller.rbac
import com.synebula.gaea.app.Application
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.IQuery
import com.synebula.gaea.query.IQueryFactory
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
@@ -13,9 +13,8 @@ import org.springframework.web.bind.annotation.RestController
@RequestMapping("/groups")
class GroupApp(
service: IGroupService,
query: IQuery,
factory: IQueryFactory,
logger: ILogger
) : Application<GroupCmd, GroupView, String>(
"组信息", GroupView::class.java,
service, query, logger
"用户组信息", service, factory.createQuery(GroupView::class.java), logger
)

View File

@@ -2,7 +2,7 @@ package com.synebula.zeus.app.controller.rbac
import com.synebula.gaea.app.Application
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.query.IQuery
import com.synebula.gaea.query.IQueryFactory
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
@@ -13,9 +13,8 @@ import org.springframework.web.bind.annotation.RestController
@RequestMapping("/roles")
class RoleApp(
service: IRoleService,
query: IQuery,
factory: IQueryFactory,
logger: ILogger
) : Application<RoleCmd, RoleView, String>(
"用户信息", RoleView::class.java,
service, query, logger
"用户信息", service, factory.createQuery(RoleView::class.java), logger
)

View File

@@ -1,13 +1,13 @@
package com.synebula.zeus.app.controller.rbac
import com.synebula.gaea.app.Application
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.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.view.UserView
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
@@ -16,11 +16,10 @@ import org.springframework.web.bind.annotation.*
@RequestMapping("/users")
class UserApp(
service: IUserService,
query: IQuery,
query: IUserQuery,
logger: ILogger
) : Application<UserCmd, UserView, String>(
"用户信息", UserView::class.java,
service, query, logger
"用户信息", service, query, logger
) {
@Autowired
@@ -28,8 +27,8 @@ class UserApp(
override fun add(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 list = this.query.list(mapOf(Pair("name", command.name)))
if (list.isEmpty())
it.from(super.add(command))
else {
it.status = Status.Failure
@@ -54,7 +53,7 @@ class UserApp(
@GetMapping("/{name}/forgot")
fun forgot(@PathVariable name: String): HttpMessage {
return this.safeExecute("遗忘用户密码出现异常") {
val users = this.query.list(mapOf(Pair("name", name)), UserView::class.java)
val users = this.query.list(mapOf(Pair("name", name)))
if (users.isNotEmpty()) {
it.load((this.service as IUserService).forgotPassword(users[0].id))

View File

@@ -1,9 +1,9 @@
package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.spring.aop.annotation.Method
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.contr.resouce.IInterfaceQuery
@@ -20,11 +20,10 @@ class InterfaceApp(
logger: ILogger,
var interfaceQuery: IInterfaceQuery
) : Application<InterfaceCmd, InterfaceView, String>(
"接口信息", InterfaceView::class.java,
service, interfaceQuery, logger
"接口信息", service, interfaceQuery, logger
) {
@MethodName("获取角色系统下有权接口")
@Method("获取角色系统下有权接口")
@GetMapping("/in-system/{system}/authorized/{role}")
fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
@@ -32,7 +31,7 @@ class InterfaceApp(
}
}
@MethodName("获取角色全部有权接口")
@Method("获取角色全部有权接口")
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
@@ -40,7 +39,7 @@ class InterfaceApp(
}
}
@MethodName("验证角色接口权限")
@Method("验证角色接口权限")
@GetMapping("/{api}/authorize/{role}")
fun authorize(@PathVariable api: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg ->

View File

@@ -1,10 +1,10 @@
package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.component.aop.annotation.ModuleName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.spring.aop.annotation.Method
import com.synebula.gaea.spring.aop.annotation.Module
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
@@ -16,17 +16,16 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/pages")
@ModuleName("页面")
@Module("页面")
class PageApp(
service: IPageService,
logger: ILogger,
var pageQuery: IPageQuery
) : Application<PageCmd, PageView, String>(
"页面信息", PageView::class.java,
service, pageQuery, logger
"页面信息", service, pageQuery, logger
) {
@MethodName("获取角色系统下有权页面")
@Method("获取角色系统下有权页面")
@GetMapping("/in-system/{system}/authorized/{role}")
fun authorized(@PathVariable system: String, @PathVariable role: String): HttpMessage {
val msg = HttpMessage()
@@ -34,7 +33,7 @@ class PageApp(
return msg
}
@MethodName("获取角色全部有权页面")
@Method("获取角色全部有权页面")
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
@@ -42,7 +41,7 @@ class PageApp(
}
}
@MethodName("验证角色页面权限")
@Method("验证角色页面权限")
@GetMapping("/{page}/authorize/{role}")
fun authorize(@PathVariable page: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg ->
@@ -50,7 +49,7 @@ class PageApp(
}
}
@MethodName("验证角色URL权限")
@Method("验证角色URL权限")
@GetMapping("/authorize/{role}")
fun uriAuthorize(@PathVariable role: String, uri: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg ->

View File

@@ -1,9 +1,9 @@
package com.synebula.zeus.app.controller.rbac.resource
import com.synebula.gaea.app.Application
import com.synebula.gaea.app.component.aop.annotation.MethodName
import com.synebula.gaea.app.struct.HttpMessage
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.log.ILogger
import com.synebula.gaea.spring.aop.annotation.Method
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
@@ -20,10 +20,9 @@ class SystemApp(
logger: ILogger,
var systemQuery: ISystemQuery
) : Application<SystemCmd, SystemView, String>(
"系统信息", SystemView::class.java,
service, systemQuery, logger
"系统信息", service, systemQuery, logger
) {
@MethodName("获取角色有权系统")
@Method("获取角色有权系统")
@GetMapping("/authorized/{role}")
fun authorized(@PathVariable role: String): HttpMessage {
return this.safeExecute("获取有权资源列表失败") { msg ->
@@ -31,7 +30,7 @@ class SystemApp(
}
}
@MethodName("验证角色系统权限")
@Method("验证角色系统权限")
@GetMapping("/{system}/authorize/{role}")
fun authorize(@PathVariable system: String, @PathVariable role: String): HttpMessage {
return this.safeExecute("获取权限信息失败") { msg ->

View File

@@ -1,6 +1,6 @@
dependencies {
compile project(":src:zeus.env")
compile "com.synebula:gaea:$gaea_version"
api project(":src:zeus.env")
api "com.synebula:gaea:$gaea_version"
}
publishing {

View File

@@ -1,8 +1,9 @@
package com.synebula.zeus.domain.repository
package com.synebula.zeus.domain.repository.rbac
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.zeus.domain.model.rbac.Authority
import com.synebula.zeus.env.ResourceType
interface IAuthorityRepository : IRepository {
interface IAuthorityRepository : IRepository<Authority, String> {
fun removeByResourceRole(type: ResourceType, resource: List<String>, role: String)
}

View File

@@ -0,0 +1,7 @@
package com.synebula.zeus.domain.repository.rbac
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.zeus.domain.model.rbac.User
interface IUserRepository : IRepository<User, String> {
}

View File

@@ -1,4 +1,4 @@
package com.synebula.zeus.domain.service.contr.component
package com.synebula.zeus.domain.service.component
interface IUserNotifier {
fun added(id: String, name: String, token: String)

View File

@@ -1,7 +1,6 @@
package com.synebula.zeus.domain.service.contr.rbac
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.Authority
import com.synebula.zeus.domain.service.cmd.rbac.AuthorityBatchAddCmd
import com.synebula.zeus.env.ResourceType

View File

@@ -1,7 +1,8 @@
package com.synebula.zeus.domain.service.contr.rbac
import com.synebula.gaea.domain.service.Domain
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.Group
interface IGroupService : IService<String> {
}
@Domain(clazz = Group::class)
interface IGroupService : IService<String>

View File

@@ -1,7 +1,8 @@
package com.synebula.zeus.domain.service.contr.rbac
import com.synebula.gaea.domain.service.Domain
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.Role
interface IRoleService : IService<String> {
}
@Domain(clazz = Role::class)
interface IRoleService : IService<String>

View File

@@ -1,7 +1,8 @@
package com.synebula.zeus.domain.service.contr.rbac.resource
import com.synebula.gaea.domain.service.Domain
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.resource.Interface
interface IInterfaceService : IService<String> {
}
@Domain(clazz = Interface::class)
interface IInterfaceService : IService<String>

View File

@@ -1,7 +1,8 @@
package com.synebula.zeus.domain.service.contr.rbac.resource
import com.synebula.gaea.domain.service.Domain
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.resource.Page
interface IPageService : IService<String> {
}
@Domain(clazz = Page::class)
interface IPageService : IService<String>

View File

@@ -1,7 +1,8 @@
package com.synebula.zeus.domain.service.contr.rbac.resource
import com.synebula.gaea.domain.service.Domain
import com.synebula.gaea.domain.service.IService
import com.synebula.zeus.domain.model.rbac.resource.System
interface ISystemService : IService<String> {
}
@Domain(clazz = System::class)
interface ISystemService : IService<String>

View File

@@ -1,23 +1,22 @@
package com.synebula.zeus.domain.service.impl.rbac
import com.synebula.gaea.data.IObjectConverter
import com.synebula.gaea.data.serialization.IObjectMapper
import com.synebula.gaea.domain.service.Service
import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.model.rbac.Authority
import com.synebula.zeus.domain.repository.IAuthorityRepository
import com.synebula.zeus.domain.repository.rbac.IAuthorityRepository
import com.synebula.zeus.domain.service.cmd.rbac.AuthorityBatchAddCmd
import com.synebula.zeus.domain.service.contr.rbac.IAuthorityService
import com.synebula.zeus.env.ResourceType
class AuthorityService(
private var authorityRepository: IAuthorityRepository,
converter: IObjectConverter, logger: ILogger
) : Service<Authority, String>(Authority::class.java, authorityRepository, converter, logger),
mapper: IObjectMapper
) : Service<Authority, String>(Authority::class.java, authorityRepository, mapper),
IAuthorityService {
override fun add(cmd: AuthorityBatchAddCmd) {
val authorities = cmd.resource.map { Authority(cmd.role, it, cmd.type, cmd.authority) }
this.repository.add(authorities, this.clazz)
this.repository.add(authorities)
}
override fun removeByResourceRole(type: ResourceType, resource: List<String>, role: String) {

View File

@@ -1,13 +0,0 @@
package com.synebula.zeus.domain.service.impl.rbac
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.Group
import com.synebula.zeus.domain.service.contr.rbac.IGroupService
class GroupService(
repository: IRepository,
converter: IObjectConverter, logger: ILogger
) : Service<Group, String>(Group::class.java, repository, converter, logger), IGroupService

View File

@@ -1,13 +0,0 @@
package com.synebula.zeus.domain.service.impl.rbac
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.Role
import com.synebula.zeus.domain.service.contr.rbac.IRoleService
class RoleService(
repository: IRepository,
converter: IObjectConverter, logger: ILogger
) : Service<Role, String>(Role::class.java, repository, converter, logger), IRoleService

View File

@@ -1,55 +1,48 @@
package com.synebula.zeus.domain.service.impl.rbac
import com.synebula.gaea.data.IObjectConverter
import com.synebula.gaea.bus.Subscribe
import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.data.message.Message
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.data.serialization.IObjectMapper
import com.synebula.gaea.domain.event.BeforeRemoveEvent
import com.synebula.gaea.domain.repository.IRepositoryFactory
import com.synebula.gaea.domain.service.ICommand
import com.synebula.gaea.domain.service.Service
import com.synebula.gaea.exception.NoticeUserException
import com.synebula.gaea.ext.toMd5
import com.synebula.gaea.log.ILogger
import com.synebula.zeus.domain.model.rbac.Group
import com.synebula.zeus.domain.model.rbac.Role
import com.synebula.zeus.domain.model.rbac.User
import com.synebula.zeus.domain.service.contr.component.IUserNotifier
import com.synebula.zeus.domain.service.contr.rbac.IGroupService
import com.synebula.zeus.domain.service.contr.rbac.IRoleService
import com.synebula.zeus.domain.service.component.IUserNotifier
import com.synebula.zeus.domain.service.contr.rbac.IUserService
import java.util.*
class UserService(
repository: IRepository,
converter: IObjectConverter,
logger: ILogger,
groupService: IGroupService,
roleService: IRoleService,
var userNotifier: IUserNotifier?
) : Service<User, String>(User::class.java, repository, converter, logger), IUserService {
factory: IRepositoryFactory,
mapper: IObjectMapper,
var userNotifier: IUserNotifier?,
var logger: ILogger
) : Service<User, String>(User::class.java, factory.createRepository(User::class.java), mapper), IUserService {
init {
groupService.addBeforeRemoveListener(this.clazz.name) { id ->
val msg = Message()
if (this.repository.count(mapOf(Pair("group", id)), this.clazz) > 0) {
msg.status = Status.Failure
msg.message = "组下还有用户"
}
msg
}
roleService.addBeforeRemoveListener(this.clazz.name) { id ->
val msg = Message()
if (this.repository.count(mapOf(Pair("role", id)), this.clazz) > 0) {
msg.status = Status.Failure
msg.message = "角色下还有用户"
}
msg
}
@Subscribe(["groupBeforeRemoveEvent"])
fun beforeRoleRemove(event: BeforeRemoveEvent<Role, String>) {
if (this.repository.count(mapOf(Pair("role", event.id!!))) > 0)
throw NoticeUserException("角色下还有用户")
}
@Subscribe(["groupBeforeRemoveEvent"])
fun beforeGroupRemove(event: BeforeRemoveEvent<Group, String>) {
if (this.repository.count(mapOf(Pair("group", event.id!!))) > 0)
throw NoticeUserException("用户组下还有用户")
}
override fun add(command: ICommand): DataMessage<String> {
val user = this.convert(command)
val user = this.map(command)
user.password = user.password.toMd5()
user.token = UUID.randomUUID().toString()
user.alive = false
this.repository.add(user, this.clazz)
this.repository.add(user)
userNotifier?.added(user.id!!, user.name, user.token!!)
return DataMessage(user.id!!)
}
@@ -60,28 +53,28 @@ class UserService(
* @param key 用户ID
*/
override fun active(key: String, token: String): DataMessage<Any> {
val user = this.repository.get(key, this.clazz)!!
val user = this.repository.get(key)!!
return if (user.alive) {
DataMessage("用户${user.name}无需重复激活")
} else {
if (token == user.token) {
user.alive = true
user.token = null
this.repository.update(user, this.clazz)
this.repository.update(user)
DataMessage(Status.Success, "用户${user.name}激活成功")
} else {
logger.warn(this, "用户${user.name}激活失败, {key: ${key}, token: ${token}")
logger.warn(this, "用户${user.name}激活失败, {key: ${key}, token: $token")
DataMessage(Status.Failure, "用户${user.name}激活失败, 请从系统发送的邮件链接激活用户")
}
}
}
override fun changePassword(key: String, password: String, newPassword: String): DataMessage<Any> {
val user = this.repository.get(key, this.clazz)!!
val user = this.repository.get(key)!!
return if (user.password == password.toMd5()) {
user.password = newPassword.toMd5()
user.token = null
this.repository.update(user, this.clazz)
this.repository.update(user)
DataMessage()
} else {
logger.warn(this, "用户修改${user.name}密码失败, 旧密码验证不通过")
@@ -91,23 +84,26 @@ class UserService(
override fun resetPassword(key: String, password: String, token: String?): DataMessage<Any> {
val user = this.repository.get(key, this.clazz)!!
val user = this.repository.get(key)!!
return if (token == user.token) {
user.password = password.toMd5()
user.token = null
this.repository.update(user, this.clazz)
this.repository.update(user)
DataMessage()
} else {
logger.warn(this, "用户重置${user.name}密码失败, 系统密码修改令牌:${user.token}, {key: ${key} , token: ${token}")
logger.warn(
this,
"用户重置${user.name}密码失败, 系统密码修改令牌:${user.token}, {key: $key , token: $token"
)
DataMessage(Status.Failure, "用户重置密码失败, 如需重置密码请从系统发送的邮件链接中重置")
}
}
override fun forgotPassword(key: String): DataMessage<String> {
val user = this.repository.get(key, this.clazz)!!
val user = this.repository.get(key)!!
return if (user.alive) {
user.token = UUID.randomUUID().toString()
this.repository.update(user, this.clazz)
this.repository.update(user)
userNotifier?.forgot(user.id!!, user.name, user.token!!)
DataMessage()
} else

View File

@@ -1,13 +0,0 @@
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.Interface
import com.synebula.zeus.domain.service.contr.rbac.resource.IInterfaceService
class InterfaceService(
repository: IRepository,
converter: IObjectConverter, logger: ILogger
) : Service<Interface, String>(Interface::class.java, repository, converter, logger), IInterfaceService

View File

@@ -1,13 +0,0 @@
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.Page
import com.synebula.zeus.domain.service.contr.rbac.resource.IPageService
class PageService(
repository: IRepository,
converter: IObjectConverter, logger: ILogger
) : Service<Page, String>(Page::class.java, repository, converter, logger), IPageService

View File

@@ -1,13 +0,0 @@
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.System
import com.synebula.zeus.domain.service.contr.rbac.resource.ISystemService
class SystemService(
repository: IRepository,
converter: IObjectConverter, logger: ILogger
) : Service<System, String>(System::class.java, repository, converter, logger), ISystemService

View File

@@ -1,5 +1,5 @@
dependencies {
compile "com.synebula:gaea:$gaea_version"
api "com.synebula:gaea:$gaea_version"
}
publishing {

View File

@@ -1,6 +1,6 @@
dependencies {
compile project(":src:zeus.env")
compile "com.synebula:gaea.mongo:$gaea_version"
api project(":src:zeus.env")
api "com.synebula:gaea.mongodb:$gaea_version"
}
publishing {

View File

@@ -5,7 +5,7 @@ import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
import com.synebula.zeus.query.view.AuthorityView
interface IAuthorityQuery : IQuery {
interface IAuthorityQuery : IQuery<AuthorityView, String> {
/**
* 获取角色已授权的资源

View File

@@ -1,10 +1,11 @@
package com.synebula.zeus.query.contr
import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.query.IQuery
import com.synebula.zeus.query.view.SignUserView
import com.synebula.zeus.query.view.UserView
interface IUserQuery {
interface IUserQuery : IQuery<UserView, String> {
/**
* 登录接口
*

View File

@@ -4,7 +4,7 @@ import com.synebula.gaea.query.IQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.query.view.resource.InterfaceView
interface IInterfaceQuery : IQuery {
interface IInterfaceQuery : IQuery<InterfaceView, String> {
fun authorized(role: String): List<InterfaceView>

View File

@@ -4,7 +4,7 @@ import com.synebula.gaea.query.IQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.query.view.resource.PageView
interface IPageQuery : IQuery {
interface IPageQuery : IQuery<PageView, String> {
fun authorized(role: String): List<PageView>

View File

@@ -4,7 +4,7 @@ import com.synebula.gaea.query.IQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.query.view.resource.SystemView
interface ISystemQuery : IQuery {
interface ISystemQuery : IQuery<SystemView, String> {
fun authorized(role: String): List<SystemView>

View File

@@ -1,6 +1,6 @@
package com.synebula.zeus.query.impl
import com.synebula.gaea.mongo.query.MongoQuery
import com.synebula.gaea.mongodb.query.MongodbQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
import com.synebula.zeus.query.contr.IAuthorityQuery
@@ -9,26 +9,27 @@ import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
class AuthorityQuery(template: MongoTemplate) : MongoQuery(template),
IAuthorityQuery {
var clazz = AuthorityView::class.java
class AuthorityQuery(template: MongoTemplate) :
MongodbQuery<AuthorityView, String>(AuthorityView::class.java, template), IAuthorityQuery {
var collection = this.collection(this.clazz)
override fun authorized(resourceType: ResourceType, role: String): List<AuthorityView> {
return this.template.find(
Query.query(
Criteria.where("type").`is`(resourceType)
.and("role").`is`(role)
), this.clazz, this.collection)
Query.query(
Criteria.where("type").`is`(resourceType)
.and("role").`is`(role)
), this.clazz, this.collection
)
}
override fun authorize(resourceType: ResourceType, resource: String, role: String): AuthorityType {
val authority = this.template.findOne(
Query.query(
Criteria.where("type").`is`(resourceType)
.and("resource").`is`(resource)
.and("role").`is`(role)
), this.clazz, this.collection)
Query.query(
Criteria.where("type").`is`(resourceType)
.and("resource").`is`(resource)
.and("role").`is`(role)
), this.clazz, this.collection
)
return authority?.authority ?: AuthorityType.Default
}
}

View File

@@ -3,7 +3,8 @@ package com.synebula.zeus.query.impl
import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.ext.toMd5
import com.synebula.gaea.mongo.whereId
import com.synebula.gaea.mongodb.query.MongodbQuery
import com.synebula.gaea.mongodb.whereId
import com.synebula.zeus.query.contr.IUserQuery
import com.synebula.zeus.query.view.GroupView
import com.synebula.zeus.query.view.RoleView
@@ -14,8 +15,8 @@ import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
import org.springframework.data.mongodb.core.query.isEqualTo
class UserQuery(var template: MongoTemplate) : IUserQuery {
private val clazz = UserView::class.java
class UserQuery(template: MongoTemplate) :
MongodbQuery<UserView, String>(UserView::class.java, template), IUserQuery {
override fun signIn(name: String, password: String): DataMessage<SignUserView> {
val query = Query.query(

View File

@@ -1,19 +1,19 @@
package com.synebula.zeus.query.impl.resouce
import com.synebula.gaea.mongo.query.MongoQuery
import com.synebula.gaea.mongodb.query.MongodbQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
import com.synebula.zeus.query.contr.resouce.IInterfaceQuery
import com.synebula.zeus.query.contr.IAuthorityQuery
import com.synebula.zeus.query.contr.resouce.IInterfaceQuery
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 authorityQuery: IAuthorityQuery, var systemQuery: ISystemQuery) :
MongoQuery(template),
IInterfaceQuery {
private val clazz = InterfaceView::class.java
class InterfaceQuery(
template: MongoTemplate,
var authorityQuery: IAuthorityQuery,
var systemQuery: ISystemQuery
) : MongodbQuery<InterfaceView, String>(InterfaceView::class.java, template), IInterfaceQuery {
override fun authorized(role: String): List<InterfaceView> {
return this.authorized(role, null)
@@ -26,9 +26,9 @@ class InterfaceQuery(template: MongoTemplate, var authorityQuery: IAuthorityQuer
if (authority == AuthorityType.Deny)
return listOf()
}
val params = mutableMapOf<String, Any>()
val params = mutableMapOf<String, String>()
if (system != null) params["system"] = system
val interfaces = this.list(params, this.clazz)
val interfaces = this.list(params)
val authorities = this.authorityQuery.authorized(ResourceType.Interface, role)
return interfaces.filter { i ->
val authority = authorities.find { p -> i.id == p.resource }

View File

@@ -1,10 +1,10 @@
package com.synebula.zeus.query.impl.resouce
import com.synebula.gaea.mongo.query.MongoQuery
import com.synebula.gaea.mongodb.query.MongodbQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
import com.synebula.zeus.query.contr.resouce.IPageQuery
import com.synebula.zeus.query.contr.IAuthorityQuery
import com.synebula.zeus.query.contr.resouce.IPageQuery
import com.synebula.zeus.query.contr.resouce.ISystemQuery
import com.synebula.zeus.query.view.resource.PageView
import org.springframework.data.mongodb.core.MongoTemplate
@@ -12,8 +12,7 @@ import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
class PageQuery(template: MongoTemplate, var authorityQuery: IAuthorityQuery, var systemQuery: ISystemQuery) :
MongoQuery(template), IPageQuery {
private val clazz = PageView::class.java
MongodbQuery<PageView, String>(PageView::class.java, template), IPageQuery {
override fun authorized(role: String): List<PageView> {
return this.authorized(role, null)
@@ -25,9 +24,9 @@ class PageQuery(template: MongoTemplate, var authorityQuery: IAuthorityQuery, va
if (authority == AuthorityType.Deny)
return listOf()
}
val params = mutableMapOf<String, Any>()
val params = mutableMapOf<String, String>()
if (system != null) params["system"] = system
val pages = this.list(params, this.clazz)
val pages = this.list(params)
val authorities = this.authorityQuery.authorized(ResourceType.Page, role)
return pages.filter { i ->
val authority = authorities.find { p -> i.id == p.resource }

View File

@@ -1,18 +1,18 @@
package com.synebula.zeus.query.impl.resouce
import com.synebula.gaea.mongo.query.MongoQuery
import com.synebula.gaea.mongodb.query.MongodbQuery
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
import com.synebula.zeus.query.contr.IAuthorityQuery
import com.synebula.zeus.query.contr.resouce.ISystemQuery
import com.synebula.zeus.query.impl.AuthorityQuery
import com.synebula.zeus.query.view.resource.SystemView
import org.springframework.data.mongodb.core.MongoTemplate
class SystemQuery(template: MongoTemplate, var authorityQuery: AuthorityQuery) : MongoQuery(template), ISystemQuery {
private val clazz = SystemView::class.java
class SystemQuery(template: MongoTemplate, var authorityQuery: IAuthorityQuery) :
MongodbQuery<SystemView, String>(SystemView::class.java, template), ISystemQuery {
override fun authorized(role: String): List<SystemView> {
val systems = this.list(mapOf(), this.clazz)
val systems = this.list(mapOf())
val authorities = this.authorityQuery.authorized(ResourceType.System, role)
return systems.filter { i -> authorities.find { p -> i.id == p.resource }?.authority == AuthorityType.Allow }
}

View File

@@ -1,14 +1,15 @@
package com.synebula.zeus.query.view
import com.synebula.gaea.query.annotation.Table
import com.synebula.gaea.query.annotation.Where
import com.synebula.gaea.query.type.Operator
import com.synebula.gaea.query.Operator
import com.synebula.gaea.query.Table
import com.synebula.gaea.query.Where
@Table("group")
class GroupView {
var id: String? = null
@Where(Operator.like)
@Where(Operator.Like)
var name = ""
var desc = ""

View File

@@ -1,6 +1,6 @@
package com.synebula.zeus.query.view
import com.synebula.gaea.query.annotation.Table
import com.synebula.gaea.query.Table
@Table("role")
class RoleView {

View File

@@ -1,8 +1,8 @@
package com.synebula.zeus.query.view
import com.synebula.gaea.query.annotation.Table
import com.synebula.gaea.query.annotation.Where
import com.synebula.gaea.query.type.Operator
import com.synebula.gaea.query.Operator
import com.synebula.gaea.query.Table
import com.synebula.gaea.query.Where
@Table("user")
class UserView {
@@ -12,7 +12,7 @@ class UserView {
var password: String = ""
@Where(Operator.like)
@Where(Operator.Like)
var realName: String? = null
var phone: String? = null

View File

@@ -1,7 +1,7 @@
dependencies {
compile project(":src:zeus.env")
compile project(":src:zeus.domain")
compile "com.synebula:gaea.mongo:$gaea_version"
api project(":src:zeus.env")
api project(":src:zeus.domain")
api "com.synebula:gaea.mongodb:$gaea_version"
}
publishing {

View File

@@ -1,14 +1,15 @@
package com.synebula.zeus.repository
import com.synebula.gaea.mongo.repository.MongoRepository
import com.synebula.gaea.mongodb.repository.MongodbRepository
import com.synebula.zeus.domain.model.rbac.Authority
import com.synebula.zeus.domain.repository.IAuthorityRepository
import com.synebula.zeus.domain.repository.rbac.IAuthorityRepository
import com.synebula.zeus.env.ResourceType
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
class AuthorityRepository(var template: MongoTemplate) : MongoRepository(template), IAuthorityRepository {
class AuthorityRepository(var template: MongoTemplate) :
MongodbRepository<Authority, String>(Authority::class.java, template), IAuthorityRepository {
override fun removeByResourceRole(type: ResourceType, resource: List<String>, role: String) {
this.template.remove(
Query.query(