Class InMemoryDirectory

java.lang.Object
net.shibboleth.shared.testing.InMemoryDirectory

public class InMemoryDirectory extends Object
Manages an instance of the in-memory directory server for unit testing.
  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Class logger.
    • directoryServer

      @Nonnull private final com.unboundid.ldap.listener.InMemoryDirectoryServer directoryServer
      Directory server.
    • customServerSocketFactory

      @Nonnull private final InMemoryDirectory.CustomServerSocketFactory customServerSocketFactory
      Server socket factory to track created sockets.
  • Constructor Details

  • Method Details

    • addSuccessSaslBindHandlers

      private void addSuccessSaslBindHandlers(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig config)
      Adds DIGEST-MD5 and EXTERNAL SASL bind handlers that always return success.
      Parameters:
      config - to add SASL bind handlers to
    • add

      public void add(String... ldifLines)
      Adds the supplied LDIF lines to the directory server.
      Parameters:
      ldifLines - to add
      Throws:
      RuntimeException - if an error occurs adding the LDIF
    • openConnectionCount

      public long openConnectionCount()
      Returns the number of open sockets.
      Returns:
      number of open sockets
    • start

      public void start()
      Starts the directory server.
      Throws:
      RuntimeException - if the in-memory directory server cannot be started
    • getListenPort

      public int getListenPort()
      Returns the port the server is listening on.
      Returns:
      port number
    • stop

      public void stop(boolean closeConnections)
      Stops the directory server. Note that in general resources should be configured so that LDAP connections are closed at the conclusion of a test method or test class.
      Parameters:
      closeConnections - whether to close existing connections
    • getKeyManagerFactory

      private static KeyManagerFactory getKeyManagerFactory(Resource keystore) throws GeneralSecurityException, IOException
      Creates a KeyManagerFactory from the supplied resource. A keystore password of "changeit" is assumed.
      Parameters:
      keystore - resource to read
      Returns:
      key manager factory built from the keystore
      Throws:
      GeneralSecurityException - if the keystore password is incorrect
      IOException - if the resource cannot be read
    • getTrustManagerFactory

      private static TrustManagerFactory getTrustManagerFactory(Resource keystore) throws GeneralSecurityException, IOException
      Creates a TrustManagerFactory from the supplied resource. A keystore password of "changeit" is assumed.
      Parameters:
      keystore - resource to read
      Returns:
      trust manager factory built from the keystore
      Throws:
      GeneralSecurityException - if the keystore password is incorrect
      IOException - if the resource cannot be read
    • loadKeyStore

      private static KeyStore loadKeyStore(Resource keystore, String password) throws GeneralSecurityException, IOException
      Creates a new KeyStore from the supplied resource.
      Parameters:
      keystore - resource to read
      password - to unlock the keystore
      Returns:
      keystore
      Throws:
      GeneralSecurityException - if the keystore cannot be created from the resource
      IOException - if the resource cannot be read