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 com.sun.net. 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 =

getServletContext();
String certificatePath = context.getInitParameter(“AD_CERTIFICATE_PATH”);
System.setProperty(“javax.net.ssl.trustStore”,  certificatePath);
ctx = new InitialDirContext(env);

http://java.sun.com/products/jndi/tutorial/ldap/connect/pool.html

http://java.sun.com/products/jndi/tutorial/ldap/connect/config.html

Advertisements
No comments yet

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: