2013-06-13 101 views
0

我能够使用Spring-ldap为ContextSource生存期配置的用户对Active Directory进行身份验证。我的Spring XML配置看起来lilke这样的:通过ssl作为匿名用户的Active Directory身份验证

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"> 
    <property name="contextSource" ref="contextSource" /> 
</bean> 


<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> 
    <property name="url" value="ldap://xxx.xxx.xxx.xxx:389" /> 
    <property name="userDn" value="[email protected]" /> 
    <property name="password" value="password" /> 

</bean> 

Java代码来验证用户的身份是:

public boolean login(String username, String password) { 
    AndFilter filter = new AndFilter(); 
    this.ldapTemplate.setIgnorePartialResultException(true); // Active Directory doesn’t transparently handle referrals. This fixes that. 
    filter.and(new EqualsFilter("objectCategory","****")); 
    filter.and(new EqualsFilter("objectClass","****")); 
    filter.and(new EqualsFilter("sAMAccountName", username)); 
    return this.ldapTemplate.authenticate("OU=myBaseOu,DC=xyz,DC=def", filter.encode(), password); 

    } 

使用Linux的Open LDAP同一作品v3还就算我没有设置用户DN密码内的财产contextSource bean。

我所需要的只是配置此xml,以便我可以匿名用户的身份访问Active Directory(无需设置userDn和密码)。

另外我需要通过SSL认证用户。对于我用

<property name="url" value="ldaps://xxx.xxx.xxx.xxx:636" /> 

,但我得到了像例外:

Exception in thread "main" org.springframework.ldap.CommunicationException: simple bind failed: 192.168.0.13:636; nested exception is javax.naming.CommunicationException: simple bind failed: 192.168.0.13:636 [Root exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target] 

在寻找,虽然,我得到的解决方案,我需要指出的是,其中存储证书的密钥库。在这里我不确定在哪里(无论是在java类还是在xml文件中)。

您的快速响应将不胜感激。 谢谢。

回答

2

我做了一些研究,发现其他应用程序有类似的问题。

  1. 请确保您已根据连接到LDAP或其他服务通过SSL说明将您的证书导入密钥库。
  2. 确保已将任何证书导入到正确的密钥库中;您可能有多个JDK。
+0

好吧,我不清楚,但我还是能够通过使用JXplorer SSL级连接到LDAP服务器。 –

+0

您必须检查您的JXplorer是否使用与您的应用程序相同的jvm/jdk。正在使用的密钥库可能不同。 – DevZer0

相关问题