我需要发回两个不同的错误消息以获取无效令牌和过期令牌。
我怎么知道令牌过期错误?我没有找到ExpiredTokenException类 仅找到ExpiringOAuth2RefreshToken类。下面是我的代码示例。
欢迎任何建议或提示!
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
@Component
public class AuthExceptionEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws ServletException {
Map<String, Object> map = new HashMap<String, Object>();
Throwable cause = authException.getCause();
response.setStatus(HttpStatus.SC_OK);
response.setHeader("Content-Type", "application/json;charset=UTF-8");
try {
ResultVO resultVO = new ResultVO();
if(cause instanceof InvalidTokenException) {
resultVO.setStatus(false).setErrmsg("INVALID_TOKEN").setData(null);
response.getWriter().write(JSONObject.toJSONString(resultVO));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}