调整app包结构

This commit is contained in:
2022-12-01 11:17:35 +08:00
parent ad3cfef96f
commit aadf880052
26 changed files with 145 additions and 68 deletions

View File

@@ -0,0 +1,8 @@
package com.synebula.gaea.app.autoconfig
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
@Configuration
@ComponentScan(basePackages = ["com.synebula.gaea.app.bus", "com.synebula.gaea.app.component", "com.synebula.gaea.app.security"])
class AppAutoConfiguration

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.component.bus
package com.synebula.gaea.app.bus
import com.synebula.gaea.bus.Bus
import org.springframework.stereotype.Component

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.component.bus
package com.synebula.gaea.app.bus
import com.synebula.gaea.bus.DomainSubscribe
import com.synebula.gaea.bus.IBus

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.component.cache
package com.synebula.gaea.app.cache
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder

View File

@@ -1,6 +1,5 @@
package com.synebula.gaea.app.component.poi
import com.synebula.gaea.app.struct.ExcelData
import com.synebula.gaea.data.date.DateTime
import com.synebula.gaea.exception.NoticeUserException
import org.apache.poi.hpsf.Decimal
@@ -40,7 +39,7 @@ object Excel {
val titleFont = wb.createFont()
titleFont.bold = true
titleStyle.setFont(titleFont)
setBorderStyle(titleStyle, BorderStyle.THIN)
setBorderStyle(titleStyle)
//声明列对象
// 第三步在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
@@ -62,7 +61,7 @@ object Excel {
val contentStyle = wb.createCellStyle()
contentStyle.alignment = HorizontalAlignment.LEFT// 创建一个修改居左格式
contentStyle.verticalAlignment = VerticalAlignment.CENTER
setBorderStyle(contentStyle, BorderStyle.THIN)
setBorderStyle(contentStyle)
//创建内容
var col = 0
@@ -146,6 +145,7 @@ object Excel {
this.getCellValue(cell, evaluator).toString().toIntOrNull()
}
}
Double::class.java.name -> {
if (cell.cellType == CellType.NUMERIC) {
cell.numericCellValue
@@ -153,6 +153,7 @@ object Excel {
this.getCellValue(cell, evaluator).toString().toDoubleOrNull()
}
}
Float::class.java.name -> {
if (cell.cellType == CellType.NUMERIC) {
cell.numericCellValue.toFloat()
@@ -160,6 +161,7 @@ object Excel {
this.getCellValue(cell, evaluator).toString().toFloatOrNull()
}
}
Decimal::class.java.name -> {
if (cell.cellType == CellType.NUMERIC) {
cell.numericCellValue.toBigDecimal()
@@ -167,6 +169,7 @@ object Excel {
this.getCellValue(cell, evaluator).toString().toBigDecimalOrNull()
}
}
Boolean::class.java.name -> {
if (cell.cellType == CellType.BOOLEAN) {
cell.booleanCellValue
@@ -174,11 +177,13 @@ object Excel {
this.getCellValue(cell, evaluator).toString().toBoolean()
}
}
Date::class.java.name -> try {
cell.dateCellValue
} catch (ignored: Exception) {
DateTime(cell.stringCellValue).date
}
else -> cell.stringCellValue
}
rowData[columns[c].first] = value
@@ -278,7 +283,7 @@ object Excel {
/**
* 设置cell style的边框
*/
private fun setBorderStyle(style: HSSFCellStyle, borderStyle: BorderStyle) {
private fun setBorderStyle(style: HSSFCellStyle, borderStyle: BorderStyle = BorderStyle.THIN) {
style.borderTop = borderStyle
style.borderRight = borderStyle
style.borderBottom = borderStyle
@@ -297,6 +302,7 @@ object Excel {
numericCellValue
}
}
CellType.STRING -> cell.richStringCellValue.string
CellType.BLANK -> ""
CellType.FORMULA -> evaluator.evaluate(cell).toString()

View File

@@ -0,0 +1,7 @@
package com.synebula.gaea.app.component.poi
class ExcelData(
var title: String = "",
var columnNames: List<String> = listOf(),
var data: List<List<String>> = listOf()
)

View File

@@ -1,7 +1,7 @@
package com.synebula.gaea.app
package com.synebula.gaea.app.controller
import com.synebula.gaea.app.cmd.ICommandApp
import com.synebula.gaea.app.query.IQueryApp
import com.synebula.gaea.app.controller.cmd.ICommandApp
import com.synebula.gaea.app.controller.query.IQueryApp
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.domain.service.ICommand
import com.synebula.gaea.domain.service.IService

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app
package com.synebula.gaea.app.controller
import com.synebula.gaea.app.component.security.session.UserSession
import com.synebula.gaea.app.security.session.UserSession
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.data.message.Status

View File

@@ -1,7 +1,7 @@
package com.synebula.gaea.app
package com.synebula.gaea.app.controller
import com.synebula.gaea.app.cmd.ISimpleCommandApp
import com.synebula.gaea.app.query.IQueryApp
import com.synebula.gaea.app.controller.cmd.ISimpleCommandApp
import com.synebula.gaea.app.controller.query.IQueryApp
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.domain.model.IAggregateRoot
import com.synebula.gaea.domain.service.ISimpleService

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.cmd
package com.synebula.gaea.app.controller.cmd
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.domain.service.ICommand

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.cmd
package com.synebula.gaea.app.controller.cmd
import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.controller.IApplication
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.domain.service.ICommand

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.cmd
package com.synebula.gaea.app.controller.cmd
import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.controller.IApplication
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.data.message.Status
import com.synebula.gaea.domain.model.IAggregateRoot

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.cmd
package com.synebula.gaea.app.controller.cmd
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.domain.model.IAggregateRoot

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.query
package com.synebula.gaea.app.controller.query
import com.synebula.gaea.app.IApplication
import com.synebula.gaea.app.controller.IApplication
import com.synebula.gaea.data.message.HttpMessage
import com.synebula.gaea.query.IQuery
import com.synebula.gaea.query.Params

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.query
package com.synebula.gaea.app.controller.query
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.log.ILogger

View File

@@ -1,9 +1,9 @@
package com.synebula.gaea.app.component.security
package com.synebula.gaea.app.security
import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import com.auth0.jwt.exceptions.TokenExpiredException
import com.google.gson.Gson
import com.synebula.gaea.app.struct.exception.TokenCloseExpireException
import com.synebula.gaea.log.ILogger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
@@ -71,6 +71,25 @@ class TokenManager {
.sign(algorithm)
}
/**
* 校验token是否正确
*
* @param token 密钥
* @param func 自定义验证方法
*/
fun verifyTime(token: String, func: (total: Long, remain: Long) -> Unit) {
try {
val now = Date()
val jwt = JWT.decode(token)
val total = jwt.expiresAt.time - jwt.issuedAt.time //总时间
val remain = jwt.expiresAt.time - now.time //剩余的时间
func(total, remain)
} catch (ex: Exception) {
this.logger.error(this, ex, "解析token出错")
throw ex
}
}
/**
* 校验token是否正确
*
@@ -78,21 +97,16 @@ class TokenManager {
* @return 是否正确
*/
fun <T> verify(token: String, clazz: Class<T>): T? {
try {
val now = Date()
return try {
val algorithm = Algorithm.HMAC256(secret)
val jwt = JWT.decode(token)
val remain = jwt.expiresAt.time - now.time //剩余的时间
val total = jwt.expiresAt.time - jwt.issuedAt.time //总时间
if (remain > 0 && 1.0 * remain / total <= 0.3) //存活时间少于总时间的1/3重新下发
throw TokenCloseExpireException("", JWT.decode(token).getClaim("user").asString())
val result = JWT.require(algorithm).build().verify(token)
val json = result.getClaim(this.payload).asString()
return gson.fromJson(json, clazz)
gson.fromJson(json, clazz)
} catch (ex: TokenExpiredException) {
null
} catch (ex: Exception) {
this.logger.debug(this, ex, "解析token出错")
throw ex
this.logger.error(this, ex, "解析token出错")
throw ex
}
}
@@ -103,20 +117,15 @@ class TokenManager {
* @return 是否正确
*/
fun verify(token: String): String {
try {
val now = Date()
return try {
val algorithm = Algorithm.HMAC256(secret)
val jwt = JWT.decode(token)
val remain = jwt.expiresAt.time - now.time //剩余的时间
val total = jwt.expiresAt.time - jwt.issuedAt.time //总时间
if (remain > 0 && 1.0 * remain / total <= 0.3) //存活时间少于总时间的1/3重新下发
throw TokenCloseExpireException("", JWT.decode(token).getClaim("user").asString())
val result = JWT.require(algorithm).build().verify(token)
return result.getClaim(payload).asString()
result.getClaim(this.payload).asString()
} catch (ex: TokenExpiredException) {
""
} catch (ex: Exception) {
this.logger.debug(this, ex, "解析token出错")
throw ex
this.logger.error(this, ex, "解析token出错")
throw ex
}
}

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.component.security
package com.synebula.gaea.app.security
import com.synebula.gaea.app.component.security.session.UserSessionManager
import com.synebula.gaea.app.security.session.UserSessionManager
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.data.message.Status
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
@@ -40,7 +40,9 @@ class WebAuthorization(
val identity = if (this.storage == "cookie") {
request.cookies.find { it.name == tokenKey }?.value ?: ""
} else {
request.getHeader(tokenKey) ?: ""
var token = request.getHeader(tokenKey) ?: ""
if (token.isEmpty()) token = request.getParameter(tokenKey) ?: ""
token
}
val user = this.userSessionManager.userSession(identity)
if (user != null) {

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.component.security
package com.synebula.gaea.app.security
import com.synebula.gaea.app.component.security.session.UserSessionManager
import com.synebula.gaea.app.security.session.UserSessionManager
import com.synebula.gaea.data.message.HttpMessageFactory
import com.synebula.gaea.data.message.Status
import org.springframework.beans.factory.annotation.Autowired

View File

@@ -0,0 +1,16 @@
package com.synebula.gaea.app.security.session
import com.synebula.gaea.data.permission.AuthorityType
import com.synebula.gaea.data.permission.PermissionType
open class User {
/**
* 权限类型, 根据类型来动态应用[permissions]中的权限信息. 通常配置在角色中
*/
var permissionType = PermissionType.Minimum
/**
* 用户的权限信息. 通常通过角色配置
*/
var permissions = mapOf<String, AuthorityType>()
}

View File

@@ -1,4 +1,4 @@
package com.synebula.gaea.app.component.security.session
package com.synebula.gaea.app.security.session
/**
* 登陆用户会话信息
@@ -27,7 +27,7 @@ class UserSession(var uid: String, var user: Any) {
* 获取指定类型的用户信息
*/
@Suppress("UNCHECKED_CAST")
fun <T> user(): T {
fun <T : User> user(): T {
return user as T
}
}

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.app.component.security.session
package com.synebula.gaea.app.security.session
import com.synebula.gaea.app.component.cache.Cache
import com.synebula.gaea.app.cache.Cache
import com.synebula.gaea.ext.toMd5
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component

View File

@@ -1,5 +0,0 @@
package com.synebula.gaea.app.struct
class ExcelData(var title: String = "",
var columnNames: List<String> = listOf(),
var data: List<List<String>> = listOf())

View File

@@ -1,5 +0,0 @@
package com.synebula.gaea.app.struct.exception
import com.auth0.jwt.exceptions.TokenExpiredException
class TokenCloseExpireException(msg: String, var payload: String) : TokenExpiredException(msg)

View File

@@ -0,0 +1 @@
com.synebula.gaea.app.autoconfig.AppAutoConfiguration

View File

@@ -0,0 +1,10 @@
package com.synebula.gaea.data.permission
/**
* 元素授权类型
*/
enum class AuthorityType {
Default,
Deny,
Allow
}

View File

@@ -0,0 +1,28 @@
package com.synebula.gaea.data.permission
/**
* 角色权限类型
*/
enum class PermissionType {
/**
* 拥有所有权限
*/
All,
/**
* 拥有最大权限
* 不配置无权则有权限
*/
Maximum,
/**
* 最小权限
* 不配置有权则无权限
*/
Minimum,
/**
* 没有任何权限
*/
None
}