Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knalli/8bb7b6762d87aa850e170526a9adaac2 to your computer and use it in GitHub Desktop.
Save knalli/8bb7b6762d87aa850e170526a9adaac2 to your computer and use it in GitHub Desktop.
Checks whether the given setup with user credentials are valid for authentication (quick check)
import javax.naming.NamingException;
import javax.naming.spi.NamingManager;
import java.util.Hashtable;
public class CheckActiveDirectoryConnectionViaLdap_ForSpringSecurity {
public static void main(String... args) throws NamingException {
Hashtable<String, String> table = new Hashtable<>();
table.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
table.put("java.naming.provider.url", "ldap://$HOST:389");
table.put("java.naming.ldap.version", "3");
table.put("java.naming.security.principal", "$USER");
table.put("java.naming.security.authentication", "simple");
table.put("java.naming.security.credentials", "$PASSWORD");
table.put("java.naming.factory.object", "org.springframework.ldap.core.support.DefaultDirObjectFactory");
NamingManager.getInitialContext(table);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment