spring-projects / spring-projects/spring-security

BasicAuthenticationFilter breaks SwitchUserFilter

Open
#9,027 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: web status: feedback-provided
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
When using the SwitchUserFilter with Basic auth, BasicAuthenticationFilter.authenticationIsRequired() fails when switched forcing a re-authentication.

To Reproduce
Enable both basic auth and the SwitchUserFilter, switch to a new user and then make another request.
BasicAuthenticationFilter.authenticationIsRequired() will return true since the current logged in user doesn't match the WWW-Authenticate header

Expected behavior
BasicAuthenticationFilter.authenticationIsRequired() should also check if existingAuth has a GrantedAuthority of ROLE_PREVIOUS_ADMINISTRATOR, and check that username against username

		if (existingAuth instanceof UsernamePasswordAuthenticationToken
				&& !existingAuth.getName().equals(username)) {
			return true;
		}

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 at BasicAuthenticationFilter.authenticationIsRequired() and reproduce the behavior with Basic auth and SwitchUserFilter enabled, switching to another user before making a second request. Done means a switched user does not trigger an unnecessary re-authentication when the existing authentication has ROLE_PREVIOUS_ADMINISTRATOR and matches the requested username.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.