spring-projects / spring-projects/spring-security

ActiveDirectoryLdapAuthenticationProvider not working with custom searchFilter since domain is added to username

Open
#3,960 9 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

Summary

Since SEC-1915 the ActiveDirectoryLdapAuthenticationProvider provides means to insert a custom searchFilter to select which user is taken from Active Directory.

The example given is searching by 'sAMAccountName' instead of 'userPrincipalName' but even this example is not working in real Active Directories.

Actual Behavior

There are two steps involved:
1.) Binding to the Active Directory Server: Here the domain Part is added to the given Username to bind. This works like a charm
2.) Finding the User in the Directory to Fill in all userDetails. This does not work at the moment, since the domain Part is also added to the username before feeding it to the given searchFilter (e.g. (sAMAccountName={0}). The User is not found since sAMAccountnames do not contain domain information. The authentication fails.

There is a test within the project, but it uses a mock that is not modeled to copy real AD behaviour: it always finds the sAMAccountName whether provided with or without the domain part ...

Expected Behavior

The ActiveDirectoryLdapAuthenticationProvider should use the domain Part ONLY for binding to the directory, for queryiing the username should be used AS-IS.

Expected behaviour is that (sAMAccountName={0}) searchFilter works against real Active Directory

Configuration

AD Server Windows 2013

Version

Verified in 3.2.9.RELEASE, Code looks the same in Current 4.x versions

Sample
AbstractLdapAuthenticationProvider ad = AbstractLdapAuthenticationProvider('domain.com','ldaps://active-directory');
ad.setSearchFilter("(sAMAccountName={0})");

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

Read ActiveDirectoryLdapAuthenticationProvider and the existing test that uses a mock Active Directory; trace how the domain is applied during binding and searchFilter expansion. The work is done when binding still uses the domain, while a custom sAMAccountName filter receives the username without domain information and the test reflects that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.