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); }