spring-projects / spring-projects/spring-security

`DelegatingAuthenticationFailureHandler` leaks implementation details in constructor

Open Beginner friendly
#19,305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
The public constructor for DelegatingAuthenticationFailureHandler requires an instance of LinkedHashMap instead of accepting any Map implementation.

Expected behavior
APIs should take collections via the least specific interface, and not force specific implementations.

Suggested fix
Add a new constructor and deprecate the existing one:

public DelegatingAuthenticationFailureHandler(
        Map<Class<? extends AuthenticationException>, AuthenticationFailureHandler> handlers,
        AuthenticationFailureHandler defaultHandler) {
    Assert.notEmpty(handlers, "handlers cannot be null or empty");
    Assert.notNull(defaultHandler, "defaultHandler cannot be null");
    this.handlers = new LinkedHashMap(handlers);
    this.defaultHandler = defaultHandler;
}

If you need to force the caller to guarantee a defined iteration order, Java 21 added SequencedMap.

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 the public constructors of DelegatingAuthenticationFailureHandler and inspect their validation and handler initialization. Add the Map-based API while deprecating the LinkedHashMap-based constructor, preserving existing behavior and accepting other Map implementations. Done means callers are no longer forced to provide LinkedHashMap and the existing validation remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.