Created
January 17, 2018 17:36
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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