fix(MyAuthenticationEntryPoint.java): 接口不存在被Security拦截报错token无效或者已过期问题
Closes https://gitee.com/youlaiorg/youlai-boot/issues/I7DJKL
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package com.youlai.system.security.exception;
|
package com.youlai.system.security.exception;
|
||||||
|
|
||||||
import com.youlai.system.common.result.ResultCode;
|
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.core.AuthenticationException;
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -15,12 +15,19 @@ import java.io.IOException;
|
|||||||
* 认证异常处理
|
* 认证异常处理
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @since 2022/10/18
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
@Override
|
@Override
|
||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
||||||
|
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);
|
ResponseUtils.writeErrMsg(response, ResultCode.TOKEN_INVALID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user