...
In order to build it, simply check it out and type "mvn install".
Implementing the class HelloWorldPartition
The following UML class diagram depicts the structure of the little example.
Using the partition
Embedded mode
In order to be a partition , HelloWorldPartition implements the corresponding interface from org.apache.directory.server.core.partition. It has an association to it's only entry (which will hold the "hello, world" method). This entry is created in the init life cycle method of the partition, which looks like this:
Code Block | ||||
---|---|---|---|---|
| ||||
...
public void init(DirectoryService core) throws Exception {
// Create LDAP DN
suffixDn = new LdapDN(suffix);
suffixDn.normalize(core.getRegistries().getAttributeTypeRegistry().getNormalizerMapping());
Rdn rdn = suffixDn.getRdn();
// Create the only entry in this partition
ServerEntry entry = new DefaultServerEntry(core
.getRegistries(), this.suffixDn);
entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
SchemaConstants.ORGANIZATIONAL_UNIT_OC);
entry.put(SchemaConstants.OU_AT, rdn.getUpValue().toString());
entry.put("description", "hello, world", "a minimal partition");
this.helloEntry = entry;
}
...
{code:java}
The _Partition_interface requires to implement many methods for all the operations a partition should support (adding, deleting, modifying entries ...). Due to the fact, that this is a readonly partition, the implementation in our case is minimalistic. Here is the _add_ method as an example.
{code:java}
...
public void delete(DeleteOperationContext opContext)
throws LdapOperationNotSupportedException {
throw new LdapOperationNotSupportedException(
MODIFICATION_NOT_ALLOWED_MSG, ResultCodeEnum.UNWILLING_TO_PERFORM);
}
...
{code:java}
TBD: search
h3. Using the partition
h4. Embedded mode
{code:java}
| ||||
Code Block | ||||
java | java |
package org.apache.directory.samples.partition.hello;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.ldap.LdapService;
import org.apache.directory.server.protocol.shared.SocketAcceptor;
public class Main {
public static void main(String[] args) throws Exception {
DirectoryService directoryService;
SocketAcceptor socketAcceptor;
LdapService ldapService;
directoryService = new DefaultDirectoryService();
directoryService.setShutdownHookEnabled(true);
socketAcceptor = new SocketAcceptor(null);
ldapService = new LdapService();
ldapService.setSocketAcceptor(socketAcceptor);
ldapService.setDirectoryService(directoryService);
ldapService.setIpPort(10389);
HelloWorldPartition helloPartition = new HelloWorldPartition();
helloPartition.setSuffix("ou=helloWorld");
helloPartition.init(directoryService);
directoryService.addPartition(helloPartition);
directoryService.startup();
ldapService.start();
}
}
|
...
Note that the class HelloWorldPartition has to be in the class path of the server. Withgout, starting the server leads to a ClassNotFoundException. You can copy the jar file which results from the build to the lib directory and adjust the command line parameters in the apacheds.sh script.
...
Verification
After adding the HelloWorldPartition to the directory service like above (embedded or via configuration in server.xml), you can browse it with an LDAP browser like the one from Apache Directory Studio. Here are some screen shots.
...
In order to build it, simply check it out and type "mvn install".
verification
After adding the SystemPropertyPartition to the directory service (embedded or via configuration in server.xml), you can browse it with an LDAP browser like the one from Apache Directory Studio. Here is a screen shot.
...