Greetings apacheds devs,
I like using apacheds as ldap server for various projects - so first of
all thanks for this great software ;) However now I'm trying to run a
minimum apacheds programmatically. My goal is a preconfigured instance
with some test users and groups that can be used for application
testing. Unfortunately I'm running into an exception that I wasn't able
to solve so far. I attached used code and below is an according excerpt
of apacheds' log output.
I am able to get a server up and running (can connect with DS Studio)
but an exception (ERR_251_PARENT_NOT_FOUND) appears when I'm trying to
insert a group entry. I inserted acoording partition and a domain
entry, which works without errors. I assume that I missed something, so
any help is very much appreciated.
Thanks and kind regards,
Markus
[1] Used Maven dependency
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>2.0.0-M20</version>
</dependency>
[2] Log output
[17:53:24] INFO [org.apache.directory.server.core.api.CacheService] - no
custom cache configuration was set, loading the default cache configuration
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named alias
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] - No
cache with name alias exists, creating one
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named piar
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] - No
cache with name piar exists, creating one
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named entryDn
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] - No
cache with name entryDn exists, creating one
[17:53:33] WARN [org.apache.directory.api.ldap.model.ldif.LdifReader] -
The ldif file is empty
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition]
- Setting CacheRecondManager's cache size to 100
[17:53:33] INFO
[org.apache.directory.server.core.DefaultDirectoryService] - ApacheDS
shutdown hook has been registered with the runtime.
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named dnCache
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named alias
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named piar
[17:53:33] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named entryDn
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex] -
Setting CacheRecondManager's cache size to 100
[17:53:38] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named alias
[17:53:38] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named piar
[17:53:38] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named entryDn
[17:53:38] INFO
[org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition]
- Setting CacheRecondManager's cache size to 100
[17:53:38] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named system
[17:53:38] INFO [org.apache.directory.server.core.api.CacheService] - No
cache with name system exists, creating one
[17:53:39] INFO
[org.apache.directory.server.core.security.TlsKeyGenerator] - Keys and
self signed certificate successfully generated.
[17:53:40] INFO [org.apache.directory.server.core.api.CacheService] -
fetching the cache named groupCache
[17:53:40] INFO
[org.apache.directory.server.core.event.EventInterceptor] - Initializing ...
[17:53:40] INFO
[org.apache.directory.server.core.event.EventInterceptor] -
Initialization complete.
[17:53:40] WARN
[org.apache.directory.server.core.DefaultDirectoryService] - You didn't
change the admin password of directory service instance 'Starbuck's LDAP
server'. Please update the admin password as soon as possible to
prevent a possible security breach.
[17:53:40] DEBUG [org.apache.directory.server.OPERATION_LOG] - >>
LookupOperation : FilteringOperationContext for Dn 'uid=admin,ou=system', *
[17:53:40] DEBUG [org.apache.directory.server.OPERATION_LOG] - <<
LookupOperation successful
[17:53:40] DEBUG [org.apache.directory.server.OPERATION_LOG] - >>
LookupOperation : FilteringOperationContext for Dn 'uid=admin,ou=system', *
[17:53:40] DEBUG [org.apache.directory.server.OPERATION_LOG] - <<
LookupOperation successful
[17:53:40] INFO [org.apache.directory.server.ldap.LdapServer] -
Successful bind of an LDAP Service (11389) is completed.
[17:53:40] INFO [org.apache.directory.server.ldap.LdapServer] - Ldap
service started.
[17:53:40] DEBUG [org.apache.directory.server.OPERATION_LOG] - >>
AddOperation : AddContext for Dn 'dc=starwit,dc=de', added entry: Entry
dn[n]: dc=starwit,dc=de
objectClass: top
objectClass: domain
dc: starwit
[17:53:41] DEBUG [org.apache.directory.server.OPERATION_LOG] - <<
AddOperation successful
[17:53:41] DEBUG [org.apache.directory.server.OPERATION_LOG] - >>
hasEntryOperation : HasEntryContext for Dn 'dc=starwit,dc=de'
[17:53:41] DEBUG [org.apache.directory.server.OPERATION_LOG] - <<
HasEntryOperation successful
checking true
[17:53:41] DEBUG [org.apache.directory.server.OPERATION_LOG] - >>
AddOperation : AddContext for Dn 'ou=users,dc=starwit,dc=de', added
entry: Entry
dn[n]: ou=users,dc=starwit,dc=de
objectClass: top
objectClass: organizationalUnit
ou: users
Exception in thread "main"
org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException:
ERR_251_PARENT_NOT_FOUND Parent dc=starwit,dc=de not found
at
org.apache.directory.server.core.exception.ExceptionInterceptor.add(ExceptionInterceptor.java:165)
at
org.apache.directory.server.core.api.interceptor.BaseInterceptor.next(BaseInterceptor.java:422)
at
org.apache.directory.server.core.admin.AdministrativePointInterceptor.add(AdministrativePointInterceptor.java:1201)
at
org.apache.directory.server.core.api.interceptor.BaseInterceptor.next(BaseInterceptor.java:422)
at
org.apache.directory.server.core.authz.AciAuthorizationInterceptor.add(AciAuthorizationInterceptor.java:515)
at
org.apache.directory.server.core.api.interceptor.BaseInterceptor.next(BaseInterceptor.java:422)
at
org.apache.directory.server.core.referral.ReferralInterceptor.add(ReferralInterceptor.java:249)
at
org.apache.directory.server.core.api.interceptor.BaseInterceptor.next(BaseInterceptor.java:422)
at
org.apache.directory.server.core.authn.AuthenticationInterceptor.add(AuthenticationInterceptor.java:337)
at
org.apache.directory.server.core.api.interceptor.BaseInterceptor.next(BaseInterceptor.java:422)
at
org.apache.directory.server.core.normalization.NormalizationInterceptor.add(NormalizationInterceptor.java:131)
at
org.apache.directory.server.core.DefaultOperationManager.add(DefaultOperationManager.java:394)
at
org.apache.directory.server.core.shared.DefaultCoreSession.add(DefaultCoreSession.java:209)
at
org.apache.directory.server.core.shared.DefaultCoreSession.add(DefaultCoreSession.java:186)
at de.starwit.DirectoryRunner.main(DirectoryRunner.java:103)
package de.starwit;
import java.io.File;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.name.Dn;
import org.apache.directory.api.ldap.model.schema.SchemaManager;
import org.apache.directory.api.ldap.model.schema.registries.SchemaLoader;
import org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor;
import
org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor;
import org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader;
import org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager;
import org.apache.directory.api.util.exception.Exceptions;
import org.apache.directory.server.constants.ServerDNConstants;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.api.CacheService;
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.DnFactory;
import org.apache.directory.server.core.api.InstanceLayout;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.schema.SchemaPartition;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.server.core.partition.ldif.LdifPartition;
import org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
/**
*
*/
public class DirectoryRunner
{
private static DirectoryService directoryService;
private static LdapServer ldapServer;
private static File workDir = new File("d:\\tmp\\apacheds\\");
public static void main( String[] args ) throws Exception
{
FileUtils.deleteDirectory(workDir);
directoryService = new DefaultDirectoryService();
directoryService.setShutdownHookEnabled(true);
directoryService.setInstanceId("Starbuck's LDAP server");
ldapServer = new LdapServer();
ldapServer.setDirectoryService( directoryService );
TcpTransport ldapTransport = new TcpTransport(11389);
ldapServer.setTransports(ldapTransport);
directoryService.setInstanceLayout(new InstanceLayout(workDir));
CacheService cacheService = new CacheService();
cacheService.initialize(directoryService.getInstanceLayout());
directoryService.setCacheService( cacheService );
initSchemaPartition();
JdbmPartition systemPartition = new
JdbmPartition(directoryService.getSchemaManager(),
directoryService.getDnFactory());
systemPartition.setId("system");
systemPartition.setPartitionPath( new File(
directoryService.getInstanceLayout().getPartitionsDirectory(),
systemPartition.getId() ).toURI() );
systemPartition.setSuffixDn( new Dn( ServerDNConstants.SYSTEM_DN ) );
systemPartition.setSchemaManager( directoryService.getSchemaManager() );
directoryService.setSystemPartition(systemPartition);
directoryService.getChangeLog().setEnabled(true);
directoryService.setDenormalizeOpAttrsEnabled(true);
SingleFileLdifPartition configPartition = new
SingleFileLdifPartition(directoryService.getSchemaManager(),
directoryService.getDnFactory());
configPartition.setId("config");
configPartition.setPartitionPath(new
File(directoryService.getInstanceLayout().getConfDirectory(),
"config.ldif").toURI());
configPartition.setSuffixDn(new Dn(directoryService.getSchemaManager(),
"ou=config"));
configPartition.setSchemaManager(directoryService.getSchemaManager());
configPartition.setCacheService(cacheService);
configPartition.initialize();
directoryService.addPartition(configPartition);
Partition myPartition = addPartition("starwit", "dc=starwit,dc=de",
directoryService.getDnFactory());
directoryService.addPartition(myPartition);
directoryService.startup();
ldapServer.start();
Entry e1 = new DefaultEntry(directoryService.getSchemaManager(),
"dc=starwit,dc=de");
e1.add("objectClass", "top", "domain");
e1.add("dc", "starwit");
Entry e2 = new DefaultEntry(directoryService.getSchemaManager(),
"ou=users,dc=starwit,dc=de");
e2.add("objectClass","top","organizationalUnit");
e2.add("ou","users");
CoreSession session = directoryService.getAdminSession();
session.add(e1);
System.out.println("checking " + session.exists("dc=starwit,dc=de"));
session.add(e2);
/*
File ldifImportFile = new File("test.ldif");
LdifFileLoader loader = new
LdifFileLoader(directoryService.getAdminSession(),
ldifImportFile.getAbsolutePath());
loader.execute();*/
}
private static void initSchemaPartition() throws Exception {
InstanceLayout instanceLayout = directoryService.getInstanceLayout();
File schemaPartitionDirectory = new File(
instanceLayout.getPartitionsDirectory(), "schema" );
if ( schemaPartitionDirectory.exists() ) {
System.out.println( "schema partition already exists, skipping
schema extraction" );
} else {
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(
instanceLayout.getPartitionsDirectory() );
extractor.extractOrCopy();
}
SchemaLoader loader = new LdifSchemaLoader( schemaPartitionDirectory );
SchemaManager schemaManager = new DefaultSchemaManager( loader );
schemaManager.loadAllEnabled();
List<Throwable> errors = schemaManager.getErrors();
if ( errors.size() != 0 ) {
throw new Exception( I18n.err( I18n.ERR_317,
Exceptions.printErrors( errors ) ) );
}
directoryService.setSchemaManager(schemaManager);
LdifPartition schemaLdifPartition = new LdifPartition(schemaManager,
directoryService.getDnFactory());
schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());
SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
schemaPartition.setWrappedPartition(schemaLdifPartition);
directoryService.setSchemaPartition(schemaPartition);
}
private static Partition addPartition(String partitionId, String
partitionDn, DnFactory dnFactory) throws Exception {
JdbmPartition partition = new
JdbmPartition(directoryService.getSchemaManager(), dnFactory);
partition.setId(partitionId);
partition.setPartitionPath(new
File(directoryService.getInstanceLayout().getPartitionsDirectory(),
partitionId).toURI());
partition.setSuffixDn(new Dn(directoryService.getSchemaManager(),
partitionDn));
partition.initialize();
return partition;
}
}