ISimApiAuthChecker 改为按接口注册 + getAll<T>() 解析,移除 SimApiOptions.authCheckers 手动列表
This commit is contained in:
@@ -265,17 +265,14 @@ struct SimApiActionInvoker {
|
||||
SimApiError.error(code: 401, message: "需要登录")
|
||||
}
|
||||
|
||||
// 2. 遍历执行 ISimApiAuthChecker(对齐 C#:先执行 checker,可修改 loginItem,再做类型判断)
|
||||
// 2. 遍历执行 ISimApiAuthChecker(对齐 C# GetServices<ISimApiAuthChecker>():一次解析全部实现)
|
||||
let token = match (context.items.get("LoginToken")) {
|
||||
case Some(v) => if (let s: String <- v) { s } else { "" }
|
||||
case None => ""
|
||||
}
|
||||
let options = context.services.getOrThrow<SimApiOptions>()
|
||||
for (checkerType in options.authCheckers) {
|
||||
let instance = context.services.getOrThrow(checkerType)
|
||||
if (let checker: ISimApiAuthChecker <- instance) {
|
||||
checker.run(loginItem, token)
|
||||
}
|
||||
let checkers = context.services.getAll<ISimApiAuthChecker>()
|
||||
for (checker in checkers) {
|
||||
checker.run(loginItem, token)
|
||||
}
|
||||
|
||||
// 3. 类型权限校验 → 403(对齐 C# Types.Intersect(loginInfo.Type).Any(),支持逗号分隔多类型)
|
||||
|
||||
Reference in New Issue
Block a user