Skip to content
Advertisement

jndi LDAPS custom HostnameVerifier and TrustManager

We are writing an application that shall connect to different LDAP servers. For each server we may only accept a certain certificate. The hostname in that certificate shall not matter. This is easy, when we use LDAP and STARTTLS, because we can use StartTlsResponse.setHostnameVerifier(..-) and use StartTlsResponse.negotiate(...) with a matching SSLSocketFactory. However we also need to support LDAPS connections. Java supports this natively, but only if the server certificate is trusted by the default java keystore. While we could replace that, we still cannot use different keystores for different servers.

The existing connection code is as follows:

JavaScript

We could add out own CustomSocketFactory, but how to pass information to that?

Advertisement

Answer

For others have the same problem: I found a very ugly solution for my case:

JavaScript

Using it like this:

JavaScript

Not nice, but it works. JNDI should be more flexible here…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement