0

Based on this I use following code to start in memory ldap server

// Create the configuration to use for the server.
InMemoryDirectoryServerConfig config =
     new InMemoryDirectoryServerConfig("dc=example,dc=com");
config.addAdditionalBindCredentials("cn=Directory Manager", "password");
config.setSchema(null); //!!! without this line I get an error thanks for https://stackoverflow.com/a/17921875/2674303
// Create the directory server instance, populate it with data from the
// "test-data.ldif" file, and start listening for client connections.
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
ds.importFromLDIF(true, "test-data.ldif");
ds.startListening();

// Get a client connection to the server and use it to perform various
// operations.
LDAPConnection conn = ds.getConnection();
SearchResultEntry entry = conn.getEntry("dc=example,dc=com");

// Do more stuff here....

// Disconnect from the server and cause the server to shut down.
conn.close();
ds.shutDown(true);

I want to import structure from exsiting ldap server. I use apach directory studio for that: enter image description here

I save the content to the file with name test-data.ldif

And when I run the code above I get an error:

Exception in thread "main" LDAPException(resultCode=32 (no such object), errorMessage='Unable to add entry 'CN=8437C3D8-7689-4200-BF38-79E4AC33DFA0,CN=Operations,CN=DomainUpdates,CN=System,DC=example,DC=com' because its parent entry 'CN=Operations,CN=DomainUpdates,CN=System,DC=example,DC=com' does not exist in the server.', matchedDN='DC=example,DC=com', ldapSDKVersion=6.0.9, revision=42839ddf0d77d954805fbbe3cce73a792af40474)

I've found out that the root cause that entry with dn

CN=8437C3D8-7689-4200-BF38-79E4AC33DFA0,CN=Operations,CN=DomainUpdates,CN=System,DC=example,DC=com

is the first entry in the exported file and if to rearrange entries manually to make sure that all parents are created above - export will be successful. So for that entry we should place defiition of entry

DC=example,DC=com

then

CN=System,DC=example,DC=com

then

CN=DomainUpdates,CN=System,DC=example,DC=com

then

CN=Operations,CN=DomainUpdates,CN=System,DC=example,DC=com

and finally

CN=8437C3D8-7689-4200-BF38-79E4AC33DFA0,CN=Operations,CN=DomainUpdates,CN=System,DC=example,DC=com'

So I neded either have feature in unboundId ldap Sdk to be a bit more intelligent or have a feature in apache directory studio to export parents first.

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • 1
    There is a tool called ldifsort that will fix the LDIF file for you. Google for it you can easily find several references for it. I believe it originally came from SUN Microsystems or Netscape. https://ldapwiki.com/wiki/Wiki.jsp?page=LDIF%20Sort%20Tools – jwilleke Jul 22 '23 at 15:40
  • Thank you for your comment, But using this link I didn't get the answer how to get anf run this tool locally. – gstackoverflow Jul 24 '23 at 13:05
  • This seems like a relatively simple problem to address: read in the LDIF objects, sort them based on the path length of their dn (the number of comma-delimited components in the dn), and you're done. – larsks Jul 24 '23 at 22:01
  • I tried it but the problem that in a dump I see some several lines like this: ` dn:: Q049aXZhbiDQl9GD0LXQutGJ0LwsQ049VXNlcnMsREM9aW5ubyxEQz10ZWNo objectClass: organizationalPerson objectClass: person objectClass: top objectClass: user ` Althought I exported the ldif using root `DC=hello,DC=world` – gstackoverflow Jul 25 '23 at 07:22
  • Those items like "dn:: Q049aXZhbiDQl9GD0LXQutGJ0LwsQ049VXNlcnMsREM9aW5ubyxEQz10ZWNo" imply there are "binary" entries present in the DN. And Google for ldifsort there are a lot of references. – jwilleke Jul 27 '23 at 09:30
  • @ jwilleke There are a lot of information but I can't combine it get the working solution. Will appreciate if you could provide detailed answer – gstackoverflow Jul 27 '23 at 12:41
  • @jwilleke For me it looks extremely weird that I can't just export dump from ldap server and then use it to import to another server without any weird manipulations – gstackoverflow Jul 27 '23 at 13:05

0 Answers0