@SuppressWarnings({"JdkObsolete", "BanJNDI"})
    private static boolean connect(final String ldapUrl,
                                   final String bindDn,
                                   final String bindCredential,
                                   final String baseDn,
                                   final String searchFilter,
                                   final String userAttributes,
                                   final String userPassword) throws Exception {
        val pair = getContext(ldapUrl, bindDn, bindCredential);
        if (pair == null) {
            LOGGER.error("Could not connect to any of the provided LDAP urls based on the given credentials.");
            return false;
        }

        val ctx = pair.getValue();
        try {
            var log = "Successfully connected to the LDAP url [" + pair.getKey() + "] ";
            if (ctx.getNameInNamespace() != null && !ctx.getNameInNamespace().isEmpty()) {
                log += "with namespace [" + ctx.getNameInNamespace() + "].";
            }
            LOGGER.info(log);

            if (!StringUtils.hasText(searchFilter)) {
                return true;
            }

            val attrIDs = userAttributes.split(",");
            LOGGER.info("******* Ldap Search *******");
            LOGGER.info("Ldap filter: [{}]", searchFilter);
            LOGGER.info("Ldap search base: [{}]", baseDn);
            LOGGER.info("Returning attributes: [{}]\n", Arrays.toString(attrIDs));

            val ctls = getSearchControls(attrIDs);
            val answer = ctx.search(baseDn, searchFilter, ctls);
            if (answer.hasMoreElements()) {
                LOGGER.info("******* Ldap Search Results *******");
                while (answer.hasMoreElements()) {
                    val result = answer.nextElement();
                    LOGGER.info("User name: [{}]", result.getName());
                    LOGGER.info("User full name: [{}]", result.getNameInNamespace());

                    if (org.apache.commons.lang3.StringUtils.isNotBlank(userPassword)) {
                        LOGGER.info("Attempting to authenticate [{}] with password [{}]", result.getName(), userPassword);

                        val env = getLdapDirectoryContextSettings(result.getNameInNamespace(), userPassword, pair.getKey());
                        new InitialDirContext(env);
                        LOGGER.info("Successfully authenticated [{}] with password [{}]", result.getName(), userPassword);
                    }
                    val attrs = result.getAttributes().getIDs();
                    while (attrs.hasMoreElements()) {
                        val id = attrs.nextElement();
                        LOGGER.info("[{}] => [{}]", id, result.getAttributes().get(id));
                    }
                }
                return true;
            } else {
                LOGGER.info("No search results could be found.");
            }
            LOGGER.info("Ldap search completed successfully.");
        } finally {
            if (ctx != null) {
                ctx.close();
            }
        }
        return false;
    }
Validate endpoint.

@param url            the url
@param bindDn         the bind dn
@param bindCredential the bind credential
@param baseDn         the base dn
@param searchFilter   the search filter
@param userPassword   the user password
@param userAttributes the user attributes
@return true/false
support/cas-server-support-shell-core/src/main/java/org/apereo/cas/shell/commands/util/ValidateLdapConnectionCommand.java