我正在使用 UnboundID SDK 中的 InMemoryDirectoryServer。如何处理来自 ldap 客户端的 ldap 请求?
这是我找到的代码(在How to get DN and password with UnboundID):
public class MyLDAPListenerRequestHandler extends LDAPListenerRequestHandler {
@Override
public LDAPListenerRequestHandler newInstance(
LDAPListenerClientConnection arg0) throws LDAPException {
System.out.println("New Instance.");
LDAPConnectionOptions option = new LDAPConnectionOptions();
LDAPConnection connection = new LDAPConnection(option, "yourIPadress", yourport);
System.out.println("Connected to : " + connection.getConnectedAddress()+ " " + connection.getConnectedPort());
return this;
}
@Override
public LDAPMessage processBindRequest(int arg0, BindRequestProtocolOp arg1,
List<Control> arg2) {
System.out.println(arg1.getBindDN());
System.out.println(arg1.getSimplePassword());
return null;
}
这是捕获绑定请求并在下处理它的正确方法吗
public LDAPMessage processBindRequest(int arg0, BindRequestProtocolOp arg1,
List<Control> arg2) {
功能?处理后,我是否必须手动发送绑定到 InMemoryDirectoryServer 实例?
你好,我们又见面了,
基于:http: //sourceforge.net/p/ldap-sdk/discussion/1001257/thread/796c129d
在我看来,可以修改 InMemoryRequestHandler 源并更改它回复 ldap 请求的方式(搜索、修改、...)。
对于别名取消引用,我修改了
for (最终 SearchResultEntry e : entryList)
循环函数:
公共同步 LDAPMessage processSearchRequest(final int messageID, final SearchRequestProtocolOp request, final List controls) {
使用此代码:
for (final SearchResultEntry e : entryList)
{
// flag which is set if for loop finds an alias entry.
boolean aliasEntryFound = false;
// aliasedObjectName reference to real entry.
String aliasedObjectName = null;
// Check that dereferencing is turned on.
if (aliasDeref)
{
// check if entry is an alias entry.
for (String objectClass : e.getAttributeValues("objectClass"))
{
if (objectClass.equalsIgnoreCase("alias"))
{
// Put on flag.
aliasEntryFound = true;
// Get real entry path.
aliasedObjectName = e.getAttributeValue("aliasedObjectName");
}
}
}
// If entry e is actually alias entry, then ...
if (aliasEntryFound && aliasedObjectName != null)
{
// Build new SearchRequest query with aliasedObjectName as real DN.
final SearchRequestProtocolOp newRequest = new SearchRequestProtocolOp(
aliasedObjectName, request.getScope(), request.getDerefPolicy(),
request.getSizeLimit(), request.getTimeLimit(),
false, request.getFilter(), request.getAttributes());
// Call recursively processSearchRequest() with new request value.
processSearchRequest(messageID, newRequest, controls);
}
else
{
try {
connection.sendSearchResultEntry(messageID, e, e.getControls());
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(),
le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs())), le.getResponseControls());
}
}
}
...
}
在 InMemoryRequestHandler 类的开头某处,我添加了:
private boolean aliasDeref = true;
我只是将其用作标志来控制是否要取消引用别名。
我的代码只是如何对搜索请求进行别名取消引用的示例。使用自定义请求处理程序,只能提醒 ldap 请求,而不是 ldap 回复或结果。
让我知道是否有更好的方法来做到这一点。谢谢