0

我必须使用ContentSyncRequestControlUnboundid sdk 搜索已修改(添加、删除、修改)条目,但它显示所有已修改条目的状态。

到目前为止我做了什么

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();
    }

但这向我显示了所有已修改条目的状态。

同样,当我浏览ContentSyncRequestControlAPI 文档时,我发现要记住以下几点。但我不知道如何设置以下内容

1] 关联的搜索请求应该有一个 SearchResultListener 以便条目在返回后立即可用,而不必等待搜索完成和/或通过将条目存储在列表中来消耗大量内存仅在搜索完成时可用。

2] 从搜索返回的条目和引用应包括 ContentSyncStateControl 和相关的 entryUUID,并可能包含一个带有更新的同步会话状态的 cookie。您应该在搜索结果条目和引用上调用 getControl(ContentSyncStateControl.SYNC_STATE_OID) 以检索具有同步状态信息的控件。

3] 如果搜索完成,则 SearchResult 可能包含一个 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模式时,它会进入无限循环

那么有人可以帮我解决这个问题吗...?

4

2 回答 2

1

你好我有“同样”的问题

我刚开始使用一些演示代码,检索 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,);

        }
于 2014-04-09T15:30:05.743 回答
0

看起来您实际上并未将控件添加到搜索请求中。您应该在调用 ldapConnection.search 之前使用 searchRequest.addControl(control)。

于 2014-03-19T16:19:42.230 回答