spring-projects / spring-projects/spring-security

PasswordEncoderFactories.createDelegatingPasswordEncoder() is not compatible with LdapShaPasswordEncoder

Open
#5,358 1 comment 4 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

Summary

PasswordEncoderFactories.createDelegatingPasswordEncoder() is creating wrong key for LdapShaPasswordEncoder(). Additionally, DelegatingPasswordEncoder removes the {SHA} prefix before call LdapShaPasswordEncoder.matches() that is expecting for it.

Actual Behavior
  1. PasswordEncoderFactories.createDelegatingPasswordEncoder() creates LdapShaPasswordEncoder() with key ldap but LdapShaPasswordEncoder() expects internally that encoded password starts with SHA or SSHA.
  2. LdapShaPasswordEncoder.matches() expectes that the encoded key is started by prefix {SHA} however DelegatingPasswordEncoder.matches() remove prefix before call LdapShaPasswordEncoder.
Expected Behavior
  1. LdapShaPasswordEncoder() must accept ldap as prefix or PasswordEncoderFactories.createDelegatingPasswordEncoder() instantiate LdapShaPasswordEncoder() with key SHA.
  2. DelegatingPasswordEncoder.matches() doesn't remove prefix or LdapShaPasswordEncoder() doesn't expect for it internally
Configuration

build.gradle
compile('org.springframework.boot:spring-boot-starter-data-ldap')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework:spring-jdbc')
compile('org.springframework.session:spring-session-core')

compile("org.springframework.ldap:spring-ldap-core")
compile("org.springframework.security:spring-security-ldap")
compile("org.springframework:spring-tx")
compile("com.unboundid:unboundid-ldapsdk")

code
DelegatingPasswordEncoder delegatingPasswordEncoder =
(DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(NoOpPasswordEncoder.getInstance());

Version

springBootVersion = '2.0.1.RELEASE'

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 tracing PasswordEncoderFactories.createDelegatingPasswordEncoder(), DelegatingPasswordEncoder.matches(), and LdapShaPasswordEncoder.matches() in the Spring Security source. Use the configuration in build.gradle to reproduce the LDAP encoder setup, then verify that the delegated prefix handling and LDAP SHA matching agree with the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
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.