Reputation: 1378
I need to add bulk data into the LDAP server from the ldif file. I researched of java APIs but can't find the suitable one
I already tried with LdapTestUtils but it requires a server restart. I need another way except this
Upvotes: 0
Views: 1451
Reputation: 1378
It can also be achieved via LdapTemplate. LdapParser will parse the record from ldif file in the form of LdapAttribute then bind this record via ldapTemplate.bind
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://192.168.99.101:389/");
contextSource.setUserDn("uid=admin,dc=abc,dc=com");
contextSource.setPassword(********);
contextSource.setPooled(false);
contextSource.afterPropertiesSet();
LdapTemplate template = new LdapTemplate(contextSource);
LdifParser parser = new LdifParser(new ClassPathResource("schema.ldif"));
parser.open();
while (parser.hasMoreRecords()) {
LdapAttributes record = parser.getRecord();
LdapName dn = record.getName();
template.bind(dn, null, record);
}
Upvotes: 0
Reputation: 3762
You will need to use a separate library that has API supporting LDIF import. Once such library is Apache Directory LDAP API. The library is in general compatible with most of the LDAP servers.
Refer the documentation, The LdifFileLoader class has features to import LDIF, in tandem with DefaultDirectoryService class (unfortunately I am unable to locate my earlier code demonstrating the LDIF import). You could refer this post, which shows how to use the above, though it deals with a problem of a different type.
I am not sure of the LDAP server you are using, however, you could give the above a shot and check.
Upvotes: 1