0

I am working on application to authenticate with the LDAP . Am using the spring LDAP template for authenticating but am getting the below response

{
    "message": "[LDAP: error code 32 - 0000208D: NameErr: DSID-031001E5, problem 2001 (NO_OBJECT), data 0, best match of:\n\t''\n\u0000]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031001E5, problem 2001 (NO_OBJECT), data 0, best match of:\n\t''\n\u0000]; remaining name '/'"
}

below are the configuration for spring

<beans:bean id="contextSource"
    class="org.springframework.ldap.core.support.LdapContextSource">
    <beans:property name="base" value="" />
    <beans:property name="url" value="<LDAP-URL>" />
    <beans:property name="userDn" value="<USER-DN>" />
    <beans:property name="password" value="<PASSWORD>" />
</beans:bean>

<beans:bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <beans:constructor-arg ref="contextSource" />
</beans:bean>

Java Code:

AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new       EqualsFilter("sAMAccountName", username));
boolean result = ldapTemplate.authenticate(LdapUtils.emptyLdapName(),               filter.toString(), password);

I am new to LDAP and anyhelp or example would be really great.

2 Answers 2

2

You don't need to specify the full dn in further operations when you've already set the base. Are you sure you have the correct specs for the server? Error 32 is usually screwing up the prefixes or directory configs!

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

2 Comments

Server configs looks fine when i change to bad password it says authentication failed which means it is authenticated and fails after
This is the correct answer. I was passing the full base DN (e.g. ou=users,dc=ad,dc=company,dc=com) to authenticate. Changing this to an empty String worked.
0

Based on the previous correct answer the searchBase must be empty. My correct filter is:

FilterBasedLdapUserSearch userSearch = new FilterBasedLdapUserSearch("", "(&(CN={0})(memberOf=cn=Group-BioBank,OU=HyperV,OU=Services,DC=bob,DC=uk))", contextSource);

This filter works like a charm. (Spring4.x)

Filters explained: https://confluence.atlassian.com/kb/how-to-write-ldap-search-filters-792496933.html

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.