...
Code Block |
---|
|
...
public void delete(DeleteOperationContext opContext)
throws LdapOperationNotSupportedException {
throw new LdapOperationNotSupportedException(
MODIFICATION_NOT_ALLOWED_MSG, ResultCodeEnum.UNWILLING_TO_PERFORM);
}
...
|
Although this example should be minimal, some methods need more attention. At least if we want to see the partitiion in an LDAP and not only in the error logs ...
The important methods are hasEntry, lookup and search. The following code is the search method. Please note that it ignores search scopes other than BASE and search filters completely in order to have simple code.
Code Block |
---|
|
public EntryFilteringCursor search(SearchOperationContext ctx)
throws Exception {
if (ctx.getDn().equals(this.suffixDn)) {
switch (ctx.getScope()) {
case OBJECT:
// return a result with the only entry we have
return new BaseEntryFilteringCursor(
new SingletonCursor<ServerEntry>(this.helloEntry), ctx);
}
}
// return an empty result
return new BaseEntryFilteringCursor(new EmptyCursor<ServerEntry>(), ctx);
}
|
For the other methods, take a look in the source code. TBD: search
Using the partition
Embedded mode
Code Block |
---|
|
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();
}
}
|
...