Spring LDAP对子组的搜索导致CommunicationException[根本原因:UnknownHostException]
我们有一个普通的java命令行软件,它使用SpringLDAP执行递归LDAP搜索,从指定的组开始,搜索指定组和子组中的所有用户 Ldap搜索配置如下:Spring LDAP对子组的搜索导致CommunicationException[根本原因:UnknownHostException],ldap,spring-ldap,ldap-query,Ldap,Spring Ldap,Ldap Query,我们有一个普通的java命令行软件,它使用SpringLDAP执行递归LDAP搜索,从指定的组开始,搜索指定组和子组中的所有用户 Ldap搜索配置如下: LdapContextSource ctxSrc = buildLdapContextSource(); PoolingContextSource poolingContextSource = buildPoolingContextSource(ctxSrc); LdapTemplate ldapTemplate = n
LdapContextSource ctxSrc = buildLdapContextSource();
PoolingContextSource poolingContextSource = buildPoolingContextSource(ctxSrc);
LdapTemplate ldapTemplate = new LdapTemplate(poolingContextSource);
private LdapContextSource buildLdapContextSource() {
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl(config.getProperty(Config.LDAP_URL));
ctxSrc.setUserDn(config.getProperty(Config.LDAP_LOGIN_USERNAME));
ctxSrc.setPassword(config.getProperty(Config.LDAP_LOGIN_PASSWORD));
ctxSrc.setReferral("follow");
Map<String, Object> baseEnvironmentProperties = new HashMap<>();
baseEnvironmentProperties.put("java.naming.ldap.attributes.binary", "objectGUID");
ctxSrc.setBaseEnvironmentProperties(baseEnvironmentProperties);
ctxSrc.afterPropertiesSet();
return ctxSrc;
}
private PoolingContextSource buildPoolingContextSource(LdapContextSource ctxSrc) {
PoolingContextSource poolingContextSource = new MutablePoolingContextSource();
poolingContextSource.setContextSource(ctxSrc);
poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
poolingContextSource.setTestOnBorrow(true);
poolingContextSource.setTestWhileIdle(true);
return poolingContextSource;
}
两组的基本单位和组织单位相同。第一次搜索admin组工作正常。没有进行递归搜索,因此管理员不包含任何子组
第二个错误会导致:
ERROR - Encountered error with LDAP:
org.springframework.ldap.CommunicationException: example.org :389; nested exception is javax.naming.CommunicationException: example.org :389 [Root exception is java.net.UnknownHostException: example.org ]
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:108)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:328)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:604)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:594)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:482)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:498)
at LDAP.LdapImporter.searchLdapGroup(LdapImporter.java:128)
...(omitted lines from the software)
Caused by: javax.naming.CommunicationException: example.org :389 [Root exception is java.net.UnknownHostException: example.org ]
at com.sun.jndi.ldap.LdapReferralContext.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapReferralException.getReferralContext(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at javax.naming.directory.InitialDirContext.search(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.ldap.pool.factory.DirContextPoolableObjectFactory$FailureAwareContextProxy.invoke(DirContextPoolableObjectFactory.java:271)
at com.sun.proxy.$Proxy17.search(Unknown Source)
at org.springframework.ldap.pool.DelegatingDirContext.search(DelegatingDirContext.java:347)
at org.springframework.ldap.core.LdapTemplate$4.executeSearch(LdapTemplate.java:322)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)
... 11 more
Caused by: java.net.UnknownHostException: example.org
错误-LDAP遇到错误:
org.springframework.ldap.CommunicationException:example.org:389;嵌套异常为javax.naming.CommunicationException:example.org:389[根异常为java.net.UnknownHostException:example.org]
位于org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:108)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:328)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:604)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:594)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:482)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:498)
位于LDAP.LdapImporter.searchLdapGroup(LdapImporter.java:128)
…(软件中省略了行)
原因:javax.naming.CommunicationException:example.org:389[根异常为java.net.unknownhostexption:example.org]
位于com.sun.jndi.ldap.LdapReferralContext。(未知来源)
位于com.sun.jndi.ldap.LdapReferralException.getReferralContext(未知源)
位于com.sun.jndi.ldap.LdapCtx.searchAux(未知源)
在com.sun.jndi.ldap.LdapCtx.c_搜索(未知源)
在com.sun.jndi.toolkit.ctx.ComponentDirContext.p_搜索(未知源)
位于com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(未知源)
位于com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(未知源)
位于javax.naming.directory.InitialDirContext.search(未知源)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(未知源)
在sun.reflect.DelegatingMethodAccessorImpl.invoke处(未知源)
位于java.lang.reflect.Method.invoke(未知源)
位于org.springframework.ldap.pool.factory.DirContextPoolableObjectFactory$FailureAwareContextProxy.invoke(DirContextPoolableObjectFactory.java:271)
位于com.sun.proxy.$Proxy17.search(未知来源)
位于org.springframework.ldap.pool.DelegatingDirContext.search(DelegatingDirContext.java:347)
位于org.springframework.ldap.core.LdapTemplate$4.executeSearch(LdapTemplate.java:322)
位于org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)
... 还有11个
原因:java.net.UnknownHostException:example.org
例外情况下,“未知主机”与搜索库相同,例如:CN=example,CN=org-->org.springframework.ldap.CommunicationException:example.org:389
这种错误的原因是什么?这个错误似乎表明存在某种DNS问题,但由于第一次使用相同的基进行搜索是有效的,因此我感到困惑
在搜索错误时,所有其他人似乎都遇到了“连接被拒绝”错误或PartialResultExceptions,但这里的情况并非如此。LDAP似乎包含引用-/检查文档。。。也许你想忽略引用。忽略引用在现有情况下会产生一个新问题:javax.naming.PartialResultException:未处理的继续引用Kay,我可以忽略PartialResultExceptions,但我不确定忽略引用在实际搜索结果中会如何显示。。。但这位客户再次设置了他的广告组,事情开始神奇地运转起来,尽管我没有改变任何事情。
CN=SyncAdminsGroup,OU=Services,DC=example,DC=org
CN=SyncNormalGroup,OU=Services,DC=example,DC=org
ERROR - Encountered error with LDAP:
org.springframework.ldap.CommunicationException: example.org :389; nested exception is javax.naming.CommunicationException: example.org :389 [Root exception is java.net.UnknownHostException: example.org ]
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:108)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:328)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:604)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:594)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:482)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:498)
at LDAP.LdapImporter.searchLdapGroup(LdapImporter.java:128)
...(omitted lines from the software)
Caused by: javax.naming.CommunicationException: example.org :389 [Root exception is java.net.UnknownHostException: example.org ]
at com.sun.jndi.ldap.LdapReferralContext.<init>(Unknown Source)
at com.sun.jndi.ldap.LdapReferralException.getReferralContext(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source)
at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source)
at javax.naming.directory.InitialDirContext.search(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.ldap.pool.factory.DirContextPoolableObjectFactory$FailureAwareContextProxy.invoke(DirContextPoolableObjectFactory.java:271)
at com.sun.proxy.$Proxy17.search(Unknown Source)
at org.springframework.ldap.pool.DelegatingDirContext.search(DelegatingDirContext.java:347)
at org.springframework.ldap.core.LdapTemplate$4.executeSearch(LdapTemplate.java:322)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)
... 11 more
Caused by: java.net.UnknownHostException: example.org