private Map<String, String> getLdapAttributes(String username) {
        // Un-escape username
        username = JID.unescapeNode(username);
        Map<String, String> map = new HashMap<>();

        DirContext ctx = null;
        try {
            Rdn[] userRDN = manager.findUserRDN(username);

            ctx = manager.getContext(manager.getUsersBaseDN(username));
            Attributes attrs = ctx.getAttributes(LdapManager.escapeForJNDI(userRDN), template.getAttributes());

            for (String attribute : template.getAttributes()) {
                javax.naming.directory.Attribute attr = attrs.get(attribute);
                String value;
                if (attr == null) {
                    Log.debug("LdapVCardProvider: No ldap value found for attribute '" + attribute + "'");
                    value = "";
                }
                else {
                    Object ob = attrs.get(attribute).get();
                    Log.debug("LdapVCardProvider: Found attribute "+attribute+" of type: "+ob.getClass());
                    if(ob instanceof String) {
                        value = (String)ob;
                    } else {
                        value = Base64.getEncoder().encodeToString((byte[])ob);
                    }
                }
                Log.debug("LdapVCardProvider: Ldap attribute '" + attribute + "'=>'" + value + "'");
                map.put(attribute, value);
            }
            return map;
        }
        catch (UserNotFoundException e) {
            Log.info("Unable to find LDAP data as user '{}' is not found in the directory service.", username, e);
            return Collections.emptyMap();
        }
        catch (Exception e) {
            Log.warn("Unexpected exception while tyring to find LDAP data for user '{}'", username, e);
            return Collections.emptyMap();
        }
        finally {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            }
            catch (Exception e) {
                // Ignore.
            }
        }
    }
Creates a mapping of requested LDAP attributes to their values for the given user.

@param username User we are looking up in LDAP.
@return Map of LDAP attribute to setting.
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapVCardProvider.java