From 81f4b0c0016da1f9ae4ccf8f2b430f84c15a7628 Mon Sep 17 00:00:00 2001 From: haoxr <1490493387@qq.com> Date: Wed, 13 Sep 2023 18:23:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(MyAuthenticationEntryPoint.java):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=8D=E5=AD=98=E5=9C=A8=E8=A2=AB`Security?= =?UTF-8?q?`=E6=8B=A6=E6=88=AA=E6=8A=A5=E9=94=99`token`=E6=97=A0=E6=95=88?= =?UTF-8?q?=E6=88=96=E8=80=85=E5=B7=B2=E8=BF=87=E6=9C=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://gitee.com/youlaiorg/youlai-boot/issues/I7DJKL --- .../exception/MyAuthenticationEntryPoint.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/youlai/system/security/exception/MyAuthenticationEntryPoint.java b/src/main/java/com/youlai/system/security/exception/MyAuthenticationEntryPoint.java index 077fe786..ca547d93 100644 --- a/src/main/java/com/youlai/system/security/exception/MyAuthenticationEntryPoint.java +++ b/src/main/java/com/youlai/system/security/exception/MyAuthenticationEntryPoint.java @@ -1,7 +1,7 @@ package com.youlai.system.security.exception; import com.youlai.system.common.result.ResultCode; -import com.youlai.system.util.ResponseUtils; +import com.youlai.system.common.util.ResponseUtils; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.stereotype.Component; @@ -15,12 +15,19 @@ import java.io.IOException; * 认证异常处理 * * @author haoxr - * @since 2022/10/18 + * @since 2.0.0 */ @Component public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint { - @Override + @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { - ResponseUtils.writeErrMsg(response, ResultCode.TOKEN_INVALID); + int status = response.getStatus(); + if (status == HttpServletResponse.SC_NOT_FOUND) { + // 资源不存在 + ResponseUtils.writeErrMsg(response, ResultCode.RESOURCE_NOT_FOUND); + } else { + // 未认证或者token过期 + ResponseUtils.writeErrMsg(response, ResultCode.TOKEN_INVALID); + } } }