Created
June 12, 2025 16:14
-
-
Save michael-o/8cff749d3ce5536bf70a16a64819cf10 to your computer and use it in GitHub Desktop.
NPE with GSS-API + TLS with Active Directory
This file contains hidden or 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
public static void main(String[] args) throws NamingException { | |
Hashtable<String, Object> env = new Hashtable<String, Object>(); | |
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); | |
env.put(Context.PROVIDER_URL, "ldaps://<fqdn>"); | |
env.put(Context.SECURITY_AUTHENTICATION, "GSSAPI"); | |
env.put(Sasl.SERVER_AUTH, "true"); | |
env.put(Sasl.QOP, "auth-int"); | |
env.put("com.sun.jndi.ldap.trace.ber", System.err); | |
env.put("java.naming.ldap.version", "3"); | |
DirContext dirContext = new InitialDirContext(env); | |
SearchControls ctls = new SearchControls(SearchControls.OBJECT_SCOPE, 0, 0, args, false, false); | |
try { | |
NamingEnumeration<SearchResult> search = dirContext.search("", "(objectClass=*)", ctls); | |
while (search.hasMore()) { | |
SearchResult res = search.next(); | |
Attributes attrs = res.getAttributes(); | |
for (String arg : args) { | |
Attribute attr = attrs.get(arg); | |
if (attr != null) { | |
System.out.println(arg + ":"); | |
NamingEnumeration<?> all = attr.getAll(); | |
while (all.hasMore()) { | |
System.out.println(" " + all.next()); | |
} | |
} | |
} | |
} | |
} catch (LdapReferralException e) { | |
e.printStackTrace(); | |
DirContext dirContext2 = (DirContext) e.getReferralContext(); | |
System.out.println(dirContext2.getNameInNamespace()); | |
dirContext2.close(); | |
} | |
dirContext.close(); | |
} |
This file contains hidden or 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
java -Dsun.security.krb5.debug=true -Djava.security.krb5.conf=C:\Config\Kerberos\krb5.conf | |
-Djava.security.auth.login.config=C:\Config\Kerberos\login.conf -Djavax.security.auth.useSubjectCredsOnly=false ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment