Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带动态基本DN的SpringLDAP_Java_Spring_Ldap_Openldap_Spring Ldap - Fatal编程技术网

Java 带动态基本DN的SpringLDAP

Java 带动态基本DN的SpringLDAP,java,spring,ldap,openldap,spring-ldap,Java,Spring,Ldap,Openldap,Spring Ldap,我有以下LDAP方案: 每个子树都包含组织单元团队。我想从特定子树中查找所有团队。为此,我使用LdapTemplateclass和findAll()方法 ldapTemplate.findAll(Team.class); 当我在LdapContextSource中将base设置为dc=global,dc=id,dc=pl时,它会从全局子树返回我的团队。当我将base更改为dc=id,dc=pl时,它将从所有子树返回我的团队 问题是我想使用DynamicBase,从特定的子树中查找团队。我尝试

我有以下LDAP方案:

每个子树都包含组织单元团队。我想从特定子树中查找所有团队。为此,我使用
LdapTemplate
class和
findAll()
方法

ldapTemplate.findAll(Team.class);
当我在
LdapContextSource
中将base设置为
dc=global,dc=id,dc=pl
时,它会从全局子树返回我的团队。当我将base更改为dc=id,dc=pl时,它将从所有子树返回我的团队

问题是我想使用DynamicBase,从特定的子树中查找团队。我尝试了多种方法来实现这一点,但没有一种方法能给我带来效果

方法1:查找

Name nameBase = LdapUtils.newLdapName("dc=global");
return ldapTemplate.find(query().base(nameBase).where("ou").is("team"), Team.class);
返回空列表

方法2:findAll

Name nameBase = LdapUtils.newLdapName("dc=global");
SearchControls searchControls = new SearchControls();
return ldapTemplate.findAll(nameBase, searchControls, Team.class);
返回空列表

起初,它看起来工作正常,因为当我将子树名称更改为不存在的名称时,我得到了
javax.naming.NameNotFoundException:[LDAP:错误代码32-没有这样的对象]

任何关于我为什么在这段代码中得到正确结果的想法:

LdapContextSource contextSource = new LdapContextSource();
contextSource.setBase("dc=global,dc=id,dc=pl");

LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
return ldapTemplate.findAll(Team.class);
和此列表中的空列表:

LdapContextSource contextSource = new LdapContextSource();
contextSource.setBase("dc=id,dc=pl");

LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
Name nameBase = LdapUtils.newLdapName("dc=global");
SearchControls searchControls = new SearchControls();
return ldapTemplate.findAll(nameBase, searchControls, Team.class);
我使用SpringLDAP核心2.0.3,我找到了解决方案

首先

搜索控件添加适当的作用域

SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
return ldapTemplate.findAll(base, searchControls, Team.class);

Name nameBase = LdapUtils.newLdapName("dc=global");
return ldapTemplate.find(query().base(nameBase).where("ou").is("team"), Team.class);
更改查询参数以检查是否存在cn

return ldapTemplate.find(query().base(base).where("cn").isPresent(), Team.class);