0.7.0 重构permission为authority并增加一些方法

This commit is contained in:
2021-04-18 00:07:34 +08:00
parent 45d080b27c
commit d0807c56fa
30 changed files with 256 additions and 130 deletions

View File

@@ -0,0 +1,19 @@
package com.synebula.zeus.domain.model.rbac
import com.synebula.gaea.domain.model.AggregateRoot
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
class Authority(override var id: String? = null) : AggregateRoot<String>() {
var role = ""
var resource = ""
var type: ResourceType? = null
var authority = AuthorityType.Allow
constructor(role: String, resource: String, type: ResourceType?, authority: AuthorityType) : this() {
this.role = role
this.resource = resource
this.type = type
this.authority = authority
}
}

View File

@@ -1,12 +0,0 @@
package com.synebula.zeus.domain.model.rbac.resource
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? = null) : AggregateRoot<String>() {
var role = ""
var resource = ""
var type: ResourceType? = null
var authority = PermissionType.Allow
}

View File

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

View File

@@ -0,0 +1,12 @@
package com.synebula.zeus.domain.service.cmd.rbac
import com.synebula.gaea.domain.service.Command
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
class AuthorityBatchAddCmd : Command() {
var role = ""
var resource = listOf<String>()
var type: ResourceType? = null
var authority = AuthorityType.Allow
}

View File

@@ -1,13 +1,13 @@
package com.synebula.zeus.domain.service.cmd.rbac.resource
package com.synebula.zeus.domain.service.cmd.rbac
import com.synebula.gaea.domain.service.Command
import com.synebula.zeus.env.PermissionType
import com.synebula.zeus.env.AuthorityType
import com.synebula.zeus.env.ResourceType
class PermissionCmd : Command() {
class AuthorityCmd : Command() {
var id: String? = null
var role = ""
var resource = ""
var type: ResourceType? = null
var authority = PermissionType.Allow
var authority = AuthorityType.Allow
}

View File

@@ -0,0 +1,14 @@
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
interface IAuthorityService : IService<String> {
fun add(cmd: AuthorityBatchAddCmd)
fun removeByResourceRole(type: ResourceType, resource: List<String>, role: String)
}

View File

@@ -1,7 +0,0 @@
package com.synebula.zeus.domain.service.contr.rbac.resource
import com.synebula.gaea.domain.service.IService
interface IPermissionService : IService<String> {
}

View File

@@ -0,0 +1,26 @@
package com.synebula.zeus.domain.service.impl.rbac
import com.synebula.gaea.data.IObjectConverter
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.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),
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)
}
override fun removeByResourceRole(type: ResourceType, resource: List<String>, role: String) {
this.authorityRepository.removeByResourceRole(type, resource, role)
}
}

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.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