diff --git a/pjcloud-auth/src/main/java/com/bsd/pjcloud/auth/support/handler/PjcloudAuthenticationFailureEventHandler.java b/pjcloud-auth/src/main/java/com/bsd/pjcloud/auth/support/handler/PjcloudAuthenticationFailureEventHandler.java index 4ef8f487..fd4eacbe 100644 --- a/pjcloud-auth/src/main/java/com/bsd/pjcloud/auth/support/handler/PjcloudAuthenticationFailureEventHandler.java +++ b/pjcloud-auth/src/main/java/com/bsd/pjcloud/auth/support/handler/PjcloudAuthenticationFailureEventHandler.java @@ -29,6 +29,7 @@ import com.bsd.pjcloud.common.data.resolver.ParamResolver; import com.bsd.pjcloud.common.log.event.SysLogEvent; import com.bsd.pjcloud.common.log.util.LogTypeEnum; import com.bsd.pjcloud.common.log.util.SysLogUtils; +import com.bsd.pjcloud.common.security.util.OAuth2ErrorCodesExpand; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -89,10 +90,11 @@ public class PjcloudAuthenticationFailureEventHandler implements AuthenticationF if (OAuth2ParameterNames.PASSWORD.equals(grantType)) { String username = request.getParameter(OAuth2ParameterNames.USERNAME); - // 密码错误记录错误次数 (TOC用户不记录) + // 密码错误记录错误次数 (TOC用户不记录;微信绑定/确认门禁不算失败) String header = WebUtils.getRequest().getHeader(SecurityConstants.HEADER_TOC); - if (exception instanceof OAuth2AuthenticationException - && !SecurityConstants.HEADER_TOC_YES.equals(header)) { + if (exception instanceof OAuth2AuthenticationException oauth2Ex + && !SecurityConstants.HEADER_TOC_YES.equals(header) + && !isWechatGateError(oauth2Ex)) { recordLoginFailureTimes(username); } @@ -131,6 +133,15 @@ public class PjcloudAuthenticationFailureEventHandler implements AuthenticationF publisher.publishEvent(new SysLogEvent(logVo)); } + /** + * PC 微信绑定/扫码确认:密码已校验通过,不应计入登录失败锁定 + */ + private boolean isWechatGateError(OAuth2AuthenticationException exception) { + String errorCode = exception.getError().getErrorCode(); + return OAuth2ErrorCodesExpand.WECHAT_BIND_REQUIRED.equals(errorCode) + || OAuth2ErrorCodesExpand.WECHAT_CONFIRM_REQUIRED.equals(errorCode); + } + /** * 记录登录失败此处,如果操作阈值 调用接口锁定用户 *