ctx = new InitialLdapContext(env, controls);
logger.debug("Active Directory LDAP context initialized");
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, activeDirectoryDomain + "\\" + loginName);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
// javax.naming.AuthenticationException
ctx.reconnect(controls);
logger.debug("Active Directory LDAP bind successful");
} else { // standard LDAP
env.put(Context.SECURITY_PRINCIPAL, searchKey + "=" + loginName + "," + searchBase);
env.put(Context.SECURITY_CREDENTIALS, password);
ctx = new InitialLdapContext(env, null);