-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Spring Security AuthenticationException message inconsistency #26357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is actually the expected behavior. The |
Thanks for your answer, @philwebb I have a couple of questions here, if you don't mind.
The This is all right for me, and looks like this behavior work for "most" exceptions thrown at any point in the application. But, looks like the Spring Security exception handling mechanism uses a different approach, directly managing the HttpServletResponse object, and not letting Spring Boot default exception handling mechanism to do its work. Why are the |
This is the flow that Spring follows to handle exceptions thrown from controller:
What the This ends been handled by At some point (I think that the In the case of the Spring Security exceptions, looks like no body is making the exception available in any of those attributes so the Am I right here? Could Spring Boot register some filter or anything that calls |
With some more debugging I found the reason:
Why is |
Thanks @philwebb for your time and support. |
In general, for any exception, the default behavior if you tell Spring Boot to include the error message via
server.error.include-message=always
is to include theException
message in the JSONmessage
attribute.Looks like with any exception whose ancestor is
org.springframework.security.core.AuthenticationException
(likeAccessDeniedException
,AccountExpiredException
,BadCredentialsException
,...), the behavior differs and themessage
value contains the same value aserror
attribute.Sample pom file:
Sample test class:
Spring Boot Version: 2.4.5
The text was updated successfully, but these errors were encountered: