...
On the mailing list, people ask regularly on how to write a custom partition. If you simply plan to add another suffix to ApacheDS (besides dc=example.,dc=com, for instance) in order to store data, it is not necessary to write any code. You can simply add some lines to the configuration. The following is for those developers who plan to use implement another storage mechanism than the provided default.
...
Currently, the sources are checked in here
In order to build it, simply check it out and type "mvn install".
...
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; } ... |
We assume that the suffix starts with "ou=" in order to create an entry of object class organizational unit. If someone tries to set a suffix which starts with another attribute for the RDN, the setSuffix will throw an exception.
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 read only partition, the implementation in our case is minimalistic. Here is the delete method as an example.
...
Code Block | ||||
---|---|---|---|---|
| ||||
$ ldapsearch -h localhost -p 10389 -D "uid=admin,ou=system" -w secret \\
-b "" -s base "(objectclass=*)" namingContexts
version: 1
dn:
namingContexts: ou=system
namingContexts: ou=helloWorld
namingContexts: ou=schema
$
$ ldapsearch -h localhost -p 10389 -D "uid=admin,ou=system" -w secret \\
-b "ou=helloWorld" -s base "(objectclass=*)"
version: 1
dn: ou=helloWorld
objectClass: organizationalUnit
objectClass: top
description: hello, world
description: a minimal partition
ou: helloWorld
$
|
...
Currently, the sources are checked in here
In order to build it, simply check it out and type "mvn install".
...