Reputation: 2819
I have to search modified (add, delete, modify) entries using ContentSyncRequestControl
in Unboundid sdk, but it showing all the entries instate of modified entries.
what I have done so far
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();
}
but this shows me all entries instate of modified entries.
also when I go through ContentSyncRequestControl
class API documentation then I found following things to keep in mind.
but I dont know how I can set this following things
1] The associated search request should have a SearchResultListener so that entries will be made available as soon as they are returned rather than having to wait for the search to complete and/or consuming a large amount of memory by storing the entries in a list that is only made available when the search completes.
2] Entries and references returned from the search should include the ContentSyncStateControl with the associated entryUUID and potentially a cookie with an updated sync session state. You should call getControl(ContentSyncStateControl.SYNC_STATE_OID) on the search result entries and references in order to retrieve the control with the sync state information.
3] If the search does complete, then the SearchResult may include a ContentSyncDoneControl with updated sync state information. You should call getResponseControl(ContentSyncDoneControl.SYNC_DONE_OID) to retrieve the control with the sync state information.
can any one help me on this ? Thanks...
EDIT
after adding the control I am still getting the all entries instate of modified entries.
right now I am using
ContentSyncRequestControl(ContentSyncRequestMode mode)
constructor so how can I use this form Of constructor can some one help me
ContentSyncRequestControl(boolean isCritical, ContentSyncRequestMode mode, ASN1OctetString cookie, boolean reloadHint)
when I am using ContentSyncRequestMode.REFRESH_ONLY
it gives me all entries but when I use ContentSyncRequestMode.REFRESH_AND_PERSIST
mode the it goes in infinite loop.
so can some one help me on this...?
Upvotes: 0
Views: 566
Reputation: 135
Hello i have the "same" problem
I just started with some democode, retrieve the cookie, provided it in the next run... still get the same data returned by the search, but the entry was NOT changed ;-( We are using OpenLdap Version 2.4.35 on RHEL6.
here some code (actually c# not java - but who cares).
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,);
}
Upvotes: 1
Reputation: 1726
It doesn't look like you're actually adding the control to the search request. You should use searchRequest.addControl(control) before calling ldapConnection.search.
Upvotes: 0