From b27fd2ae18d29c02191b249c4452feb833ba04a6 Mon Sep 17 00:00:00 2001 From: lbw Date: Wed, 22 Mar 2023 09:45:05 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20fix=20#4773=20?= =?UTF-8?q?=E7=99=BB=E9=99=86=E6=88=90=E5=8A=9F=E6=B8=85=E9=99=A4=E7=B4=AF?= =?UTF-8?q?=E8=AE=A1=E5=A4=B1=E8=B4=A5=E6=AC=A1=E6=95=B0=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PigxAuthenticationFailureEventHandler.java | 2 +- .../PigxAuthenticationSuccessEventHandler.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationFailureEventHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationFailureEventHandler.java index 95e4c5828..3817ad62f 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationFailureEventHandler.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationFailureEventHandler.java @@ -132,7 +132,7 @@ public class PigxAuthenticationFailureEventHandler implements AuthenticationFail * @param username username */ private void recordLoginFailureTimes(String username) { - String key = String.format("%s:%s:%s", CacheConstants.LOGIN_ERROR_TIMES, tenantKeyStrResolver.key(), username); + String key = String.format("%s:%s:%s", tenantKeyStrResolver.key(), CacheConstants.LOGIN_ERROR_TIMES, username); Long deltaTimes = ParamResolver.getLong("LOGIN_ERROR_TIMES", 5L); Long times = redisTemplate.opsForValue().increment(key); diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationSuccessEventHandler.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationSuccessEventHandler.java index aad23a12c..5312fc7f4 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationSuccessEventHandler.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/support/handler/PigxAuthenticationSuccessEventHandler.java @@ -80,9 +80,6 @@ public class PigxAuthenticationSuccessEventHandler implements AuthenticationSucc public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { - // 清除账号历史锁定次数 - clearLoginFailureTimes(authentication); - // 写入登录成功的日志 OAuth2AccessTokenAuthenticationToken accessTokenAuthentication = (OAuth2AccessTokenAuthenticationToken) authentication; Map map = accessTokenAuthentication.getAdditionalParameters(); @@ -90,6 +87,9 @@ public class PigxAuthenticationSuccessEventHandler implements AuthenticationSucc sendSuccessEventLog(request, accessTokenAuthentication, map); } + // 清除账号历史锁定次数 + clearLoginFailureTimes(map); + // 输出token sendAccessTokenResponse(response, authentication); } @@ -127,11 +127,11 @@ public class PigxAuthenticationSuccessEventHandler implements AuthenticationSucc /** * 清空登录失败的记录 - * @param authentication + * @param map */ - private void clearLoginFailureTimes(Authentication authentication) { - String username = authentication.getName(); - String key = String.format("%s:%s:%s", CacheConstants.LOGIN_ERROR_TIMES, tenantKeyStrResolver.key(), username); + private void clearLoginFailureTimes(Map map) { + String key = String.format("%s:%s:%s", tenantKeyStrResolver.key(), CacheConstants.LOGIN_ERROR_TIMES, + MapUtil.getStr(map, SecurityConstants.DETAILS_USERNAME)); redisTemplate.delete(key); }