1

I need to insert bulk data into the LDAP server for this I used LdapTestUtils class but got some error

Gradle dependencies

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testCompile group: 'org.springframework.ldap', name: 'spring-ldap-test', version: '2.3.2.RELEASE'
}

Java code

public static void loadData() throws Exception
    {
        // Bind to the directory
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl("ldap://127.0.0.1:10389");
        contextSource.setUserDn("uid=admin,ou=system");
        contextSource.setPassword("secret");
        contextSource.setPooled(false);
        contextSource.afterPropertiesSet();
        // Create the Sprint LDAP template
        LdapTemplate template = new LdapTemplate(contextSource);
        // Clear out any old data - and load the test data
        LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com"));
        LdapTestUtils.loadLdif(contextSource, new ClassPathResource("schema.ldif"));
    }

Link - https://www.programcreek.com/java-api-examples/index.php?api=org.springframework.ldap.test.LdapTestUtils first example

Error - org.apcahe.directory.server.core can not be resolve it is indirectly referred from require.class file

What dependency am i missing? Is there any other way to do so?

Stephane
  • 11,836
  • 25
  • 112
  • 175
UDIT JOSHI
  • 1,298
  • 12
  • 26

1 Answers1

1
public static void loadData() throws Exception
    {
        // Bind to the directory
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl("ldap://127.0.0.1:10389");
        contextSource.setUserDn("uid=admin,ou=system");
        contextSource.setPassword("secret");
        contextSource.setPooled(false);
        contextSource.afterPropertiesSet();
        // Create the Sprint LDAP template
        LdapTemplate template = new LdapTemplate(contextSource);
        // Clear out any old data - and load the test data
     LdapTestUtils.cleanAndSetup(
                contextSource,
                LdapUtils.newLdapName("dn to remove"),
                new ClassPathResource("schema.ldif"));

          }

cleanAndSetup method works for me but it will restart server as well

UDIT JOSHI
  • 1,298
  • 12
  • 26