Root exception is java.net.SocketException: Unconnected sockets not implemented

使用LDAP 的 636 端口链接AD域服务器的时候,

我的配置链接配置如下:

public static Properties sslInit() throws NamingException {
    Properties env = new Properties();
    System.setProperty("com.sun.jndi.ldap.object.disableEndpointIdentification", "true");
    env.put(Context.SECURITY_PROTOCOL, "ssl");
    env.put("java.naming.ldap.factory.socket", "kl.idaas.id.sender.util.ADSSL2.CustomSSLSocketFactory");
    env.put(DirContext.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://101.2.14.118");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.setProperty(Context.REFERRAL, "ignore");
    env.put(Context.SECURITY_PRINCIPAL, "cn=Aadmin,cn=Users,dc=asserv,dc=com");
    env.put(Context.SECURITY_CREDENTIALS, "123456");
    env.put(Context.AUTHORITATIVE, "true");
    env.put("com.sun.jndi.ldap.connect.timeout", "500"); 
    return env;
}

链接服务的时候报如下错误

javax.naming.CommunicationException: xxx:xx
 [Root exception is java.net.SocketException: Unconnected sockets not implemented]
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:216)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:137)
    at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1615)
    at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749)
    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.getUsingURLs(LdapCtxFactory.java:210)
    at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:153)
    at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:83)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.init(InitialContext.java:244)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:101)
    at kl.idaas.id.sender.util.ADUtils2Test.modifyPwd(ADUtils2Test.java:26)
    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:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.net.SocketException: Unconnected sockets not implemented
    at javax.net.SocketFactory.createSocket(SocketFactory.java:125)
    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 com.sun.jndi.ldap.Connection.createSocket(Connection.java:303)
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:203)
    ... 39 more
Caused by: java.lang.UnsupportedOperationException
    at javax.net.SocketFactory.createSocket(SocketFactory.java:123)
    ... 45 more

实在是个大坑,整整研究了3天,网上各种找资料,没有相同的报错。最后配置参数一个一个注释掉试,直到试到 env.put("com.sun.jndi.ldap.connect.timeout", "500"); 的时候才找到是这个参数的问题。

百思不得解,设置个超时时间不是很正常的吗?为啥不让设置。后来才想明白,ssl链接就没有超时的说法,客户端与服务器之间链接只要网络不断就不会断,没有超时的概念。只有当是389端口链接的时候(即http链接)的时候才可以设置env.put("com.sun.jndi.ldap.connect.timeout", "500");这个参数

最后得出结论:636端口链接(即https)的时候不能设置这个参数。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值