【问题标题】:Disabling SSL Certificate Validation for Active Directory server using spring-ldap 1.3.1使用 spring-ldap 1.3.1 禁用 Active Directory 服务器的 SSL 证书验证
【发布时间】:2013-06-17 09:01:21
【问题描述】:

如果只需要配置一台 AD 服务器,我可以对 Active Directory 进行身份验证。解决方案如下 Active Directory authentication through ssl as anonymous user 我。

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

由于负载均衡器介于两者之间,我将仅获取主机名,并且将根据可用性将 AD 的 IP 替换为负载均衡器后面的主机名。因此,我将无法知道将使用哪个 Active Directory 服务器来处理我的身份验证请求。所以,我将无法提前生成证书。此外,我无法获取客户端用于平衡负载的 AD 的 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 方面的新手。 , 请帮助提供适当的答案。

【问题讨论】:

  • 这里不是 LDAP 特定的,而是与 TLS 相关的。
  • @fge 是的,我同意 SSL 到位。
  • 我也看不出 OpenLDAP 与它有什么关系。重新标记为 LDAP 和 SSL。

标签: java ssl active-directory ldap


【解决方案1】:

好吧,感谢 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();
    }
}

我们只需要创建一个实用程序类并将这个方法放入其中。在需要的地方调用此方法。

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

谢谢。

【讨论】:

  • 在上面的代码中,您使用的是默认 SSLContext,因此您不会关心此应用程序上使用的任何证书。您知道是否可以仅针对此特定 ldap 证书跳过证书检查?提前致谢
  • 有什么办法可以在启动参数中配置这个吗?
  • 旁注,注意粘贴时要使用的导入,不要使用来自 com.sun.* 的导入,而是来自 javax.netjava.security 的导入
猜你喜欢
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 2011-05-03
  • 2020-04-08
  • 2014-06-11
相关资源
最近更新 更多