Class SampleDirectory

  • All Implemented Interfaces:
    EventListener, javax.servlet.ServletContextListener

    public class SampleDirectory
    extends Object
    implements javax.servlet.ServletContextListener
    Sample in-memory LDAP directory server for demonstration and testing purposes. Access is limited to read and bind (authenticate) only.

    The directory server is configured by a set of "sampleDirectoryServer.*" properties which can be overridden with Java system properties, see SampleDirectory.Configuration.

    The sample directory implements ServletContextListener. This enables its automatic startup and shutdown in a servlet container (Java web server), such as Apache Tomcat. When started from a servlet container the directory configuration is obtained from a properties file specified by a context parameter named sampleDirectoryServer.configurationFile.

    • Method Detail

      • start

        public void start​(SampleDirectory.Configuration config)
                   throws com.unboundid.ldap.sdk.LDAPException,
                          IOException,
                          com.unboundid.ldif.LDIFException
        Starts the sample in-memory directory server.
        Parameters:
        config - The sample directory server configuration. Must not be null.
        Throws:
        com.unboundid.ldap.sdk.LDAPException - If the in-memory directory server couldn't be started or its initialisation failed.
        IOException - If a schema file was specified and it couldn't be read.
        com.unboundid.ldif.LDIFException - If a schema file was specified that is not valid LDIF.
      • stop

        public void stop()
        Stops the sample in-memory directory server (if previously started). Information and status messages are logged at INFO level.
      • contextInitialized

        public void contextInitialized​(javax.servlet.ServletContextEvent sce)
        Handler for servlet context startup events. Launches the sample in-memory directory server (if enabled per configuration). Exceptions are logged at ERROR level, information and status messages at INFO level.

        The sample directory server configuration is retrieved from a properties file which location is specified by a servlet context parameter named sampleDirectory.configurationFile.

        Specified by:
        contextInitialized in interface javax.servlet.ServletContextListener
        Parameters:
        sce - A servlet context event.
      • contextDestroyed

        public void contextDestroyed​(javax.servlet.ServletContextEvent sce)
        Handler for servlet context shutdown events. Stops the sample in-memory directory server (if previously started).
        Specified by:
        contextDestroyed in interface javax.servlet.ServletContextListener
        Parameters:
        sce - A servlet context event.