public class LdapUserDetailsManager
extends java.lang.Object
implements org.springframework.security.provisioning.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.
Constructor and Description |
---|
LdapUserDetailsManager(org.springframework.ldap.core.ContextSource contextSource) |
Modifier and Type | Method and Description |
---|---|
protected void |
addAuthorities(org.springframework.ldap.core.DistinguishedName userDn,
java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) |
protected org.springframework.ldap.core.DistinguishedName |
buildGroupDn(java.lang.String group)
Creates a DN from a group name.
|
void |
changePassword(java.lang.String oldPassword,
java.lang.String newPassword)
Changes the password for the current user.
|
protected void |
copyToContext(org.springframework.security.core.userdetails.UserDetails user,
org.springframework.ldap.core.DirContextAdapter ctx) |
void |
createUser(org.springframework.security.core.userdetails.UserDetails user) |
void |
deleteUser(java.lang.String username) |
org.springframework.security.core.userdetails.UserDetails |
loadUserByUsername(java.lang.String username) |
protected void |
removeAuthorities(org.springframework.ldap.core.DistinguishedName userDn,
java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) |
void |
setAttributesToRetrieve(java.lang.String[] attributesToRetrieve) |
void |
setGroupMemberAttributeName(java.lang.String groupMemberAttributeName)
Sets the name of the multi-valued attribute which holds the DNs of users who are
members of a group.
|
void |
setGroupRoleAttributeName(java.lang.String groupRoleAttributeName) |
void |
setGroupSearchBase(java.lang.String groupSearchBase) |
void |
setPasswordAttributeName(java.lang.String passwordAttributeName) |
void |
setRoleMapper(org.springframework.ldap.core.AttributesMapper roleMapper) |
void |
setUserDetailsMapper(UserDetailsContextMapper userDetailsMapper) |
void |
setUsernameMapper(LdapUsernameToDnMapper usernameMapper) |
void |
updateUser(org.springframework.security.core.userdetails.UserDetails user) |
boolean |
userExists(java.lang.String username) |
public LdapUserDetailsManager(org.springframework.ldap.core.ContextSource contextSource)
public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(java.lang.String username)
loadUserByUsername
in interface org.springframework.security.core.userdetails.UserDetailsService
public void changePassword(java.lang.String oldPassword, java.lang.String newPassword)
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.
changePassword
in interface org.springframework.security.provisioning.UserDetailsManager
oldPassword
- the old passwordnewPassword
- the new value of the password.public void createUser(org.springframework.security.core.userdetails.UserDetails user)
createUser
in interface org.springframework.security.provisioning.UserDetailsManager
public void updateUser(org.springframework.security.core.userdetails.UserDetails user)
updateUser
in interface org.springframework.security.provisioning.UserDetailsManager
public void deleteUser(java.lang.String username)
deleteUser
in interface org.springframework.security.provisioning.UserDetailsManager
public boolean userExists(java.lang.String username)
userExists
in interface org.springframework.security.provisioning.UserDetailsManager
protected org.springframework.ldap.core.DistinguishedName buildGroupDn(java.lang.String group)
group
- the name of the groupprotected void copyToContext(org.springframework.security.core.userdetails.UserDetails user, org.springframework.ldap.core.DirContextAdapter ctx)
protected void addAuthorities(org.springframework.ldap.core.DistinguishedName userDn, java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
protected void removeAuthorities(org.springframework.ldap.core.DistinguishedName userDn, java.util.Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
public void setUsernameMapper(LdapUsernameToDnMapper usernameMapper)
public void setPasswordAttributeName(java.lang.String passwordAttributeName)
public void setGroupSearchBase(java.lang.String groupSearchBase)
public void setGroupRoleAttributeName(java.lang.String groupRoleAttributeName)
public void setAttributesToRetrieve(java.lang.String[] attributesToRetrieve)
public void setUserDetailsMapper(UserDetailsContextMapper userDetailsMapper)
public void setGroupMemberAttributeName(java.lang.String groupMemberAttributeName)
Usually this will be uniquemember (the default value) or member.
groupMemberAttributeName
- the name of the attribute used to store group
members.public void setRoleMapper(org.springframework.ldap.core.AttributesMapper roleMapper)