liveBook · Manning

LdapUserDetailsManager

As explained in Spring Security in Action, Second Edition

LdapUserDetailsManager is a Spring Security UserDetailsManager implementation that retrieves and manages user details in an LDAP directory.

LdapUserDetailsManager is Spring Security’s UserDetailsManager implementation for retrieving and managing users in an LDAP directory. Use it when application user management must integrate with LDAP rather than an in-memory or relational store. section 3.3.3 section 3.0

public interface UserDetailsManager extends UserDetailsService {
 void createUser(UserDetails user);
 void updateUser(UserDetails user);
 void deleteUser(String username);
 void changePassword(String oldPassword, String newPassword);
 boolean userExists(String username);
}

The implementation follows the UserDetailsManager contract, including user creation, updates, deletion, password changes, and existence checks. section 3.3.3

Configure an LDAP-backed manager by wiring the directory context and mapping application users to LDAP entries:

  • Define an LDIF file containing the directory base, organizational unit, and test user. section 3.3.3
  • Add Spring Security LDAP and UnboundID LDAP SDK dependencies, then configure the embedded server with the LDIF location, base DN, and port. section 3.3.3
  • Create a DefaultSpringSecurityContextSource, pass it to LdapUserDetailsManager, map usernames with DefaultLdapUsernameToDnMapper, and set the group search base. section 3.3.3

Authenticate against an embedded LDAP directory

Store a user named john under ou=groups with password 12345, expose /hello, and verify authentication with curl -u john:12345 http://localhost:8080/hello. A successful request returns Hello!. section 3.3.3

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains embedded LDAP setup, LDIF data, dependencies, directory context, username mapping, and group search configuration.
Examples
Uses an embedded LDAP server, a server.ldif file containing john, and a curl request to a protected endpoint.
What it assumes
Assumes basic Spring Security configuration and introduces LDAP data, LDIF, directory context, and username mapping.
What you can do after
Operate/configure LDAP-backed authentication with an embedded directory and verify it through a protected endpoint.
How it connects
Connects UserDetailsManager, UserDetailsService, LDAP, LDIF, username-to-DN mapping, and group search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.