【问题标题】:Tomcat is showing wrong http statusTomcat 显示错误的 http 状态
【发布时间】:2019-02-11 20:49:40
【问题描述】:

我需要一些帮助。

我在 SPRING Tool Suite 上构建了一个 API,它会在发布任何对 API 的操作之前验证 JWT。 那是我的 JWT 过滤器:

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain filterChain
    ) throws IOException, ServletException {
    try {

        Authentication authentication = TokenAuthenticationService.getAuthentication((HttpServletRequest) request);
        if (authentication == null) {
            System.out.println("auth  null");
            ((HttpServletResponse) response).sendError(BackEndUtilities.INVALID_TOKEN, BackEndUtilities.ERROR_MSG_INVALID_TOKEN);

        }
        SecurityContextHolder.getContext().setAuthentication((Authentication) authentication);
    }catch(ExpiredJwtException ex) {
        ((HttpServletResponse) response).sendError(BackEndUtilities.INVALID_TOKEN);


    }

    filterChain.doFilter(request, response);
}

当我在身份验证中获得空值时,我发送 HTTP 状态 401 以告知需要登录。

常量 BackEndUtilities.INVALID_TOKEN 是 int 值 401。我在 STS 服务器上运行 API 时得到这个值,但是当我在 TOMCAT 8.5 上部署 war 文件时,我不断得到 HTTP STATUS 403。

在这两种情况下,我都在控制台上获得了字符串“auth null”,它只是在身份验证为空时出现。但为什么 TOMCAT 8.5 正在“改变”状态?

有人知道为什么它一直在发生吗?

【问题讨论】:

    标签: spring http jwt


    【解决方案1】:

    我明白了。

    ((HttpServletResponse) 响应).sendError(BackEndUtilities.INVALID_TOKEN, BackEndUtilities.ERROR_MSG_INVALID_TOKEN);

    这一行停止了 sts 上正在运行的处理,但它不会在 TOMCAT 上发生。

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2014-09-11
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      相关资源
      最近更新 更多