Over a million developers have joined DZone.

Spring Boot Application Connect to LDAP Userstore

DZone's Guide to

Spring Boot Application Connect to LDAP Userstore

There are detailed instructions on connecting Java Spring Boot applications to LDAP and an example using Apache Directory Studio.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

In this blog post, we are going to connect a sample spring boot application with LDAP-based userstore to do the authentication. 

First, create an LDAP server. I've created a sample server using Apache Directory Studio.

Then create a sample spring-boot application with the following dependencies.


Then in your sample application extend the WebSecurityConfigurerAdapter class and override the below two methods. Provide the connection details as per the LDAP server created above.

public class LdapSecurity extends WebSecurityConfigurerAdapter {

    protected void configure(HttpSecurity httpSecurity) throws Exception {


    protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {

That's it the spring will engage basic authenticate your requests to the webapp.
Now start the app using mvn spring-boot:run or using the java -jar spring-boot-ldap-sample.jar, Access the webapp using http://localhost:8080/ and provide the credentials of a user in the LDAP user base. You'll see the authenticated user's details after a successful authentication.

 Full source to the sample can be found here.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

spring ,ldap ,apache ,web dev

Published at DZone with permission of Aruna Karunarathna, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}