public List<String> retrieveAttributeOf(String attributeName, LdapName dn) throws NamingException {
        Log.debug("LdapManager: Reading attribute '{}' of DN '{}' ...", attributeName, dn);

        DirContext ctx = null;
        NamingEnumeration<?> values = null;
        try {

            ctx = getContext(dn);
            Attributes attributes = ctx.getAttributes("", new String[]{attributeName});
            Attribute attribute = attributes.get(attributeName);
            if (attribute == null)
                return Collections.emptyList();
            List<String> result = new ArrayList<>(attribute.size());
            values = attribute.getAll();
            while (values.hasMoreElements()) {
                result.add(values.next().toString());
            }
            return result;
        }
        catch (final Exception e) {
            Log.debug("LdapManager: Exception thrown when reading attribute '{}' of DN '{}' ...", attributeName, dn, e);
            throw e;
        }
        finally {
            try {
                if (values != null)
                    values.close();
            }
            catch (Exception ex) {
                Log.debug("An exception occurred while trying to close values after trying to read attribute {}.", attributeName, ex);
            }
            try {
                if (ctx != null)
                    ctx.close();
            }
            catch (Exception ex) {
                Log.debug("An exception occurred while trying to close a LDAP context after trying to read attribute {}.", attributeName, ex);
            }
        }
    }
Reads the attribute values of an entry with the given DN.

@param attributeName LDAP attribute to be read.
@param dn            DN of the entry.
@return A list with the values of the attribute.
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapManager.java