public String ldapLogin(String userId, String userPwd) {
        Properties searchEnv = getManagerLdapEnv();
        LdapContext ctx = null;
        try {
            // Connect to the LDAP server and Authenticate with a service user of whom we know the DN and credentials
            ctx = new InitialLdapContext(searchEnv, null);
            SearchControls sc = new SearchControls();
            sc.setReturningAttributes(new String[]{ldapEmailAttribute});
            sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
            EqualsFilter filter = new EqualsFilter(ldapUserIdentifyingAttribute, userId);
            NamingEnumeration<SearchResult> results = ctx.search(ldapBaseDn, filter.toString(), sc);
            if (results.hasMore()) {
                // get the users DN (distinguishedName) from the result
                SearchResult result = results.next();
                NamingEnumeration<? extends Attribute> attrs = result.getAttributes().getAll();
                while (attrs.hasMore()) {
                    // Open another connection to the LDAP server with the found DN and the password
                    searchEnv.put(Context.SECURITY_PRINCIPAL, result.getNameInNamespace());
                    searchEnv.put(Context.SECURITY_CREDENTIALS, userPwd);
                    try {
                        new InitialDirContext(searchEnv);
                    } catch (Exception e) {
                        log.warn("invalid ldap credentials or ldap search error", e);
                        return null;
                    }
                    Attribute attr = attrs.next();
                    if (attr.getID().equals(ldapEmailAttribute)) {
                        return (String) attr.get();
                    }
                }
            }
        } catch (NamingException e) {
            log.error("ldap search error", e);
            return null;
        } finally {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            } catch (NamingException e) {
                log.error("ldap context close error", e);
            }
        }

        return null;
    }
@Test
    public void ldapLoginError() throws NoSuchFieldException, IllegalAccessException {
        changeSslEnable(false);
        String email2 = ldapService.ldapLogin(username, "error password");
        Assertions.assertNull(email2);
    }