[java-opensaml] branch main updated: IDP-1963 Update ldaptive to version 2.

Daniel Fisher dfisher at vt.edu
Thu Oct 13 03:29:14 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=20dd1e20e675d0fa66656a83fd31b89cc3a8de97

The following commit(s) were added to refs/heads/main by this push:
     new 20dd1e20e IDP-1963 Update ldaptive to version 2.
20dd1e20e is described below

commit 20dd1e20e675d0fa66656a83fd31b89cc3a8de97
Author: Daniel Fisher <dfisher at vt.edu>
AuthorDate: Wed Oct 12 22:15:18 2022 -0400

    IDP-1963 Update ldaptive to version 2.
    
    https://shibboleth.atlassian.net/browse/IDP-1963
    
    Update TrustEngineX509TrustManagerTest for API changes.
---
 .../impl/TrustEngineX509TrustManagerTest.java      | 81 +++++++++++-----------
 1 file changed, 39 insertions(+), 42 deletions(-)

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 6f2cfd13f..8a4b12e54 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
@@ -25,15 +25,16 @@ import java.io.IOException;
 import javax.annotation.Nonnull;
 
 import org.cryptacular.util.KeyPairUtil;
+import org.ldaptive.ConnectException;
 import org.ldaptive.Connection;
 import org.ldaptive.ConnectionConfig;
+import org.ldaptive.ConnectionFactory;
 import org.ldaptive.DefaultConnectionFactory;
 import org.ldaptive.LdapException;
-import org.ldaptive.Response;
 import org.ldaptive.ResultCode;
 import org.ldaptive.SearchOperation;
 import org.ldaptive.SearchRequest;
-import org.ldaptive.SearchResult;
+import org.ldaptive.SearchResponse;
 import org.ldaptive.ssl.SslConfig;
 import org.opensaml.security.credential.BasicCredential;
 import org.opensaml.security.credential.impl.StaticCredentialResolver;
@@ -79,18 +80,14 @@ public class TrustEngineX509TrustManagerTest {
      * 
      * @throws LdapException ...
      */
-    @Test(expectedExceptions=LdapException.class)
+    @Test(expectedExceptions=ConnectException.class)
     public void testDefaultTrust() throws LdapException {
-        final ConnectionConfig config = new ConnectionConfig();
-        config.setLdapUrl("ldap://localhost:10389");
-        config.setUseStartTLS(true);
-        final DefaultConnectionFactory factory = new DefaultConnectionFactory(config);
-        final Connection conn = factory.getConnection();
-        try {
-            conn.open();
-        } finally {
-            conn.close();
-        }
+        doOpen(DefaultConnectionFactory.builder()
+            .config(ConnectionConfig.builder()
+                .url("ldap://localhost:10389")
+                .useStartTLS(true)
+                .build())
+            .build());
     }
     
     /**
@@ -98,22 +95,18 @@ public class TrustEngineX509TrustManagerTest {
      * 
      * @throws LdapException ...
      */
-    @Test(expectedExceptions=LdapException.class)
+    @Test(expectedExceptions=ConnectException.class)
     public void testNullTrust() throws LdapException {
         final TrustEngineX509TrustManager trustManager = new TrustEngineX509TrustManager();
-        final SslConfig sslConfig = new SslConfig();
-        sslConfig.setTrustManagers(trustManager);
-        final ConnectionConfig config = new ConnectionConfig();
-        config.setLdapUrl("ldap://localhost:10389");
-        config.setUseStartTLS(true);
-        config.setSslConfig(sslConfig);
-        final DefaultConnectionFactory factory = new DefaultConnectionFactory(config);
-        final Connection conn = factory.getConnection();
-        try {
-            conn.open();
-        } finally {
-            conn.close();
-        }
+        doOpen(DefaultConnectionFactory.builder()
+            .config(ConnectionConfig.builder()
+                .url("ldap://localhost:10389")
+                .useStartTLS(true)
+                .sslConfig(SslConfig.builder()
+                    .trustManagers(trustManager)
+                    .build())
+                .build())
+            .build());
     }
     
     /**
@@ -126,33 +119,37 @@ public class TrustEngineX509TrustManagerTest {
     @Test
     public void testStaticTrust() throws LdapException, FileNotFoundException, IOException {
         final StaticCredentialResolver resolver;
-        try (final FileInputStream is = new FileInputStream(new File(DATA_PATH + "test-ldap.key"))) {
+        try (final FileInputStream is = new FileInputStream(DATA_PATH + "test-ldap.key")) {
             resolver = new StaticCredentialResolver(new BasicCredential(KeyPairUtil.readPublicKey(is)));
         }
         final TrustEngineX509TrustManager trustManager = new TrustEngineX509TrustManager();
         trustManager.setTLSTrustEngine(new ExplicitKeyTrustEngine(resolver));
-        final SslConfig sslConfig = new SslConfig();
-        sslConfig.setTrustManagers(trustManager);
-        final ConnectionConfig config = new ConnectionConfig();
-        config.setLdapUrl("ldap://localhost:10389");
-        config.setUseStartTLS(true);
-        config.setSslConfig(sslConfig);
-        final DefaultConnectionFactory factory = new DefaultConnectionFactory(config);
+        doSearch(DefaultConnectionFactory.builder()
+            .config(ConnectionConfig.builder()
+                .url("ldap://localhost:10389")
+                .useStartTLS(true)
+                .sslConfig(SslConfig.builder()
+                    .trustManagers(trustManager)
+                    .build())
+                .build())
+            .build());
+    }
+
+    protected void doOpen(@Nonnull final ConnectionFactory factory) throws LdapException {
         final Connection conn = factory.getConnection();
         try {
             conn.open();
-            doSearch(conn);
         } finally {
             conn.close();
         }
     }
 
-    protected void doSearch(@Nonnull final Connection conn) throws LdapException {
-        final SearchOperation search = new SearchOperation(conn);
-        final Response<SearchResult> result =
-                search.execute(SearchRequest.newObjectScopeSearchRequest(context, new String[] {"description"}));
-        Assert.assertNotNull(result);
-        Assert.assertEquals(result.getResultCode(), ResultCode.SUCCESS);
+    protected void doSearch(@Nonnull final ConnectionFactory factory) throws LdapException {
+        final SearchOperation search = new SearchOperation(factory);
+        final SearchResponse response =
+                search.execute(SearchRequest.objectScopeSearchRequest(context, new String[] {"description"}));
+        Assert.assertNotNull(response);
+        Assert.assertEquals(response.getResultCode(), ResultCode.SUCCESS);
     }
     
 }

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


More information about the commits mailing list