[英]How to handle LDAP connection?
I'm trying to implement the following: 我正在尝试实现以下内容:
I have an Importer class which registers so called Processor
s, and then executes them by iterating over them and calling execute ( Processor
is an interface and contains a method void execute()
). 我有一个Importer类,它注册所谓的
Processor
s,然后通过遍历它们并调用execute来执行它们( Processor
是一个接口并包含一个方法void execute()
)。
What those processors do is connect to an LDAP, and do certain tasks, eg retrieves a list of persons and stores them into a database, or reads certain privileges and maps them to groups. 这些处理器所做的是连接到LDAP,并执行某些任务,例如检索人员列表并将其存储到数据库中,或者读取某些特权并将它们映射到组。
This all works out quite well... except I just don't know how to handle the LDAP connection. 一切都很好...除了我只是不知道如何处理LDAP连接。
Here are some ideas: 以下是一些想法:
execute()
method or execute()
方法或 Handle the connection to the LDAP server with a Strategy method that is a required parameter. 使用作为必需参数的Strategy方法处理与LDAP服务器的连接。 This de-couples and isolates the code.
这解耦并隔离了代码。 You should prefer the UnboundID LDAP SDK for this work - and the SDK supports the ability to create an in-memory directory server so there is no need to use "mock" or "fake" connections.
您应该更喜欢UnboundID LDAP SDK来完成这项工作 - 并且SDK支持创建内存中目录服务器的功能,因此不需要使用“模拟”或“假”连接。 Also, you can examine the blog post "LDAP: Programming Practices" .
另外,您可以查看博客文章“ LDAP:编程实践” 。
Build it somewhere else and inject it into the application. 在其他地方构建它并将其注入应用程序。
If you don't have JEE6 which provides dependency injection via CDDI then you can use Spring framework as a workaround. 如果您没有通过CDDI提供依赖注入的JEE6,那么您可以使用Spring框架作为解决方法。
It has two benefits. 它有两个好处。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.