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

Har*_*ana 4 java spring spring-security http-status-codes spring-boot

当我抛出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"
}
Run Code Online (Sandbox Code Playgroud)

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

Ali*_*ani 6

ExceptionTranslationFilter处理安全拦截器抛出的异常并提供合适的HTTP响应:

ExceptionTranslationFilter位于FilterSecurityInterceptor安全过滤器堆栈的上方 .它本身不执行任何实际的安全实施,但处理安全拦截器抛出的异常并提供合适的HTTP响应.

检查出更多的信息Spring Security的文件在这里这里.