fix: 系统性修复安全问题、性能问题和错误处理
安全问题修复: - X-Forwarded-For越界检查(auth.go) - checkTokenStatus Context参数传递(auth.go) - Type Assertion安全检查(auth.go) 性能问题修复: - TokenCache过期清理机制 - BruteForceProtection过期清理 - InMemoryIdempotencyStore过期清理 错误处理修复: - AuditStore.Emit返回error - domain层emitAudit辅助方法 - List方法返回空slice而非nil - 金额/价格负数验证 架构一致性: - 统一使用model.RoleHierarchyLevels 新增功能: - Alert API完整实现(CRUD+Resolve) - pkg/error错误码集中管理
This commit is contained in:
@@ -15,6 +15,7 @@ const (
|
||||
)
|
||||
|
||||
// 角色层级常量(用于权限优先级判断)
|
||||
// 注意:这些常量值必须与 RoleHierarchyLevels map保持一致
|
||||
const (
|
||||
LevelSuperAdmin = 100
|
||||
LevelOrgAdmin = 50
|
||||
@@ -25,6 +26,33 @@ const (
|
||||
LevelViewer = 10
|
||||
)
|
||||
|
||||
// RoleHierarchyLevels 角色层级映射(用于权限验证)
|
||||
// 层级越高,权限越大。superset角色可以执行subset角色的操作。
|
||||
// 注意:此map的值必须与上述常量保持一致!
|
||||
var RoleHierarchyLevels = map[string]int{
|
||||
"super_admin": LevelSuperAdmin, // 100 - 超级管理员
|
||||
"org_admin": LevelOrgAdmin, // 50 - 组织管理员
|
||||
"supply_admin": LevelSupplyAdmin, // 40 - 供应商管理员
|
||||
"consumer_admin": LevelSupplyAdmin, // 40 - 消费者管理员(同供应商)
|
||||
"operator": LevelOperator, // 30 - 操作员
|
||||
"developer": LevelDeveloper, // 20 - 开发者
|
||||
"finops": LevelFinops, // 20 - 财务运营
|
||||
"supply_operator": LevelOperator, // 30 - 供应商操作员
|
||||
"supply_finops": LevelFinops, // 20 - 供应商财务
|
||||
"supply_viewer": LevelViewer, // 10 - 供应商查看者
|
||||
"consumer_operator": LevelOperator, // 30 - 消费者操作员
|
||||
"consumer_viewer": LevelViewer, // 10 - 消费者查看者
|
||||
"viewer": LevelViewer, // 10 - 通用查看者
|
||||
}
|
||||
|
||||
// GetRoleLevelByCode 根据角色代码获取层级数值
|
||||
func GetRoleLevelByCode(roleCode string) int {
|
||||
if level, ok := RoleHierarchyLevels[roleCode]; ok {
|
||||
return level
|
||||
}
|
||||
return 0 // 默认最低级别
|
||||
}
|
||||
|
||||
// 角色错误定义
|
||||
var (
|
||||
ErrInvalidRoleCode = errors.New("invalid role code: cannot be empty")
|
||||
|
||||
Reference in New Issue
Block a user