feat(auth): 优化租户过期验证逻辑并统一Redis key格式

- 修改登录失败/成功处理中的Redis key格式,移除tenantKeyStrResolver依赖
- 简化RedisUtils.execute调用方式,移除冗余的RedisCallback类型声明
- 在SysTenantServiceImpl中增加租户状态和时间有效性过滤
- 重构TenantContextHolderFilter的租户验证逻辑,增加remoteTenantService备用查询
- 调整租户无效时的HTTP状态码为426并优化响应内容类型
This commit is contained in:
PIG AI committed 2025-07-04 16:41:06 +08:00
1 parent 00efa97eef
commit 2d7d089fcd
4 files changed
+28 -14

No files matched your search

@@ -36,7 +36,6 @@ import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -131,11 +130,11 @@ public class PigxAuthenticationFailureEventHandler implements AuthenticationFail
* @param username username
*/
private void recordLoginFailureTimes(String username) {
String key = String.format("%s:%s:%s", tenantKeyStrResolver.key(), CacheConstants.LOGIN_ERROR_TIMES, username);
String key = String.format("%s%s:%s", CacheConstants.GLOBALLY, CacheConstants.LOGIN_ERROR_TIMES, username);
Long deltaTimes = ParamResolver.getLong("LOGIN_ERROR_TIMES", 5L);
// 使用 RedisUtils 执行原生 Redis 命令进行递增操作
Long times = RedisUtils.execute((RedisCallback<Long>) connection ->
Long times = RedisUtils.execute(connection ->
connection.incr(key.getBytes())
);
@@ -128,7 +128,7 @@ public class PigxAuthenticationSuccessEventHandler implements AuthenticationSucc
* @param map
*/
private void clearLoginFailureTimes(Map<String, Object> map) {
String key = String.format("%s:%s:%s", tenantKeyStrResolver.key(), CacheConstants.LOGIN_ERROR_TIMES,
String key = String.format("%s%s:%s", CacheConstants.GLOBALLY, CacheConstants.LOGIN_ERROR_TIMES,
MapUtil.getStr(map, SecurityConstants.DETAILS_USERNAME));
RedisUtils.delete(key);
}