Class LdapUserDetailsMapper

All Implemented Interfaces:

public class LdapUserDetailsMapper extends Object implements UserDetailsContextMapper
The context mapper used by the LDAP authentication provider to create an LDAP user object.
  • Constructor Details

    • LdapUserDetailsMapper

      public LdapUserDetailsMapper()
  • Method Details

    • mapUserFromContext

      public UserDetails mapUserFromContext(org.springframework.ldap.core.DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities)
      Description copied from interface: UserDetailsContextMapper
      Creates a fully populated UserDetails object for use by the security framework.
      Specified by:
      mapUserFromContext in interface UserDetailsContextMapper
      ctx - the context object which contains the user information.
      username - the user's supplied login name.
      the user object.
    • mapUserToContext

      public void mapUserToContext(UserDetails user, org.springframework.ldap.core.DirContextAdapter ctx)
      Description copied from interface: UserDetailsContextMapper
      Reverse of the above operation. Populates a context object from the supplied user object. Called when saving a user, for example.
      Specified by:
      mapUserToContext in interface UserDetailsContextMapper
    • mapPassword

      protected String mapPassword(Object passwordValue)
      Extension point to allow customized creation of the user's password from the attribute stored in the directory.
      passwordValue - the value of the password attribute
      a String representation of the password.
    • createAuthority

      protected GrantedAuthority createAuthority(Object role)
      Creates a GrantedAuthority from a role attribute. Override to customize authority object creation.

      The default implementation converts string attributes to roles, making use of the rolePrefix and convertToUpperCase properties. Non-String attributes are ignored.

      role - the attribute returned from
      the authority to be added to the list of authorities for the user, or null if this attribute should be ignored.
    • setConvertToUpperCase

      public void setConvertToUpperCase(boolean convertToUpperCase)
      Determines whether role field values will be converted to upper case when loaded. The default is true.
      convertToUpperCase - true if the roles should be converted to upper case.
    • setPasswordAttributeName

      public void setPasswordAttributeName(String passwordAttributeName)
      The name of the attribute which contains the user's password. Defaults to "userPassword".
      passwordAttributeName - the name of the attribute
    • setRoleAttributes

      public void setRoleAttributes(String[] roleAttributes)
      The names of any attributes in the user's entry which represent application roles. These will be converted to GrantedAuthoritys and added to the list in the returned LdapUserDetails object. The attribute values must be Strings by default.
      roleAttributes - the names of the role attributes.
    • setRolePrefix

      public void setRolePrefix(String rolePrefix)
      The prefix that should be applied to the role names
      rolePrefix - the prefix (defaults to "ROLE_").