2013-06-13 99 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

相關問題