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
