我必须在Unboundid sdk中使用ContentSyncRequestControl
搜索修改(添加,删除,修改)条目,但它会显示已修改条目的所有条目。
到目前为止我做了什么
LDAPConnection ldapConnection = null;
try {
/*Apache LDAP*/
ldapConnection = new LDAPConnection("192.168.0.0", 389);
ldapConnection.bind("uid=test,ou=system", "mypassword");
Scanner sc = new Scanner(System.in);
ASN1OctetString cookie = null;
int choice = 3;
while (true) {
SearchRequest searchRequest = new SearchRequest(ldapConnection
.getRootDSE().getAttributeValue("namingContexts"),
SearchScope.SUB, "(&(objectclass=person))",
"createTimestamp","modifyTimestamp","sn","mobile","givenName","ucMiddleName","mail",
"isDeleted");
ContentSyncRequestControl control = new ContentSyncRequestControl(ContentSyncRequestMode.REFRESH_AND_PERSIST);
//added control to request
searchRequest.addControl(control);
final SearchResult searchResult = ldapConnection.search(searchRequest);
java.util.List<SearchResultEntry> entries = searchResult
.getSearchEntries();
int count = 0;
for (SearchResultEntry entry : entries) {
System.out.println(entry.getAttributes());
++count;
}
System.out.println("Press 0 for exit");
choice = sc.nextInt();
if (choice == 0) {
System.exit(0);
}
}
} catch (LDAPSearchException e) {
e.printStackTrace();
} catch (LDAPException e) {
e.printStackTrace();
}
但这显示了修改条目的所有条目实例。
当我通过ContentSyncRequestControl
课程 API documentation 时,我发现要记住以下事项。
但我不知道如何设置以下内容
1]关联的搜索请求应该有一个SearchResultListener 条目将在退回后立即提供 而不是必须等待搜索完成和/或消费 通过将条目存储在仅列表中来存储大量内存 搜索完成后可用。
2]从搜索返回的条目和引用应包括 ContentSyncStateControl与相关的entryUUID和潜在的 具有更新的同步会话状态的cookie。你应该打电话 搜索上的getControl(ContentSyncStateControl.SYNC_STATE_OID) 结果条目和引用,以便检索控件 同步状态信息。
3]如果搜索确实完成,则SearchResult可能包含a ContentSyncDoneControl具有更新的同步状态信息。你应该 调用getResponseControl(ContentSyncDoneControl.SYNC_DONE_OID)来 使用同步状态信息检索控件。
任何人都能帮助我吗?感谢...
修改 的
添加控件后,我仍然获得修改条目的所有条目实例。
现在我正在使用
ContentSyncRequestControl(ContentSyncRequestMode mode)
构造函数所以如何使用这种形式的构造函数可以帮助我一些
ContentSyncRequestControl(boolean isCritical, ContentSyncRequestMode mode, ASN1OctetString cookie, boolean reloadHint)
当我使用ContentSyncRequestMode.REFRESH_ONLY
时,它会为我提供所有条目,但当我使用ContentSyncRequestMode.REFRESH_AND_PERSIST
模式时, 会进入无限循环 。
所以有人可以帮我这个......?
答案 0 :(得分:1)
你好,我有&#34;相同&#34;问题
我刚开始使用一些democode,检索cookie,在下次运行时提供它... 仍然获得搜索返回的相同数据,但条目没有改变;-( 我们在RHEL6上使用OpenLdap版本2.4.35。
这里有一些代码(实际上是c#而不是java - 但是谁在乎)。
public void LdapConnect()
{
//connect
LDAPConnection connection = new LDAPConnection("SERVER", 389, "cn=USER,dc=ksz,dc=ch", "PASSWORD");
//search
//ContentSyncRequestControl syncReqCtrl = new ContentSyncRequestControl((ContentSyncRequestMode.REFRESH_ONLY);
//TEST TEST TEST
com.unboundid.asn1.ASN1OctetString cookieOld = new com.unboundid.asn1.ASN1OctetString("rid=111,csn=20140409143056.252248Z#000000#000#000000");
ContentSyncRequestControl syncReqCtrl = new ContentSyncRequestControl(ContentSyncRequestMode.REFRESH_ONLY, cookieOld, false);
//reloadHint - Indicates whether the client wishes to retrieve an initial content during an incremental update if the server determines that the client cannot reach convergence with the server data.
SearchRequest searchReq = new SearchRequest("dc=ksz,dc=ch", SearchScope.SUB, "(uid=student)", "*");//new string[]{"mail", "username"});
searchReq.addControl(syncReqCtrl);
SearchResult searchRes = connection.search(searchReq);
String mail = null;
if (searchRes.getEntryCount() > 0)
{
SearchResultEntry entry = (SearchResultEntry)searchRes.getSearchEntries().get(0);
mail = entry.getAttributeValue("mail");
//eat cookie here or later???
ContentSyncStateControl syncStateCtrl = (ContentSyncStateControl)entry.getControl(ContentSyncStateControl.SYNC_STATE_OID);
com.unboundid.asn1.ASN1OctetString leckerSearchCookie = syncReqCtrl.getCookie();
}
//syncrepl
//TODO in future use:
//-AsyncSearchResultListener
//request state, provide cookie if you have one. REFRESH_ONLY:just to this point, no psuh notification
ContentSyncDoneControl syncReqDoneCtrl = (ContentSyncDoneControl)searchRes.getResponseControl(ContentSyncDoneControl.SYNC_DONE_OID);
if (syncReqDoneCtrl != null)
{
//have a cookie
com.unboundid.asn1.ASN1OctetString leckerEndCookie = syncReqDoneCtrl.getCookie();
}
//syncReqState.getMode().name
//state
//ContentSyncState syncState = null;
//ContentSyncStateControl syncStateCtrl = new ContentSyncStateControl(syncState,);
}
答案 1 :(得分:0)
您实际上并未将控件添加到搜索请求中。您应该在调用ldapConnection.search。
之前使用searchRequest.addControl(control)