无法捕获 InvalidBearerTokenException 异常
来源:8-5 搭建授权服务器(三)授权服务器配置

abulaka
2022-01-04
当 token 过期或是一个非法 token 的时候,在org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider
的private Jwt getJwt(BearerTokenAuthenticationToken bearer)
方法里抛出了InvalidBearerTokenException
异常。
我尝试使用下面的方式想捕获 InvalidBearerTokenException 异常,但是始终捕获不到。想问下是哪里漏东西了吗?
我参考过 Catching exception thrown in AuthenticationProvider
public class SecurityExceptionHandlerSupport implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter printWriter = response.getWriter();
printWriter.write("message");
printWriter.flush();
}
}
写回答
1回答
-
接灰的电子产品
2022-01-05
你为什么不在方法调用的时候catch呢
012022-01-06
相似问题