Skip to content

Instantly share code, notes, and snippets.

@jakecoffman
Created September 9, 2015 14:42
Show Gist options
  • Save jakecoffman/b4baece7da7fa7cd227a to your computer and use it in GitHub Desktop.
Save jakecoffman/b4baece7da7fa7cd227a to your computer and use it in GitHub Desktop.
apache directory ldap ssl example
package com.jakecoffman.ldap
import org.apache.directory.api.ldap.model.entry.DefaultEntry
import org.apache.directory.api.ldap.model.message.SearchScope
import org.apache.directory.ldap.client.api.LdapConnectionConfig
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import org.apache.directory.ldap.client.api.NoVerificationTrustManager
// I hope this helps someone
def sslConfig = new LdapConnectionConfig()
sslConfig.setTrustManagers(new NoVerificationTrustManager())
sslConfig.setLdapHost("ldap.example.com")
sslConfig.setLdapPort(636)
sslConfig.setName("cn=manager,ou=org,ou=users,o=data")
sslConfig.setCredentials("mypassword")
sslConfig.setSslProtocol("SSLv3");
sslConfig.setUseSsl(true);
def connection = new LdapNetworkConnection(sslConfig)
connection.connect()
connection.bind()
def baseDN = "ou=org,ou=users,o=data"
def cursor = connection.search(baseDN, "(objectclass=*)", SearchScope.ONELEVEL, "*")
while (cursor.next()) {
def thing = cursor.get()
assert thing instanceof DefaultEntry
println("${thing.get("cn").get()}")
}
connection.unBind()
connection.close()
@HybridProgrammer
Copy link

I needed an example of the SSL setup. Thank you for posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment