Lukas Egrmaier
Lukas Egrmaier

Reputation: 91

Spring-boot LDAP - Property 'userDn' not set

I am running a Spring-boot application which authenticates users via our internal LDAP with spring-security-ldap.

By default it binds with LDAP anonymously.

Property 'userDn' not set - anonymous context will be used for read-write operations

But I want the first bind to be with current username.

Where should I specify the userDn attribute?

Thank you for your advice

Upvotes: 4

Views: 10331

Answers (2)

ivan.rosina
ivan.rosina

Reputation: 408

When using spring ldap maybe you started from one many tutorials on the web but main of them uses embedded ldap server; embdedded server uses ldif file and doesn't need the manager credetials.

When connecting to an external ldap server you need to specify userDn setting it via managerDn method. Here the snippet of code

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth.ldapAuthentication().contextSource().managerDn("uid=admin,ou=system")
        .managerPassword("secret")
.......
}

Obviously you need to provide also all the other infos like url, port, etc (and userSearchBase like mvreijn told).

Upvotes: 1

mvreijn
mvreijn

Reputation: 2942

I am not the most knowledgeable person regarding Spring-boot, more so regarding LDAP. That said, your LDAP configuration properties should be mentioned in your application.properties file and are named spring.ldap.*. They are mentioned in the documentation here.

When initializing your authentication provider, you can pass important properties like the Base DN (root to search from) and the filter using:

.userSearchBase("ou=<your users container>").userSearchFilter("(uid={0})")

Most likely, your search filter will be uid={0} or cn={0}.

Upvotes: -1

Related Questions