首页 新闻 搜索 专区 学院

请问Spring LDAP 在链接AD域的时候报ConnectException: Connection refused: connect]]

0
悬赏园豆:50 [已解决问题] 解决于 2017-09-14 17:32

我在用Spring Ldap链接AD域的时候报PartialResultException [Root exception is (我尝试着随便写个密码,链接的时候会提示密码错误)

(用java自带的可以链接成功)

我从看文档说可以抑制,结果抑制了还是不行,有没有朋友知道这是为什么?求告知

 

这是我xml的配置文件

 

这是报的异常

org.springframework.ldap.PartialResultException: nested exception is javax.naming.PartialResultException [Root exception is javax.naming.CommunicationException: wzax.com:389 [Root exception is java.net.ConnectException: Connection refused: connect]]
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:216)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:385)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:1617)
    at com.wzax.springldap.MyPersonRepoImpl.getPassword(MyPersonRepoImpl.java:316)
    at com.wzax.springldap.PersonRepoTest.testPassword(PersonRepoTest.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: javax.naming.PartialResultException [Root exception is javax.naming.CommunicationException: wzax.com:389 [Root exception is java.net.ConnectException: Connection refused: connect]]
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMoreImpl(AbstractLdapNamingEnumeration.java:237)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMore(AbstractLdapNamingEnumeration.java:189)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:365)
    ... 35 more
Caused by: javax.naming.CommunicationException: wzax.com:389 [Root exception is java.net.ConnectException: Connection refused: connect]
    at com.sun.jndi.ldap.LdapReferralContext.<init>(LdapReferralContext.java:96)
    at com.sun.jndi.ldap.LdapReferralException.getReferralContext(LdapReferralException.java:150)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMoreReferrals(AbstractLdapNamingEnumeration.java:325)
    at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMoreImpl(AbstractLdapNamingEnumeration.java:227)
    ... 37 more
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:211)
    at com.sun.jndi.ldap.Connection.createSocket(Connection.java:363)
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:203)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
    at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1614)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2746)
    at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:319)
    at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:192)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:151)
    at com.sun.jndi.url.ldap.ldapURLContextFactory.getObjectInstance(ldapURLContextFactory.java:52)
    at javax.naming.spi.NamingManager.getURLObject(NamingManager.java:601)
    at javax.naming.spi.NamingManager.processURL(NamingManager.java:381)
    at javax.naming.spi.NamingManager.processURLAddrs(NamingManager.java:361)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:333)
    at com.sun.jndi.ldap.LdapReferralContext.<init>(LdapReferralContext.java:119)
    ... 40 more


这样写也不行

 

public static void main(String[] args) {
         LdapContextSource contextSource = new LdapContextSource();  
            contextSource.setUrl("ldap://192.168.2.28:389");  
            contextSource.setUserDn("wangx@wzax.com");  
            contextSource.setPassword("SSOldap@1");  
            contextSource.setPooled(false);  
            contextSource.afterPropertiesSet(); // important  
              
            LdapTemplate template = new LdapTemplate();  
            template.setContextSource(contextSource);  
              
            Boolean result = template.authenticate("dc=wzax,dc=com", "", "SSOldap@1");  
    }

 

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/xuan/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/xuan/.m2/repository/org/slf4j/slf4j-log4j12/1.7.18/slf4j-log4j12-1.7.18.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
17:25:58.282 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
17:25:58.290 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
17:25:58.291 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://192.168.2.28:389
17:25:58.500 [main] DEBUG o.s.l.c.s.AbstractContextSource - Got Ldap context on server 'ldap://192.168.2.28:389'
Exception in thread "main" org.springframework.ldap.InvalidSearchFilterException: Empty filter; nested exception is javax.naming.directory.InvalidSearchFilterException: Empty filter; remaining name 'dc=wzax,dc=com'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:143)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1441)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1426)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1369)
    at com.wzax.springldap.最后一次.main(最后一次.java:20)
Caused by: javax.naming.directory.InvalidSearchFilterException: Empty filter; remaining name 'dc=wzax,dc=com'
    at com.sun.jndi.ldap.Filter.encodeFilterString(Filter.java:57)
    at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:546)
    at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1985)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1844)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358)
    at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:276)
    at org.springframework.ldap.core.LdapTemplate$3.executeSearch(LdapTemplate.java:303)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)

砖家变专家的主页 砖家变专家 | 初学一级 | 园豆:42
提问于:2017-09-12 17:01
< >
分享
最佳答案
1

是webservice吧,有几种可能,第一,服务没启动,第二,密匙不对,第三配置问题,你可以打断点调试

收获园豆:50
金琥 | 老鸟四级 |园豆:2570 | 2017-09-14 09:14

