1

Below is my spring security ldap authentication code snippet I am able to authenticate admin user as shown in CASE 2. However, when I am not able to authenticate user1 as shown in CASE 1 for a different base dn.

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        if (ldapEnabled) {
            auth.ldapAuthentication()
                    .userDetailsContextMapper(customContextMapper())
                    .userSearchFilter("(&(objectClass=user)(" + userDn+ "))")
                    .contextSource()
                    .url(ldapProviderUrl + baseDn.trim().replaceAll(" ", "%20"))
                    .managerDn(ldap.username)
                    .managerPassword(ldap.password);
        } else {
            super.configure(auth);
        }
    }

The properties that I use are For case 1

ldap.enabled=true
ldap.provider.url=ldap://XX.XX.XX.XX:389/
ldap.username=CN=XXXXXX,OU=**People**,DC=pserv,DC=local
ldap.password=#########
ldap.base.dn=OU=**User Accounts**,DC=pserv,DC=local
ldap.user.dn.patterns=sAMAccountName={0}
ldap.user.password.attribute=userPassword
ldap.search.base.group=ou=groups

for case 2

ldap.enabled=true
ldap.provider.url=ldap://XX.XX.XX.XX:389/
ldap.username=CN=XXXXXX,OU=**People**,DC=pserv,DC=local
ldap.password=#########
ldap.base.dn=OU=**People**,DC=pserv,DC=local
ldap.user.dn.patterns=sAMAccountName={0}
ldap.user.password.attribute=userPassword
ldap.search.base.group=ou=groups

And my ldap directory tree: (Failed case) CASE 1 :

enter image description here

Working Ldap directory CASE 2:

enter image description here

Questions:

  1. Is it because my ldap.username OU is under "People"?
  2. I fixed the issue for space in the base dn in case 1 nu replacing with %20. But I am not able to authenticate the user. Getting this error
org.springframework.security.authentication.InternalAuthenticationServiceException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100245, problem 2001 (NO_OBJECT), data 0, best match of:
    'DC=pserv,DC=local'
 ]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100245, problem 2001 (NO_OBJECT), data 0, best match of:
    'DC=pserv,DC=local'
 ]; remaining name '/'
0

1 Answer 1

1

Looks like the problem is with spring-security not able to handle basedn with space.

https://github.com/spring-projects/spring-security/issues/2264

Replacing the space in the basedn with %20 helps in successfully building the application. However, the workaround provided above doesn't work for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.