四郎は最近トークンをチェックすることにより、認証局のためのフレームワーク、すべての裁判官ログインユーザかどうかとして使用されるが、問題を発見し、JwtFilter異常@ControllerAdviceによってキャプチャ(ないコントローラそれまで)が、統一されたデータ形式に戻す必要性をカスタマイズすることができません
@Slf4j
public class JwtFilter extends BasicHttpAuthenticationFilter {
/**
* 执行登录认证
*
* @param request
* @param response
* @param mappedValue
* @return
*/
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
try {
log.info("Filter=====isAccessAllowed========");
executeLogin(request, response);
} catch (Exception e) {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setCharacterEncoding("utf-8");
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", HttpStatus.HTTP_UNAUTHORIZED);
jsonObject.put("msg", "Token失效 请重新登陆");
jsonObject.put("data","");
PrintWriter outputStream = response.getWriter();
outputStream.write(jsonObject.toJSONString());
outputStream.close();
} catch (IOException ex) {
log.error("错误"+ex);
}
}
return true;
}
}
リターン統一アプローチ以下たかっデータを達成するために、フロントエンドに直接フィルタ応答データ
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setCharacterEncoding("utf-8");
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", HttpStatus.HTTP_UNAUTHORIZED);
jsonObject.put("msg", "Token失效 请重新登陆");
jsonObject.put("data","");
PrintWriter outputStream = response.getWriter();
outputStream.write(jsonObject.toJSONString());
outputStream.close();
} catch (IOException ex) {
log.error("错误"+ex);
}
再びこのブログを更新するためのより良い方法があれば