使用spring-ldap 1.3.1禁用Active Directory服务器的SSL证书验证

Bal*_*ngh 8 java ssl ldap active-directory

如果只需要配置一台AD服务器,我就可以对Active Directory进行身份验证.该解决方案由我作为匿名用户通过ssl作为 Active Directory身份验证提供.

现在,当负载均衡器后面有多个AD运行时,我卡住了.

由于Load Balancer介于两者之间,因此我将仅获取主机名,并根据可用性将AD的IP替换为Load Balancer后面的主机名.因此,我将无法知道将使用哪个Active Directory服务器来处理我的身份验证请求.所以,我将无法提前生成证书.此外,我无法获取客户端用于平衡负载的AD的IP(出于安全原因).所以没有必要生成jssecacert.我需要做的就是禁用证书验证.我正在使用LdapTemplate类(使用spring-ldap 1.3.1)来验证用户身份.我的春天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>
Run Code Online (Sandbox Code Playgroud)

验证方法:

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;

    }
Run Code Online (Sandbox Code Playgroud)

由于我们不需要证书System.setProperty("javax.net.ssl.trustStore", .../jssecacerts"); 也不需要.

我需要做哪些更改才能禁用证书验证.

我在LDAP方面很新.,请帮助适当的答案.

Bal*_*ngh 8

好吧,感谢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();
}
Run Code Online (Sandbox Code Playgroud)

}

我们需要创建一个实用程序类并将此方法放在其中.在您需要的任何地方调用此方法.

欢迎对此解决方案发表任何评论.

谢谢.

  • 在上面的代码中,您使用的是默认的 SSLContext,因此您不必关心此应用程序上使用的任何证书。您知道是否可以仅针对此特定 LDAP 证书跳过证书检查?提前致谢 (2认同)