Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Created August 28, 2020 04:29
Show Gist options
  • Save frasertweedale/c1f5bde72750ebc5d1789b5b37708274 to your computer and use it in GitHub Desktop.
Save frasertweedale/c1f5bde72750ebc5d1789b5b37708274 to your computer and use it in GitHub Desktop.
ldapjdk GSSAPI bind test program
import java.util.Hashtable;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.Callback;
import netscape.ldap.LDAPConnection;
import netscape.ldap.LDAPEntry;
import netscape.ldap.LDAPUrl;
class Main {
String SASL_PACKAGE = "com.netscape.sasl";
public static void main(String[] args) {
LDAPConnection conn = new LDAPConnection(LDAPUrl.getSocketFactory());
try {
// set debug on connection
conn.setProperty("debug", "true");
conn.connect("f31-1.ipa.local", 636);
//conn.bind("cn=Directory Manager", "4me2Test"); // works
// attempt GSS-API authn
String[] mechanisms = {"GSSAPI"};
Hashtable<Object, Object> props = new Hashtable<>();
conn.bind(null, mechanisms, props, new CBH());
LDAPEntry entry = conn.read("cn=cas,cn=ca,dc=ipa,dc=local");
if (entry == null) {
System.out.println("failed to read entry");
} else {
System.out.println(entry.toString());
}
} catch (Throwable e) {
e.printStackTrace();
}
System.out.println("done");
}
}
class CBH implements CallbackHandler {
public void handle(Callback[] callbacks) {
System.out.println("CALLBACKS:");
for (int i = 0; i < callbacks.length; i++) {
System.out.println(callbacks[i].toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment