Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments to an LDAP custom socket factory with JNDI?

Tags:

java

ldap

jndi

I'm using JNDI to make LDAP connections. Example:

Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, LDAPS_URL);
env.put(Context.SECURITY_AUTHENTICATION, "EXTERNAL");
env.put("java.naming.ldap.factory.socket", "ldaptest.CustomSocketFactory");
...

I need to pass parameters at run time to the CustomSocketFactory. Specifically a reference to a client certificate.

How can I do this? I could use thread local storage.

Is there a better way?

like image 908
Conor Avatar asked Jun 21 '11 11:06

Conor


People also ask

Does LDAP use JNDI?

JNDI does for LDAP what JDBC does for Oracle -- it provides a standard API for interacting with naming and directory services using a service provider interface (SPI), which is analogous to an JDBC driver. LDAP is a standard way to provide access to directory information.

How does JNDI LDAP work?

Both the JNDI and LDAP models define a hierarchical namespace in which you name objects. Each object in the namespace may have attributes that can be used to search for the object. At this high level, the two models are similar, so it is not surprising that the JNDI maps well to the LDAP.

What port does JNDI LDAP use?

String url = "ldap://localhost:389" ; That specifies URL of a LDAP server which is running on local host and is listening on the default port number 389 - a well known port number of the Lightweight Directory Access Protocol.

What protocols does JNDI support?

These naming and directory services are supported by JNDI: Lightweight Directory Access Protocol (LDAP) Corba Object Services (COS) Naming Service. RMI Registry.


2 Answers

Actually thread local is only way to solve this I found so far. I posted my solution here:

jndi LDAPS custom HostnameVerifier and TrustManager

like image 174
Steffen Heil Avatar answered Sep 28 '22 07:09

Steffen Heil


I think that you may be looking for something like this:

env.put("javax.net.ssl.keyStore", keystorePath);
//Where keystorePath is the path to the Keys file resource

env.put("javax.net.ssl.keyStorePassword", "password");
like image 38
icrovett Avatar answered Sep 28 '22 06:09

icrovett