2017-08-12 72 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

但我觉得很奇怪的是,应用程序应该想要这样做。