Created
September 9, 2015 14:42
-
-
Save jakecoffman/b4baece7da7fa7cd227a to your computer and use it in GitHub Desktop.
apache directory ldap ssl example
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed an example of the SSL setup. Thank you for posting.