[java-opensaml] branch main updated: Use new shared InMemoryDirectory.

Daniel Fisher dfisher at vt.edu
Fri Nov 11 01:12:31 UTC 2022


This is an automated email from the git hooks/post-receive script.

dfisher pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=42c774c16cc7567061457935e3638d5ee1c4488c

The following commit(s) were added to refs/heads/main by this push:
     new 42c774c16 Use new shared InMemoryDirectory.
42c774c16 is described below

commit 42c774c16cc7567061457935e3638d5ee1c4488c
Author: Daniel Fisher <dfisher at vt.edu>
AuthorDate: Thu Nov 10 20:06:56 2022 -0500

    Use new shared InMemoryDirectory.
    
    Add dependency on shib-testing artifact.
---
 opensaml-security-impl/pom.xml                     | 12 +--
 .../security/trust/impl/InMemoryDirectory.java     | 89 ----------------------
 .../impl/TrustEngineX509TrustManagerTest.java      | 29 ++++---
 3 files changed, 25 insertions(+), 105 deletions(-)

diff --git a/opensaml-security-impl/pom.xml b/opensaml-security-impl/pom.xml
index 7f59f0ee7..019d1d237 100644
--- a/opensaml-security-impl/pom.xml
+++ b/opensaml-security-impl/pom.xml
@@ -96,6 +96,12 @@
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>${shib-shared.groupId}</groupId>
+            <artifactId>shib-testing</artifactId>
+            <scope>test</scope>
+        </dependency>
+
         <dependency>
             <groupId>org.cryptacular</groupId>
             <artifactId>cryptacular</artifactId>
@@ -114,12 +120,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>com.unboundid</groupId>
-            <artifactId>unboundid-ldapsdk</artifactId>
-            <scope>test</scope>
-        </dependency>
-        
         <dependency>
             <groupId>${slf4j.groupId}</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
diff --git a/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/InMemoryDirectory.java b/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/InMemoryDirectory.java
deleted file mode 100644
index faea1775a..000000000
--- a/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/InMemoryDirectory.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.opensaml.security.trust.impl;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.security.GeneralSecurityException;
-
-import javax.annotation.Nonnull;
-
-import com.unboundid.ldap.listener.InMemoryDirectoryServer;
-import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
-import com.unboundid.ldap.listener.InMemoryListenerConfig;
-import com.unboundid.ldap.sdk.LDAPException;
-import com.unboundid.ldif.LDIFReader;
-import com.unboundid.util.ssl.KeyStoreKeyManager;
-import com.unboundid.util.ssl.SSLUtil;
-
-import net.shibboleth.shared.logic.Constraint;
-
-/**
- * Manages an instance of the in-memory directory server.
- */
-public class InMemoryDirectory {
-
-    /** Directory server. */
-    @Nonnull private final InMemoryDirectoryServer directoryServer;
-
-    /**
-     * Constructor with STARTTLS support.
-     * 
-     * @param ldif the LDIF resource to be imported
-     * @param keystore to use for startTLS
-     * 
-     * @throws LDAPException if the in-memory directory server cannot be created
-     * @throws IOException if the LDIF resource cannot be imported
-     */
-    public InMemoryDirectory(@Nonnull final File ldif, @Nonnull final File keystore) throws LDAPException,
-            IOException {
-        Constraint.isNotNull(ldif, "LDIF resource cannot be null");
-        final InMemoryDirectoryServerConfig config =
-                new InMemoryDirectoryServerConfig("dc=example,dc=org");
-        try {
-            final SSLUtil sslUtil =
-                    new SSLUtil(new KeyStoreKeyManager(keystore, "changeit".toCharArray()), null);
-            config.setListenerConfigs(
-                InMemoryListenerConfig.createLDAPConfig(
-                    "default", InetAddress.getByName("localhost"), 10389, sslUtil.createSSLSocketFactory()));
-        } catch (GeneralSecurityException e) {
-            throw new IOException("Error reading keystore", e);
-        }
-        config.addAdditionalBindCredentials("cn=Directory Manager", "password");
-        directoryServer = new InMemoryDirectoryServer(config);
-        directoryServer.importFromLDIF(true, new LDIFReader(new FileInputStream(ldif)));
-    }
-
-    /**
-     * Starts the directory server.
-     * 
-     * @throws LDAPException if the in-memory directory server cannot be started
-     */
-    public void start() throws LDAPException {
-        directoryServer.startListening();
-    }
-
-    /**
-     * Stops the directory server.
-     */
-    public void stop() {
-        directoryServer.shutDown(true);
-    }
-}
diff --git a/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/TrustEngineX509TrustManagerTest.java b/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/TrustEngineX509TrustManagerTest.java
index 8a4b12e54..fd13e5a63 100644
--- a/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/TrustEngineX509TrustManagerTest.java
+++ b/opensaml-security-impl/src/test/java/org/opensaml/security/trust/impl/TrustEngineX509TrustManagerTest.java
@@ -17,13 +17,15 @@
 
 package org.opensaml.security.trust.impl;
 
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.Optional;
 
 import javax.annotation.Nonnull;
 
+import net.shibboleth.shared.testing.InMemoryDirectory;
+
 import org.cryptacular.util.KeyPairUtil;
 import org.ldaptive.ConnectException;
 import org.ldaptive.Connection;
@@ -38,12 +40,13 @@ import org.ldaptive.SearchResponse;
 import org.ldaptive.ssl.SslConfig;
 import org.opensaml.security.credential.BasicCredential;
 import org.opensaml.security.credential.impl.StaticCredentialResolver;
+import org.springframework.core.io.ClassPathResource;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import com.unboundid.ldap.sdk.LDAPException;
+import static org.testng.Assert.assertEquals;
 
 /**
  * Test of {@link TrustEngineX509TrustManager} implementation.
@@ -51,20 +54,25 @@ import com.unboundid.ldap.sdk.LDAPException;
 public class TrustEngineX509TrustManagerTest {
 
     private final static String DATA_PATH = "src/test/resources/org/opensaml/security/ldap/impl/";
-    
+
+    private final static String DATA_CLASSPATH = "/org/opensaml/security/ldap/impl/";
+
     private InMemoryDirectory directoryServer;
 
     /** LDAP DN to test. */
     private final String context = "ou=people,dc=example,dc=org";
 
     /**
-     * Creates an UnboundID in-memory directory server. Leverages LDIF found in test resources.
-     * 
-     * @throws LDAPException if the in-memory directory server cannot be created
-     * @throws IOException ...
+     * Creates an in-memory directory server. Leverages LDIF found in test resources.
      */
-    @BeforeClass public void setupDirectoryServer() throws IOException, LDAPException {
-        directoryServer = new InMemoryDirectory(new File(DATA_PATH + "test-ldap.ldif"), new File(DATA_PATH + "test-ldap.keystore"));
+    @BeforeClass public void setupDirectoryServer() {
+        directoryServer =
+            new InMemoryDirectory(
+                new String[] {"dc=example,dc=org"},
+                new ClassPathResource(DATA_CLASSPATH + "test-ldap.ldif"),
+                10389,
+                new ClassPathResource(DATA_CLASSPATH + "test-ldap.keystore"),
+                Optional.empty());
         directoryServer.start();
     }
 
@@ -72,7 +80,8 @@ public class TrustEngineX509TrustManagerTest {
      * Shutdown the in-memory directory server.
      */
     @AfterClass public void teardownDirectoryServer() {
-        directoryServer.stop();
+        assertEquals(directoryServer.openConnectionCount(), 0);
+        directoryServer.stop(true);
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list