有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何将Spring Security BadCredentialsException映射到HTTP 401代码

当我抛出org.springframework.security.authentication.BadCredentialsException异常时,在客户机中它将显示401,如下所示

{
  "timestamp": "2016-03-29T09:07:50.866+0000",
  "status": 401,
  "error": "Unauthorized",
  "message": "Some message",
  "path": "/test/service1/getAll"
}

我想知道BadCredentialsException映射到HTTP 401状态码的位置和方式


共 (1) 个答案

  1. # 1 楼答案

    ^{}处理安全拦截器引发的异常,并提供合适的HTTP响应:

    The ExceptionTranslationFilter sits above the FilterSecurityInterceptor in the security filter stack. It doesn’t do any actual security enforcement itself, but handles exceptions thrown by the security interceptors and provides suitable and HTTP responses.

    查看Spring安全文档以获取更多信息herehere