Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Using the interceptor

Embedded mode

The following Java code starts an ApacheDS embedded in a main method. The list of interceptors is complemented with the example interceptor. We insert it exactly behind the NormalizingInterceptor.

Code Block
java
java
package org.apache.directory.samples.interceptor.pwdhash;

import java.util.List;

import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.interceptor.Interceptor;
import org.apache.directory.server.core.normalization.NormalizationInterceptor;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;

/**
 * Main class which starts an embedded server with the interceptor addedinserted to theinto
 * the chain.
 */
public class Main {

    public static void main(String[] args) throws Exception {

        DirectoryService directoryService = new DefaultDirectoryService();
        directoryService.setShutdownHookEnabled(true);

        LdapServerList<Interceptor> ldapServerinterceptors = new LdapServer();
        ldapServer.setDirectoryService(directoryService);
directoryService.getInterceptors();

        // Find Normalization interceptor in chain
        int insertionPosition = -1;
        for (int pos = 0; pos < interceptors.size(); ++pos) {
           ldapServer.setAllowAnonymousAccess(true);

 Interceptor interceptor = interceptors.get(pos);
            if (interceptor instanceof NormalizationInterceptor) {
          List<Interceptor> is      insertionPosition = directoryService.getInterceptors();pos;
            }
        }

        // insert our new interceptor just behind
        isinterceptors.add(insertionPosition + 1, new PasswordHashInterceptor());
        directoryService.setInterceptors(is(interceptors);

        LdapServer ldapServer = new LdapServer();
        ldapServer.setDirectoryService(directoryService);
        ldapServer.setAllowAnonymousAccess(true);

        TcpTransport ldapTransport = new TcpTransport(10389);
        ldapServer.setTransports(ldapTransport);

        directoryService.startup();
        ldapServer.start();
    }
}

...