Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 667
Martin Ždila Avatar asked Nov 05 '22 19:11

Martin Ždila


1 Answers

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
like image 100
Martin Ždila Avatar answered Nov 12 '22 15:11

Martin Ždila