Class LdapUserDetailsManager
- All Implemented Interfaces:
- UserDetailsService,- 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.
- Since:
- 2.0
- 
Constructor SummaryConstructorsConstructorDescriptionLdapUserDetailsManager(org.springframework.ldap.core.ContextSource contextSource) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaddAuthorities(LdapName userDn, Collection<? extends GrantedAuthority> authorities) protected voidaddAuthorities(org.springframework.ldap.core.DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities) Deprecated.protected org.springframework.ldap.core.DistinguishedNamebuildGroupDn(String group) Deprecated.protected LdapNamebuildGroupName(String group) voidchangePassword(String oldPassword, String newPassword) Changes the password for the current user.protected voidcopyToContext(UserDetails user, org.springframework.ldap.core.DirContextAdapter ctx) voidcreateUser(UserDetails user) Create a new user with the supplied details.voiddeleteUser(String username) Remove the user with the given login name from the system.loadUserByUsername(String username) Locates the user based on the username.protected voidremoveAuthorities(LdapName userDn, Collection<? extends GrantedAuthority> authorities) protected voidremoveAuthorities(org.springframework.ldap.core.DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities) Deprecated.voidsetAttributesToRetrieve(String[] attributesToRetrieve) voidsetGroupMemberAttributeName(String groupMemberAttributeName) Sets the name of the multi-valued attribute which holds the DNs of users who are members of a group.voidsetGroupRoleAttributeName(String groupRoleAttributeName) voidsetGroupSearchBase(String groupSearchBase) voidsetPasswordAttributeName(String passwordAttributeName) voidsetRoleMapper(org.springframework.ldap.core.AttributesMapper roleMapper) voidsetRolePrefix(String rolePrefix) Sets the role prefix used when converting authorities.voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.voidsetUsePasswordModifyExtensionOperation(boolean usePasswordModifyExtensionOperation) Sets the method by which a user's password gets modified.voidsetUserDetailsMapper(UserDetailsContextMapper userDetailsMapper) voidsetUsernameMapper(LdapUsernameToDnMapper usernameMapper) voidupdateUser(UserDetails user) Update the specified user.booleanuserExists(String username) Check if a user with the supplied login name exists in the system.
- 
Constructor Details- 
LdapUserDetailsManagerpublic LdapUserDetailsManager(org.springframework.ldap.core.ContextSource contextSource) 
 
- 
- 
Method Details- 
loadUserByUsernameDescription copied from interface:UserDetailsServiceLocates the user based on the username. In the actual implementation, the search may possibly be case sensitive, or case insensitive depending on how the implementation instance is configured. In this case, theUserDetailsobject that comes back may have a username that is of a different case than what was actually requested..- Specified by:
- loadUserByUsernamein interface- UserDetailsService
- Parameters:
- username- the username identifying the user whose data is required.
- Returns:
- a fully populated user record (never null)
 
- 
changePasswordChanges the password for the current user. The username is obtained from the security context.There are two supported strategies for modifying the user's password depending on the capabilities of the corresponding LDAP server. Configured one way, this method will modify the user's password via the LDAP Password Modify Extended Operation . See setUsePasswordModifyExtensionOperation(boolean)for details.By default, though, 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 oldPasswordis null, the update will be attempted using a standard read/write context supplied by the context source.- Specified by:
- changePasswordin interface- UserDetailsManager
- Parameters:
- oldPassword- the old password
- newPassword- the new value of the password.
 
- 
createUserDescription copied from interface:UserDetailsManagerCreate a new user with the supplied details.- Specified by:
- createUserin interface- UserDetailsManager
 
- 
updateUserDescription copied from interface:UserDetailsManagerUpdate the specified user.- Specified by:
- updateUserin interface- UserDetailsManager
 
- 
deleteUserDescription copied from interface:UserDetailsManagerRemove the user with the given login name from the system.- Specified by:
- deleteUserin interface- UserDetailsManager
 
- 
userExistsDescription copied from interface:UserDetailsManagerCheck if a user with the supplied login name exists in the system.- Specified by:
- userExistsin interface- UserDetailsManager
 
- 
buildGroupDnDeprecated.Creates a DN from a group name.- Parameters:
- group- the name of the group
- Returns:
- the DN of the corresponding group, including the groupSearchBase
 
- 
buildGroupName
- 
copyToContext
- 
addAuthorities@Deprecated protected void addAuthorities(org.springframework.ldap.core.DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities) Deprecated.
- 
addAuthorities
- 
removeAuthorities@Deprecated protected void removeAuthorities(org.springframework.ldap.core.DistinguishedName userDn, Collection<? extends GrantedAuthority> authorities) Deprecated.
- 
removeAuthoritiesprotected void removeAuthorities(LdapName userDn, Collection<? extends GrantedAuthority> authorities) 
- 
setUsernameMapper
- 
setPasswordAttributeName
- 
setGroupSearchBase
- 
setGroupRoleAttributeName
- 
setAttributesToRetrieve
- 
setUserDetailsMapper
- 
setGroupMemberAttributeNameSets 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.
 
- 
setRoleMapperpublic void setRoleMapper(org.springframework.ldap.core.AttributesMapper roleMapper) 
- 
setUsePasswordModifyExtensionOperationpublic void setUsePasswordModifyExtensionOperation(boolean usePasswordModifyExtensionOperation) Sets the method by which a user's password gets modified.If set to true, thenchangePassword(java.lang.String, java.lang.String)will modify the user's password by way of the Password Modify Extension Operation.If set to false, thenchangePassword(java.lang.String, java.lang.String)will modify the user's password by directly modifying attributes on the corresponding entry.Before using this setting, ensure that the corresponding LDAP server supports this extended operation. By default, usePasswordModifyExtensionOperationis false.- Parameters:
- usePasswordModifyExtensionOperation- whether to use the Password Modify Extension Operation to modify the password
- Since:
- 4.2.9
 
- 
setSecurityContextHolderStrategypublic void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
 
- 
setRolePrefixSets the role prefix used when converting authorities. The default value is "ROLE_"- Parameters:
- rolePrefix- role prefix
- Since:
- 6.3
 
 
-