5

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.

stevevls
  • 10,675
  • 1
  • 45
  • 50
Martin Ždila
  • 2,998
  • 3
  • 31
  • 35
  • I want to do the same thing - I've asked this question before - I'm currently using thread local storage to do this - see: http://stackoverflow.com/questions/6424422/how-to-pass-arguments-to-an-ldap-custom-socket-factory-with-jndi – Conor Jul 01 '11 at 13:36
  • Thanks for the tip. Today I played with Apache LDAP API and it is much easier and cleaner there :-) – Martin Ždila Jul 01 '11 at 14:44

1 Answers1

2

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
Martin Ždila
  • 2,998
  • 3
  • 31
  • 35