你用的脚本吗? 怎么回答和csdn上的一模一样?

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 16:30

@砖家变专家: 我只是在csdn上也回答了问题

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 16:37


@砖家变专家:

Error: javax.naming.CommunicationException: [server]:[port] [Root exception is java.net.ConnectException: Connection refused: connect] 错误:javax.naming.CommunicationException:[服务器]:[端口] [根异常java.net.ConnectException:连接被拒绝:连接]

Cause: The port name you have specified for the LDAP/AD server is incorrect. 原因:你有服务器的端口名指定为LDAP / AD是不正确的。

转自:http://blog.csdn.net/baidu_18607183/article/details/51038183

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 16:40

@金琥: 你看我用java自己的可以连

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 16:42

@金琥: 好吧 哈哈 我说怎么一模一样

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 16:42

@砖家变专家: 我觉得你可以再去检查下自己的这个端口名

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 16:46

@金琥: 刚刚图片没传上来,这是我用java自己的ldap写的,也可正常使用,应该是spring ldap配置的问题,但我不知道该怎么配

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 16:50

@砖家变专家: 参考:http://angelbill3.iteye.com/blog/2321533

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 17:10

@砖家变专家: 我觉得你可以去找下配置的相关资料,这个也许就能找到问题了

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 17:10

@金琥: 这个博客很给力,官方的文档我看过了,没有写AD域的  java文档是英文的,我尝试着看看,git那个怎么用?下载下来导入eclipse里面吗?

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 17:17

@砖家变专家: 你说的是github吗?

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 17:21

@金琥: 是的  我下载下来了,想看看里面吗有没有关于链接AD域的

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 17:22

    public static void main(String[] args) {
         LdapContextSource contextSource = new LdapContextSource();  
            contextSource.setUrl("ldap://192.168.2.28:389");  
            contextSource.setUserDn("wangx@wzax.com");  
            contextSource.setPassword("SSOldap@1");  
            contextSource.setPooled(false);  
            contextSource.afterPropertiesSet(); // important  
              
            LdapTemplate template = new LdapTemplate();  
            template.setContextSource(contextSource);  
              
            Boolean result = template.authenticate("dc=wzax,dc=com", "", "SSOldap@1");  
    }
  

刚把代码跑了一下 还是这样

 

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/xuan/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/xuan/.m2/repository/org/slf4j/slf4j-log4j12/1.7.18/slf4j-log4j12-1.7.18.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
17:25:58.282 [main] DEBUG o.s.l.c.s.AbstractContextSource - AuthenticationSource not set - using default implementation
17:25:58.290 [main] DEBUG o.s.l.c.s.AbstractContextSource - Not using LDAP pooling
17:25:58.291 [main] DEBUG o.s.l.c.s.AbstractContextSource - Trying provider Urls: ldap://192.168.2.28:389
17:25:58.500 [main] DEBUG o.s.l.c.s.AbstractContextSource - Got Ldap context on server 'ldap://192.168.2.28:389'
Exception in thread "main" org.springframework.ldap.InvalidSearchFilterException: Empty filter; nested exception is javax.naming.directory.InvalidSearchFilterException: Empty filter; remaining name 'dc=wzax,dc=com'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:143)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:309)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:642)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:578)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1441)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1426)
    at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1369)
    at com.wzax.springldap.最后一次.main(最后一次.java:20)
Caused by: javax.naming.directory.InvalidSearchFilterException: Empty filter; remaining name 'dc=wzax,dc=com'
    at com.sun.jndi.ldap.Filter.encodeFilterString(Filter.java:57)
    at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:546)
    at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1985)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1844)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358)
    at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:276)
    at org.springframework.ldap.core.LdapTemplate$3.executeSearch(LdapTemplate.java:303)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:363)

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 17:27

@砖家变专家: 

接下来fork、clone一个repo,如果不懂,这里是一个指导手册。按照readme里讲述的,一步步做下来,确保项目能在你本机上运行。如果遇到了readme中没有的问题或者错误,那么这就是你的第一个贡献!你可以编辑readme,把遇到的问题说的清楚,好让在你后来加入项目的人收益。你也可以删除readme,在文档中编辑你遇到的错误。直接读别人已经写好的代码并作出改进,会让人望而生畏。

转自:http://blog.csdn.net/qianlong4526888/article/details/11529981

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 17:29

@砖家变专家: 我个人建议  断点调试一下

金琥 | 园豆:2570 (老鸟四级) | 2017-09-14 17:30

@金琥: 好的 我研究一下,刚入行还不了解fork、clone一个repo,的意思,我看一下指导手册, 研究研究,非常感谢您耐心的回答

砖家变专家 | 园豆:42 (初学一级) | 2017-09-14 17:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册