hi Stefan,
the partition impl requires few changes(at least to pass the test)
which I have attached as a patch.
HTH
Kiran Ayyagari
Stefan Zoerner wrote:
Hi all,
I try to write a very (!) simple example for a custom partition, in
order tom provide a starting point in the docs. Unfortunately I fail to
add my implementation to the DirectoryService, and I have no idea why.
This is how I add my partition ...
--8<--
directoryService = new DefaultDirectoryService();
directoryService.setShutdownHookEnabled(true);
// Determine an appropriate working directory
File workingDir = new File("work");
directoryService.setWorkingDirectory(workingDir);
// Create a new partition
EnvironmentPartition envPartition = new EnvironmentPartition();
envPartition.setId("env");
envPartition.setSuffix("ou=env");
envPartition.init(directoryService);
directoryService.addPartition(envPartition);
directoryService.startup();
-->8--
EnvironmentPartition is my implementation of the Partition interface.
Currently it does not make a lot, I was just trying to add it and start
the server. Adding is successful, but calling the startUp() method
causes an exception:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.688
sec <<< FAILURE!
testAddPartition(org.apache.directory.samples.partition.env.EnvironmentPartitionTest)
Time elapsed: 2.64 sec <<< ERROR!
org.apache.directory.shared.ldap.exception.LdapNameNotFoundException:
ou=env
at
org.apache.directory.server.core.partition.DefaultPartitionNexus.getPartition(DefaultPartitionNexus.java:1097)
at
org.apache.directory.server.core.partition.DefaultPartitionNexus.search(DefaultPartitionNexus.java:964)
at
org.apache.directory.server.core.authz.TupleCache.initialize(TupleCache.java:138)
at
org.apache.directory.server.core.authz.TupleCache.<init>(TupleCache.java:111)
at
org.apache.directory.server.core.authz.AciAuthorizationInterceptor.init(AciAuthorizationInterceptor.java:210)
at
org.apache.directory.server.core.interceptor.InterceptorChain.register0(InterceptorChain.java:439)
at
org.apache.directory.server.core.interceptor.InterceptorChain.register(InterceptorChain.java:395)
at
org.apache.directory.server.core.interceptor.InterceptorChain.init(InterceptorChain.java:255)
at
org.apache.directory.server.core.DefaultDirectoryService.initialize(DefaultDirectoryService.java:1385)
at
org.apache.directory.server.core.DefaultDirectoryService.startup(DefaultDirectoryService.java:840)
at
org.apache.directory.samples.partition.env.EnvironmentPartitionTest.testAddPartition(EnvironmentPartitionTest.java:29)
---
Although it is totally clear to my, that my partition won't work (most
methost throw an OperationNotSupportedException), I thought about
starting by simply adding it and starting the server correctly.
I was able to determin that getUpSuffixDn() and getSuffixDn() have been
called fom my partition. I assume, that I
a) do not return valid values
b) adding as described above is not sufficient
Does anybody have any idea. I have provided my code as a maven project
here:
https://svn.apache.org/repos/asf/directory/sandbox/szoerner/envpartition
Thanks in advance,
Stefan
Index: src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java
===================================================================
--- src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java (revision 711172)
+++ src/main/java/org/apache/directory/samples/partition/env/EnvironmentPartition.java (working copy)
@@ -3,7 +3,10 @@
import javax.naming.OperationNotSupportedException;
import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.cursor.EmptyCursor;
import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.filtering.BaseEntryFilteringCursor;
import org.apache.directory.server.core.filtering.EntryFilteringCursor;
import org.apache.directory.server.core.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -32,6 +35,8 @@
private String suffix;
+ private DirectoryService service;
+
public String getId() {
return id;
}
@@ -87,6 +92,7 @@
public void init(DirectoryService service) throws Exception {
LOG.debug("init()");
+ this.service = service;
}
public boolean isInitialized() {
@@ -106,7 +112,10 @@
LOG.debug("getSuffixDn()");
- return new LdapDN(suffix); // TODO: Check, whether OK ...
+ LdapDN dn = new LdapDN(suffix);
+ dn.normalize( service.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+
+ return dn; // TODO: Check, whether OK ...
}
@Override
@@ -114,7 +123,7 @@
LOG.debug("getUpSuffixDn()");
- return getSuffixDn();
+ return new LdapDN( suffix );
}
@Override
@@ -156,7 +165,7 @@
throws Exception {
LOG.debug("search()");
- return null;
+ return new BaseEntryFilteringCursor( new EmptyCursor<ServerEntry>(), ctx );
}
@Override