Martin Ždila
Martin Ždila

Reputation: 3219

Is there a way to provide SocketFactory _instance_ to InitialLdapContext?

There is a static way of providing SocketFactory to InitialLdapContext:

env.put("java.naming.ldap.factory.socket", MySocketFactory.class.getName());
new InitialLdapContext(env, null);

But is there some way to provide the instance itself instead of its class name? My socket factory is parameterized with the input stream of trusted certificate and there can be configured many instances of InitialLdapContext with different trusted certificates. BTW this will run in OSGi environment.

Thanks in advance.

Upvotes: 5

Views: 663

Answers (1)

Martin Ždila
Martin Ždila

Reputation: 3219

Inspecting source of com.sun.jndi.ldap.Connection.createSocket(String, int, String, int) I can see that there is unfortunately no way to do this. It is sad that so many Java core APIs have that bad design.

The solution might be to use different implementation:

  • Netscape LdapSdk
  • OpenLDAP JLdap
  • Apache Directory LDAP API

Upvotes: 2

Related Questions