public class

LdapUserDetailsManager

extends Object
implements UserDetailsManager
java.lang.Object
   ↳ org.springframework.security.ldap.userdetails.LdapUserDetailsManager

Class Overview

An Ldap implementation of UserDetailsManager.

It is designed around a standard setup where users and groups/roles are stored under separate contexts, defined by the "userDnBase" and "groupSearchBase" properties respectively.

In this case, LDAP is being used purely to retrieve information and this class can be used in place of any other UserDetailsService for authentication. Authentication isn't performed directly against the directory, unlike with the LDAP authentication provider setup.

Summary

Public Constructors
LdapUserDetailsManager(ContextSource contextSource)
Public Methods
void changePassword(String oldPassword, String newPassword)
Changes the password for the current user.
void createUser(UserDetails user)
Create a new user with the supplied details.
void deleteUser(String username)
Remove the user with the given login name from the system.
UserDetails loadUserByUsername(String username)
Locates the user based on the username.
void setAttributesToRetrieve(String[] attributesToRetrieve)
void setGroupMemberAttributeName(String groupMemberAttributeName)
Sets the name of the multi-valued attribute which holds the DNs of users who are members of a group.
void setGroupRoleAttributeName(String groupRoleAttributeName)
void setGroupSearchBase(String groupSearchBase)
void setPasswordAttributeName(String passwordAttributeName)
void setRoleMapper(AttributesMapper roleMapper)
void setUserDetailsMapper(UserDetailsContextMapper userDetailsMapper)
void setUsernameMapper(LdapUsernameToDnMapper usernameMapper)
void updateUser(UserDetails user)
Update the specified user.
boolean userExists(String username)
Check if a user with the supplied login name exists in the system.
Protected Methods
void addAuthorities(DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities)
DistinguishedName buildGroupDn(String group)
Creates a DN from a group name.
void copyToContext(UserDetails user, DirContextAdapter ctx)
void removeAuthorities(DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.security.core.userdetails.UserDetailsService
From interface org.springframework.security.provisioning.UserDetailsManager

Public Constructors

public LdapUserDetailsManager (ContextSource contextSource)

Public Methods

public void changePassword (String oldPassword, String newPassword)

Changes the password for the current user. The username is obtained from the security context.

If the old password is supplied, the update will be made by rebinding as the user, thus modifying the password using the user's permissions. If oldPassword is null, the update will be attempted using a standard read/write context supplied by the context source.

Parameters
oldPassword the old password
newPassword the new value of the password.

public void createUser (UserDetails user)

Create a new user with the supplied details.

public void deleteUser (String username)

Remove the user with the given login name from the system.

public UserDetails loadUserByUsername (String username)

Locates the user based on the username. In the actual implementation, the search may possibly be case insensitive, or case insensitive depending on how the implementation instance is configured. In this case, the UserDetails object that comes back may have a username that is of a different case than what was actually requested..

Parameters
username the username identifying the user whose data is required.
Returns
  • a fully populated user record (never null)

public void setAttributesToRetrieve (String[] attributesToRetrieve)

public void setGroupMemberAttributeName (String groupMemberAttributeName)

Sets the name of the multi-valued attribute which holds the DNs of users who are members of a group.

Usually this will be uniquemember (the default value) or member.

Parameters
groupMemberAttributeName the name of the attribute used to store group members.

public void setGroupRoleAttributeName (String groupRoleAttributeName)

public void setGroupSearchBase (String groupSearchBase)

public void setPasswordAttributeName (String passwordAttributeName)

public void setRoleMapper (AttributesMapper roleMapper)

public void setUserDetailsMapper (UserDetailsContextMapper userDetailsMapper)

public void setUsernameMapper (LdapUsernameToDnMapper usernameMapper)

public void updateUser (UserDetails user)

Update the specified user.

public boolean userExists (String username)

Check if a user with the supplied login name exists in the system.

Protected Methods

protected void addAuthorities (DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities)

protected DistinguishedName buildGroupDn (String group)

Creates a DN from a group name.

Parameters
group the name of the group
Returns
  • the DN of the corresponding group, including the groupSearchBase

protected void copyToContext (UserDetails user, DirContextAdapter ctx)

protected void removeAuthorities (DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities)