`

LDAP connection issue

阅读更多
Problem1:

Sometimes we can not get LDAP connection from LDAP server.

Cause1:
We can not close LDAP connection when program is end.

Solution1-1(don't do that):


Currently our code to close LDAP connection are as below,

LdapContext cladptx = null;
NamingEnumeration<?> results = null;
try {
cladptx = createConnection();
results = cladptx.search(ldapConnector.getEntry(), filter, constraints); } catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
try {
if (cladptx != null) {
cladptx.close();
}
} catch (Exception e2) {
logger.error(e2.getMessage(), e2);
}
}

But actually LDAP connection was not closed completely.

Solution1-2(Good solution):

We need to close various parameters of context and NamingEnumeration.Code as below,

LdapContext cladptx = null;
NamingEnumeration<?> results = null;
try {
cladptx = createConnection();
results = cladptx.search(ldapConnector.getEntry(), filter, constraints);

} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
try {
if(results!=null) {
results.close();
}
if (cladptx != null) {
cladptx.close();
}
} catch (Exception e2) {
logger.error(e2.getMessage(), e2);
}
}

Problem2:

After I closed various parameters and ran a test which loops 4000 times on a LDAP client application, I observed the following errors in Windows Operating System when the load increased beyond a certain threshold:

    javax.naming.CommunicationException: localhost:10389 [Root exception is java.net.BindException: Address already in use: connect]
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:210)
    at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
    </init></init>

Cause2:

The causes for the errors are that the dynamic ports in the OS are running out so that client application can not make any more connections to LDAP server.
Usually LDAP server is running on a specific port (say 10389) and when a connection is created from client, that is assigned a port in the range of dynamic ports which is defined as a property of Windows OS. This issue is not visible on Linux.

So the above errors can occur when no available ports are left.

Solution2:

We'd better use connection pool to solve this problem.See below code,

InitialDirContext context = null;
try {
System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", "50");
Hashtable<String,String> env = new Hashtable<String,String>();
//env.put("com.sun.jndi.ldap.connect.pool", "true");
context = new InitialDirContext(env);
} catch (NamingException e) {
logger.error(e.getMessage(),e);
}

Conclusion
1. Enable LDAP connection pooling when creating the connection to the LDAP..
2. Close all sub Contexts and NamingEnumerations derived from a particular LDAP connection Context, close them explicitly at the end of their usage.
分享到:
评论

相关推荐

    LDAP入門LDAP入門LDAP入門

    LDAP入門,LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門LDAP入門

    LdapBrowser2.82版和LDAP使用手册

    LdapBrowser2.82版,能浏览服务器的ldap数据,还有一份word详细使用文档及ldap安装说明

    对LDAP的基本操作(Spring-ldap)+Ext实现显示LDAP的树状结构

    资源没有对LDAP创建的内容。 资源主要有: rar包:一个Web工程, 主要有,利用Spring-ldap对LDAP的基本操作(查询,增删改);Extjs实现的对Ldap的树状结构的显示,结构有点类似Softerra LDAP;一个测试类。 pdf:...

    ldap 浏览器 LdapBrowser282

    LdapBrowser282 ldap浏览器 LdapBrowser 查看openldap的好工具。 使用需要有JDK环境。

    LDAP服务器.pdf

    1 LDAP 基础 LDAP 的英文全称是 Lightweight Directory Access Protocol, 一般都简称为 LDAP。 它是基于 X.500 标准的,但是简单多了并且可以根据需要定制。与 X.500 不同,LDAP 支 持 TCP/IP,这对访问 Internet ...

    LDAP使用手册.doc

    LDAP是轻量级目录访问协议的简称(Lightweight Directory Access Protocol).用于访问目录服务。它是X.500目录访问协议的移植,但是简化了实现方法。本文给大家带来LDAP使用手册,需要的可以来下载看看 LDAP的优点 1:...

    ldap安装与客户端ldapadmin windows

    ldap安装与客户端ldapadmin windows版本,

    RuoYi前后端不分离项目整合LDAP

    基于RuoYi框架,使用的是ruoyi前后端不分离的版本,实现对LDAP的整合 基于RuoYi框架,使用的是ruoyi前后端不分离的版本,实现对LDAP的整合 基于RuoYi框架,使用的是ruoyi前后端不分离的版本,实现对LDAP的整合 基于...

    c操作ldap例子c操作ldap例

    c操作ldap例c操作ldap例c操作ldap例c操作ldap例c操作ldap例c操作ldap例c操作ldap例c操作ldap例c操作ldap例

    svn安装配置与ldap整合

    这是一遍比较完整的linux下svn+apche+ldap安装配置手册,根据本人实际安装整理后的文档,目前都算是最新版本。其中ldap使用sun的opends,个人感觉比openldap要方便,当然重点不是用什么ldap而是如何配置。 主要包括...

    spring boot集成ldap

    项目中使用spring boot框架集成了ldap协议的方法,调用了增删改查的API,基本实现了spring boot对于ldap的所有方法,只要搭建好了ldap服务器,改一下配置文件即可运行。

    什么是LDAP连接工具?如何利用好它.docx

    # LDAP连接工具 LDAP是一种轻量级目录访问协议,用于在网络中访问分布式目录服务。要连接到LDAP目录,需要一种LDAP连接工具。 以下是一些常用的LDAP连接工具: ## 1. Apache Directory Studio Apache Directory ...

    LDAP客户端GitHub-Ldap.zip

    GitHub-Ldap 是 GitHub Enterprise 的一部分,是 LDAP 客户端。GitHub-Ldap 封装了 Net::LDAP,方便易用。 标签:GitHub

    java操作ldap类

    java操作ldap类java操作ldap类java操作ldap类

    jdbc-ldap spring

    class="org.springframework.jdbc.... ${ldap.datasource.driverClassName}" /&gt; ${ldap.datasource.url}" /&gt; ${ldap.datasource.username}" /&gt; ${ldap.datasource.password}" /&gt; &lt;/bean&gt;

    LdapAdmin-1.8.3 win64下的ldap可视化管理工具

    LdapAdmin-1.8.3 win64下的ldap可视化管理工具,非常好用哦。

    LDAPBrowser 4.5 x86 LDAP测试工具

    LDAPBrowser4.5 x86 32位系统使用的LDAP测试工具

    LDAP统一身份认证

    LDAP的研究及其在统一身份认证系统中的应用 LDAP的研究与在校园网统一身份认证中的应用 基于LDAP的统一身份认证的设计与实现 基于LDAP的统一身份认证系统的实现 基于LDAP的校园网统一身份认证系统设计 基于LDAP和...

    ldapadmin,最简单的LDAP管理客户端,免安装

    LDAPAdmin,最简单的LDAP管理客户端

    Spring LDAP API(Spring LDAP 开发文档).CHM

    Spring LDAP。 官网 Spring LDAP API。 Spring LDAP 开发文档。

Global site tag (gtag.js) - Google Analytics