Repository navigation
fix(认证缓存): 拒绝停用用户并阻止旧加载回填 - #371
Merged
zhou-hao merged 4 commits intoOct 15, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
默认权限初始化需要兼顾后台任务与外部登录:锁定用户仍可供后台按其权限执行任务,禁用用户不提供默认权限;外部用户凭据只允许启用状态。原本清缓存时的旧加载还可能在失效后回填,让后续请求读到旧认证。
本 PR 在 UserEntity 定义禁用 0、启用 1、锁定 2 三个常量。在默认 initializer 的 doInit 中复用已查询用户,仅排除禁用;不存在返回空,null/其他非禁用状态仍可初始化权限。真实状态写入 SimpleUser.options.status,供可信调用方判断外部凭据准入。Manager 只负责缓存与委派,冷加载查用户一次、热命中不查库;默认密码认证仍只允许启用。初始化接口和原非禁用用户的权限构造、事件语义保持不变。
同时修复本地响应式缓存的加载与失效协调:
PR CI 为原 Redis 集成测试提供 Redis 7 服务和健康检查。相邻测试复用现成自动配置,去除重复用户服务来源、补入实体工厂配置,并使用独立 H2 名称保持上下文隔离;原测试数据与断言保留。
验证
JDK 21.0.10,offline 联合同源 reactor 单次 BUILD SUCCESS:9 类、143 个唯一 testcase,0 failures/errors/skipped。框架默认认证 6 项,应用认证 137 项;真实 HTTP classpath 确认使用当前 hsweb API/default/cache 源码产物,无全局修补 SNAPSHOT 安装。日志为
/tmp/application-three-state-final.log。默认 initializer 的用户读取用 Mono.defer 计实际订阅:非禁用用户冷加载 1 次,热命中新增 0 次。验证三状态、null/未知非禁用状态、实际权限和初始化事件、缺失用户、查询异常、自定义 initializer 委派与原 H2 登录/删除流程。真实 PostgreSQL、Redis、HTTP 验证锁定用户后台读权限、密码登录与旧 Code/委托 Token 拒绝、重新启用、真实删除及回滚,以及机器凭据不受创建人状态影响。可信 User options 经认证复制、权限收窄、二进制与 JSON 序列化保留。
最终提交
7b477fa83的 GitHub Actions CI 已通过:JDK 17、Redis 7,运行原完整变更模块测试命令。缓存源码本轮未改;既有 Guava/Caffeine 参数化回归覆盖单 key、批量及全量失效,旧成功/错误、新 loader 身份、Mono/Flux 未订阅装配窗口与失败重载。此前 8 个新增并发反例修复前稳定失败,修后原断言通过;独立反例结果为 oldRequest=A、currentAfterEviction=B、freshLoads=1,不累加历史测试计数。
兼容边界
默认来源返回空不阻止其他 Authentication Provider 为同 ID 提供认证;自定义 initializer 对自身来源负责,Manager 不额外查询持久用户。外部用户委托的可信来源需提供 User.options.status,缺失或非启用状态拒绝。应用侧接入见 authentication-manager #359,须一并采用本 PR 的 API 常量和 initializer 产物,并通过既有机制刷新旧用户认证缓存;本地缓存也可随服务重启刷新。机器身份不经过该用户加载入口。
状态变更和删除后仍需在事务提交后失效认证缓存。本地缓存不取消既有在途请求;clear 不构成全缓存事务。外部若重写 AbstractReactiveCache 的 protected 两参数 handleLoaderError,需核对恢复行为:加载源错误改在携 owner 的路径处理,该重写仍处理外层装配/转换错误;仓内没有该重写实现。
公共投递见 jetlinks-components #1607。