2017-08-12 74 views
0

我作爲春LDAP基本配置

ou=studentBase,dc=example,dc=com 

在我的安全XML我有

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> 
    <property name="base" value="ou=studentBase,dc=example,dc=com" /> 
    <property name="url" value="ldaps://serveraddress:port" /> 
    <property name="userDn" value="username" /> 
    <property name="password" value="pwd" /> 
</bean> 

我想查詢屬性的容器對象

cn=container,cn=schema,cn=configuration,dc=example,dc=com 

當目錄結構我搜索的基地設置爲

cn=container,cn=schema,cn=configuration,dc=example,dc=com 

ldapTemplate.search(base, filter.encode(), new AttributesMapper()){ 
} 

我得到一個錯誤

org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100238, problem 2001 (NO_OBJECT), data 0, best match of: 'ou=studentBase,dc=example,dc=com']; nested exception is 
javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-03100238, problem 2001 (NO_OBJECT), data 0, best match of: 
    'ou=studentBase,dc=example,dc=com']; remaining name cn=container,cn=schema,cn=configuration,dc=example,dc=com 

問題是我無法改變的基礎搜索比我把xml配置文件基點之外任何東西。我也嘗試SearchControls,並有同樣的問題。我如何在不同的基礎上搜索。我編寫了整個應用程序,無法解決這個問題。

回答

0

您需要添加另一個contextSource的配置查找:

<bean id="schemaContextSource" class="org.springframework.ldap.core.support.LdapContextSource"> 
    <property name="base" value="cn=configuration,dc=example,dc=com" /> 
    <property name="url" value="ldaps://serveraddress:port" /> 
    <property name="userDn" value="username" /> 
    <property name="password" value="pwd" /> 
</bean> 

,並確保您使用userDN有權查看/更改在線配置,這應該是相同的用戶作爲爲了安全起見,我們使用了contextSource

但我覺得很奇怪的是,應用程序應該想要這樣做。