Versions Compared

Key

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

...

Using the interceptor

Embedded mode

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.ldap.LdapServer;
import org.apache.directory.server.protocol.shared.transport.TcpTransport;

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

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

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

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

        List<Interceptor> is = directoryService.getInterceptors();
        is.add(new PasswordHashInterceptor());
        directoryService.setInterceptors(is);

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

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

Adding it to a server.xml file

...