spring-projects / spring-projects/spring-security

SEC-1818: BindAuthenticator and AbstractLdapAuthenticator improvement

Open
#2,048 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: ldap type: jira
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Mikhail Mazursky (Migrated from SEC-1818) said:

I'm using bind authenticator and i want to format userDn not only based on username but also on some other attribute(s) of Authentication. Right now i have two options:

  • copy the entire AbstractLdapAuthenticator and BindAuthenticator sources into custom class and implement the logic;
  • use a workaround-like code with synchronization to avoid data race which lowers potential throughput:
public class CustomLdapAuthenticator extends BindAuthenticator {
...
    @Override
    public DirContextOperations authenticate(Authentication authentication) {

    // Some logic to create custom userDnPattern based on authentication
    String userDnPattern = ...;

    synchronized (this) {
        setUserDnPatterns(new String[] { userDnPattern });
        return super.authenticate(authentication);
    }
}

...
}

To improve this situation i propose to change the argument of AbstractLdapAuthenticator.getUserDns() from String username to Authentication authentication so one will have to override only this method.

p.s. Also i'm not sure why there is "synchronized (userDnFormat)" in this method. What's it protecting from?
p.p.s It would be nice to have a getter for userDnFormat field.

Related gh-9745

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 with AbstractLdapAuthenticator.getUserDns() and the BindAuthenticator.authenticate(Authentication) entry point, then inspect the existing userDnFormat synchronization and related accessors. The change is complete when authentication attributes can participate in user-DN formatting without the reported synchronization workaround, with the existing authenticator behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authentication, backend, security
Issue type
Feature
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.