spring-projects / spring-projects/spring-security

InitializeUserDetailsBeanManagerConfigurer does configure a DaoAuthenticationProvider without Encoder although there are encoders found

Open
#15,751 1 comment 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

Hi,

using spring-security 6.3.3 the InitializeUserDetailsBeanManagerConfigurer does have this code:

PasswordEncoder passwordEncoder = getBeanOrNull(PasswordEncoder.class);

It does look for a password encoder and if this one returns null, a new DaoAuthenticationProvider(); is used.

The problem is, that if more than one encoder is in the context, getBeanOrNull(PasswordEncoder.class) does return null too. This is imho unexpected see here

Expected behavior
My expectation would be, that if more than one PasswordEncoder is found, that the context build fails here and issues an error OR tell the user with a WARN message that the first one found is used.

But simple not using any encoder at all, although there are some configured is a problem. The problem was found, because an upstream project used by me configured its own encoder (which is not that easy to discover with component scanning enabled) and I had myself already one configured and wondered, why NO encoder at all was registered on the DaoAuthenticationProvider - a warning or an error would be nice here.

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 in config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java, especially the PasswordEncoder lookup around lines 95 and 126. Reproduce the configuration with multiple PasswordEncoder beans and verify that the completed behavior no longer silently creates a DaoAuthenticationProvider without an encoder, with an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.