From db6253ca88606d3785a28d4acd4211816a579c4f Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Fri, 5 Jan 2024 00:03:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(MyAuthenticationEntryPoint):=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E6=88=96=E5=AF=86=E7=A0=81=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/MyAuthenticationEntryPoint.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/youlai/system/core/security/exception/MyAuthenticationEntryPoint.java b/src/main/java/com/youlai/system/core/security/exception/MyAuthenticationEntryPoint.java index 2a82ab8a..368bdcef 100644 --- a/src/main/java/com/youlai/system/core/security/exception/MyAuthenticationEntryPoint.java +++ b/src/main/java/com/youlai/system/core/security/exception/MyAuthenticationEntryPoint.java @@ -2,6 +2,7 @@ package com.youlai.system.core.security.exception; import com.youlai.system.common.result.ResultCode; import com.youlai.system.common.util.ResponseUtils; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -26,8 +27,14 @@ public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint { // 资源不存在 ResponseUtils.writeErrMsg(response, ResultCode.RESOURCE_NOT_FOUND); } else { - // 未认证或者token过期 - ResponseUtils.writeErrMsg(response, ResultCode.TOKEN_INVALID); + + if(authException instanceof BadCredentialsException){ + // 用户名或密码错误 + ResponseUtils.writeErrMsg(response, ResultCode.USERNAME_OR_PASSWORD_ERROR); + }else { + // 未认证或者token过期 + ResponseUtils.writeErrMsg(response, ResultCode.TOKEN_INVALID); + } } } }