spring-projects / spring-projects/spring-security
Why treat InternalAuthenticationServiceException as 401 error?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
When exceptions occur in BasicAuthenticationFilter, most of them should be treated as 401 error.
But InternalAuthenticationServiceException is an internal error, why not treat it is as 500 error?
I think the commence function in BasicAuthenticationEntryPoint should be like as follow:
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
response.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\"");
if (authException instanceof InternalAuthenticationServiceException) {
logger.error("Internal server error. ", authException);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, authException.getMessage());
}
else {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading BasicAuthenticationFilter and BasicAuthenticationEntryPoint, focusing on how authentication exceptions reach commence. Check existing tests for Basic authentication entry-point responses, then verify that InternalAuthenticationServiceException and other authentication failures produce the intended status codes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100