Skip to content

Ldap ssl bind

November 10, 2008

Hashtable<String, String> env = new Hashtable<String, String>();

env.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”);
env.put(Context.PROVIDER_URL, “ldaps://” + server + “:” + serverPort);
env.put(Context.SECURITY_PRINCIPAL, baseDN);
env.put(Context.SECURITY_AUTHENTICATION, “simple”);
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, getDecryptedPassword());
env.put(LdapContext.CONTROL_FACTORIES, “com.sun.jndi.ldap.ControlFactory”);
env.put(Context.SECURITY_PROTOCOL, “ssl”);

Security.addProvider(new ssl.internal.ssl.Provider()); env.put(“com.sun.jndi.ldap.connect.pool”, “true”);

// use connection pooling

System.setProperty(“com.sun.jndi.ldap.connect.pool.protocol”, “plain ssl”);

// load the location of keystore that holds trusted root certificates from web.xml
ServletContext context =

String certificatePath = context.getInitParameter(“AD_CERTIFICATE_PATH”);
System.setProperty(“”,  certificatePath);
ctx = new InitialDirContext(env);

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: