public Object mapAttributes(String dn, Attributes attributes) throws NamingException { LdapUserDetailsImpl.Essence essence = new LdapUserDetailsImpl.Essence(); essence.setDn(dn); essence.setAttributes(attributes); Attribute passwordAttribute = attributes.get(passwordAttributeName); if (passwordAttribute != null) { essence.setPassword(mapPassword(passwordAttribute)); } // Map the roles for (int i = 0; (roleAttributes != null) && (i < roleAttributes.length); i++) { Attribute roleAttribute = attributes.get(roleAttributes[i]); if (roleAttribute == null) { logger.debug("Couldn't read role attribute '" + roleAttributes[i] + "' for user " + dn); continue; } NamingEnumeration attributeRoles = roleAttribute.getAll(); while (attributeRoles.hasMore()) { GrantedAuthority authority = createAuthority(attributeRoles.next()); if (authority != null) { essence.addAuthority(authority); } else { logger.debug("Failed to create an authority value from attribute with Id: " + roleAttribute.getID()); } } } return essence; }