mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 14:09:00 +08:00
feat(auth): 优化租户过期验证逻辑并统一Redis key格式
- 修改登录失败/成功处理中的Redis key格式,移除tenantKeyStrResolver依赖 - 简化RedisUtils.execute调用方式,移除冗余的RedisCallback类型声明 - 在SysTenantServiceImpl中增加租户状态和时间有效性过滤 - 重构TenantContextHolderFilter的租户验证逻辑,增加remoteTenantService备用查询 - 调整租户无效时的HTTP状态码为426并优化响应内容类型
This commit is contained in:
1 parent
00efa97eef
commit
2d7d089fcd
4 files changed
+28
-14
No files matched your search
+2
-3
@@ -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())
|
||||
);
|
||||
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user