pingidentity / ldapsdk

UnboundID LDAP SDK for Java
Other
327 stars 79 forks source link

can i sync data from ldap server by pull(every some time sync the changed data) with ldapsdk ? #132

Closed bossfriday closed 2 years ago

bossfriday commented 2 years ago

hope some example code. thank you very much!

dirmgr commented 2 years ago

This ultimately depends on the type of server that you’re using, as different servers offer different ways of discovering changes. Some of them include:

bossfriday commented 2 years ago

thank and appreciate your help firstly , follow your advice, i try to use ContentSyncRequestControl to accomplish the sync. i think, it shouldn't give any cookie when retrieve an initial full copy of the data , and it should give a cookie when retrieve a changed data. So i have the bellow try , but i met 2 question: 1: if open "baseSearchRequest.addControl(syncRequestCtl);", it will get error: resultCode=12 (unavailable critical extension) 2: it always "hasn't any ResponseControl", so i have no way to get the cookie ;

i can't find any example code about this in /ldap-sdk/docs/examples/index.html , can you help me correct the below test code ? thank you very much and hopes your help ...

` public static void main(String[] args) throws Exception {

    LDAPConnection conn = new LDAPConnection(LDAP_HOST, LDAP_PORT, LDAP_BIND_DN, LDAP_BIND_PASSWORD);
    SearchRequest baseSearchRequest = new SearchRequest(LDAP_BASE_DN, SearchScope.ONE, LDAP_EAB_SEARCH_FILTER);
    ContentSyncRequestControl syncRequestCtl = new ContentSyncRequestControl(ContentSyncRequestMode.REFRESH_ONLY);
    baseSearchRequest.addControl(syncRequestCtl);
    SearchResult searchResult = conn.search(baseSearchRequest);
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
        System.out.println(entry.toString());
    }

    if (searchResult.hasResponseControl()) {
        ContentSyncDoneControl syncReqDoneCtrl = (ContentSyncDoneControl) searchResult.getResponseControl(ContentSyncDoneControl.SYNC_DONE_OID);
        if (syncReqDoneCtrl != null) {
            ASN1OctetString cookie = syncReqDoneCtrl.getCookie();
            System.out.println(cookie.stringValue());
        }
    } else {
        System.out.println("hasn't any ResponseControl");
    }
}

`

dirmgr commented 2 years ago

A result of "unavailable critical extension" means that either the directory server you're trying to use doesn't support that control, or perhaps there's something else that doesn't permit you to use it. For example, maybe the server needs some special configuration to enable support for that control, or maybe the authenticated client doens't have permission to use it.

What type of server are you using? The best way to determine what controls a server supports would be to retrieve the root DSE (the entry with a DN of "") and look at its supportedControl attribute. If you see a value of "1.3.6.1.4.1.4203.1.9.1.1" for that attribute, then that indicates that it does support that control. However, if you don't see that OID, then that means that either the server doesn't support that control, or maybe that it hasn't been configured to enable it. You could also see if the root DSE gives any clue about what else it might support (for example, if there are other supported control values that might relate to a control that could be used to provide synchronization, or if there are other attributes that indicate the presence of a changelog or something like that).

I can assist you with the LDAP SDK, but I'm not the best person to try to help you with whatever type of server you're using. I believe that all of the most common directory server implementations support at least one of the mechanisms I outlined above, but none of them support all of them. I'm not really in a position to assist with directory server-specific configuration for most types of servers. Those questions are probably better suited to people more directly involved with those products.

bossfriday commented 2 years ago

thank u very much firstly ! I decide to do full sync every time in order to suit to most situation, so i have to implement the changed sync by myself in an other way (use db as a buffer and get the changed data by myself, at last notify the changed data to someone ).