class 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;
    }

    public  CustomAttributesLdapUserDetailsMapper(Map<String, String> attributeMappings);

}