CustomAttributesLdapUserDetailsMapper extends LdapUserDetailsMapper { @Override public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<GrantedAuthority> authorities) { LdapUserDetails details = (LdapUserDetails)super.mapUserFromContext(ctx, username, authorities); LdapUserDetailsWithAttributes detailsWithAttributes = new LdapUserDetailsWithAttributes(details); for(String attributeName : attributeMappings.keySet()) { detailsWithAttributes.setAttribute(attributeName, ctx.getStringAttribute(attributeMappings.get(attributeName))); } return detailsWithAttributes; } CustomAttributesLdapUserDetailsMapper(Map<String, String> attributeMappings); @Override UserDetails mapUserFromContext(DirContextOperations ctx, String username,
            Collection<GrantedAuthority> authorities);  }
@Test public void testMappings() { ctx.getLdapAttributes().put("cn", "mock"); attributeMappings.put("FullName", "cn"); UserDetails details = mapper.mapUserFromContext(ctx, SAMPLE_USERNAME, authorities); assertTrue(details instanceof UserDetailsWithAttributes); UserDetailsWithAttributes detailsWithAttribute = (UserDetailsWithAttributes) details; assertEquals("mock", detailsWithAttribute.getAttribute("FullName")); }