我需要通过带有SSL的spring-ldap与LDAP服务器进行通信,并且另一端拥有一个自签名证书。

请问有什么好心的人给我一些指导来进行设置吗?

最佳答案

查阅Spring LDAP文档以通过HTTP(S)连接到LDAP服务器:

就自签名证书而言,您可以将证书链导入信任库并设置以下VM参数:

-Djavax.net.ssl.trustStore="<path to truststore file>"
-Djavax.net.ssl.trustStorePassword="<passphrase for truststore>"

或在运行时覆盖信任库,例如:
System.setProperty("javax.net.ssl.trustStore","<path to truststore file>");
System.setProperty("javax.net.ssl.trustStorePassword","<passphrase for truststore>");

请记住,这两个选项都将覆盖默认的JVM信任库。因此,如果您使用不同的证书访问不同的站点,则可能需要将所有证书导入一个信任库中。

如果需要帮助来创建信任库文件,请引用:Digital Certificate: How to import .cer file in to .truststore file using?

10-03 00:06