spring-projects / spring-projects/spring-security

Why treat InternalAuthenticationServiceException as 401 error?

Open
#3,948 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.