如果只需要配置一个 AD 服务器,我可以向 Active Directory 进行身份验证。解决方案如下 Active Directory authentication through ssl as anonymous user由我。
现在,当负载均衡器后面运行多个 AD 时,我陷入困境。
由于负载均衡器介于两者之间,我将仅获取主机名,AD 的 IP 将根据可用性替换为负载均衡器后面的主机名。因此,我无法知道将使用哪个 Active Directory 服务器来处理我的身份验证请求。所以,我将无法提前生成证书。此外,我无法获取我的客户端用于平衡负载的广告的 IP(出于安全原因)。所以没有生成 jssecacert 的意义。我需要做的就是禁用证书验证。我正在使用 LdapTemplate 类(使用 spring-ldap 1.3.1)来验证用户。 我的 spring Config 看起来像这样......
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<property name="contextSource" ref="contextSource" />
<property name="ignorePartialResultException" value="yes" />
</bean>
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldaps://xxx.xxx.xxx.xxx:636" />
</bean>
认证方式:
public boolean login(String username, String password) {
System.setProperty("javax.net.ssl.trustStore",
.../jssecacerts");
boolean authenticate=false;
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("xyz","xyz"));
filter.and(new EqualsFilter("xyz", xyz));
authenticate = this.ldapTemplate.authenticate(base, filter.encode(), password);
return authenticate;
}
因为我们不需要证书 System.setProperty("javax.net.ssl.trustStore",
.../jssecacerts");
将不需要。
我需要进行哪些更改才能禁用证书验证。
我是 LDAP 方面的新手。 , 请帮助提供适当的答案。
最佳答案
好吧,感谢 Darren Hauge 提供了一个不关心 ssl 证书的棘手解决方案。在这里重写解决方案:
public static void trustSelfSignedSSL() {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLContext.setDefault(ctx);
} catch (Exception ex) {
ex.printStackTrace();
}
}
我们只需要创建一个实用程序类并将此方法放入其中。在任何需要的地方调用此方法。
欢迎对此解决方案发表任何评论。
谢谢。
关于java - 使用 spring-ldap 1.3.1 禁用 Active Directory 服务器的 SSL 证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143858/