private Boolean lookupExistence(InitialDirContext ctx, LdapName dn, String[] returnattrs) throws NamingException {
        Log.debug("In lookupExistence(ctx, dn, returnattrs), searchdn is: {}", dn);

        // Bind to the object's DN
        ctx.addToEnvironment(Context.PROVIDER_URL, getProviderURL(dn));

        String filter = "(&(objectClass=*))";
        SearchControls srcnt = new SearchControls();
        srcnt.setSearchScope(SearchControls.OBJECT_SCOPE);
        srcnt.setReturningAttributes(returnattrs);

        NamingEnumeration<SearchResult> answer = null;

        try {
            answer = ctx.search(
                    "",
                    filter,
                    srcnt);
        } catch (javax.naming.NameNotFoundException nex) {
            Log.debug("Unable to find ldap object {}.", dn);
        }

        if (answer == null || !answer.hasMoreElements())
        {
            Log.debug(".... lookupExistence: DN not found.");
            return false;
        }
        else
        {
            Log.debug(".... lookupExistence: DN found.");
            return true;
        }
    }
Looks up an LDAP object by its DN and returns {@code true} if
the search was successful.

@param ctx the Context to use for the lookup.
@param dn the object's dn to lookup.
@return true if the lookup was successful.
@throws NamingException if login credentials were wrong.
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapManager.java