Active directory 通过ContentSyncRequestControl进行未绑定sdk搜索,不显示修改的条目

Active directory 通过ContentSyncRequestControl进行未绑定sdk搜索,不显示修改的条目,active-directory,ldap,openldap,spring-ldap,unboundid-ldap-sdk,Active Directory,Ldap,Openldap,Spring Ldap,Unboundid Ldap Sdk,我必须在Unbounded sdk中使用ContentSyncRequestControl搜索已修改(添加、删除、修改)的条目,但它会显示所有条目以及已修改的条目 到目前为止我做了什么 LDAPConnection ldapConnection = null; try { /*Apache LDAP*/ ldapConnection = new LDAPConnection("192.168.0.0", 389); ldapConnecti

我必须在Unbounded 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(boolean isCritical, ContentSyncRequestMode mode, ASN1OctetString cookie, boolean reloadHint) 
当我使用
ContentSyncRequestMode.REFRESH\u ONLY
时,它会给我所有的条目,但当我使用
ContentSyncRequestMode.REFRESH\u和\u PERSIST
模式时,它会以无限循环的方式运行


有人能帮我吗

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

您好,我有“相同”的问题

我只是从一些演示代码开始,检索cookie,在下一次运行中提供它。。。 仍然获取搜索返回的相同数据,但条目未更改-( 我们在RHEL6上使用OpenLdap版本2.4.35

这里有一些代码(实际上不是java——但谁在乎呢)


我做了更改,但仍然无法获得修改的条目请检查我的更新…您可以添加一些代码,以便我能够更好地了解如何使用此ContentSyncRequestControl搜索修改的条目吗
ContentSyncRequestControl(boolean isCritical, ContentSyncRequestMode mode, ASN1OctetString cookie, boolean reloadHint) 
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,);

        }