Spring Data LDAP

Last Updated : 30 Mar, 2026

Spring Data LDAP is a part of the Spring ecosystem that provides a consistent repository abstraction for working with LDAP directories. It builds on top of Spring LDAP and simplifies CRUD operations and directory access using familiar Spring Data patterns.

  • Provides repository abstraction similar to Spring Data JPA for easy CRUD operations
  • Supports complex search queries with filters, criteria, and pagination
  • Enables transactional support for consistent LDAP operations
  • Offers LDAP templates to simplify common operations like search and update

Dependency

Maven:

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-ldap</artifactId>
<version>3.2.3</version>
</dependency>

Gradle:

dependencies {
implementation 'org.springframework.data:spring-data-ldap:3.2.3'
}

Configuration

The recommended way of configuring Spring LDAP is to use the custom XML configuration namespace. To make this available, you need to include the Spring LDAP namespace declaration in your bean file, as follows:

XML
<beans xmlns="http://www.springframework.org/schema/beans/"
       xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
       xmlns:ldap="http://www.springframework.org/schema/ldap/"
       xsi:schemaLocation="http://www.springframework.org/schema/beans/ https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/ldap/ https://www.springframework.org/schema/ldap/spring-ldap.xsd">

LDAP Entities

  • In Spring LDAP, LDAP entities are Java classes that represent entries in an LDAP directory. Spring LDAP provides a way to map LDAP directory data to Java objects and vice versa.
  • Entities represent LDAP objects and are annotated with @Entry.
  • Entities can have default/custom constructors.
  • Entities are Plain Old Java Objects (POJOs) and don't extend any classes.
  • Attributes of the LDAP object are mapped to properties of the entity using @Attribute.

LDAP Repositories

  • Spring LDAP repositories are a Spring Data abstraction that makes it easy to interact with LDAP directories using the Spring Data repository paradigm. Spring Data repositories provide a consistent and easy-to-use way to perform CRUD operations on LDAP entities.
  • Repositories extend the LdapRepository interface to define CRUD methods.
  • Standard Spring Data methods like findAll(), findById() etc. are supported.
  • Repositories provide a higher level of abstraction over raw LDAP APIs.
Comment

Explore