[java-idp-testbed] branch main updated: JSSH-16: Update to Apache HttpClient 5.x

Brent Putman putmanb at georgetown.edu
Tue Feb 21 21:47:36 UTC 2023


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

putmanb pushed a commit to branch main
in repository java-idp-testbed.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-testbed.git;a=commit;h=75ed764a423b4dd3f66fca87075e751e811e9593

The following commit(s) were added to refs/heads/main by this push:
     new 75ed764  JSSH-16: Update to Apache HttpClient 5.x
75ed764 is described below

commit 75ed764a423b4dd3f66fca87075e751e811e9593
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Tue Feb 21 16:47:29 2023 -0500

    JSSH-16: Update to Apache HttpClient 5.x
    
    Initial refactor.
---
 pom.xml                               |  9 +++++++++
 src/main/java/sp/SAML1Controller.java | 26 +++++++++++++++++++-------
 src/main/java/sp/SAML2Controller.java | 26 +++++++++++++++++++-------
 3 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/pom.xml b/pom.xml
index be72157..dbc1f10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,6 +93,15 @@
             <artifactId>jetty-start</artifactId>
             <version>${jetty.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>${httpclient.groupId}</groupId>
+            <artifactId>${httpclient.artifactId}</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${httpclient.httpcore.groupId}</groupId>
+            <artifactId>${httpclient.httpcore.artifactId}</artifactId>
+        </dependency>
 
         <!-- Provided scope -->
         <dependency>
diff --git a/src/main/java/sp/SAML1Controller.java b/src/main/java/sp/SAML1Controller.java
index dc872d0..f78e24e 100644
--- a/src/main/java/sp/SAML1Controller.java
+++ b/src/main/java/sp/SAML1Controller.java
@@ -36,11 +36,15 @@ import net.shibboleth.shared.security.IdentifierGenerationStrategy.ProviderType;
 import net.shibboleth.shared.xml.SerializeSupport;
 import net.shibboleth.shared.xml.XMLParserException;
 
-import org.apache.http.client.HttpClient;
-import org.apache.http.conn.ssl.SSLContextBuilder;
-import org.apache.http.conn.ssl.SSLContexts;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.core5.ssl.SSLContextBuilder;
+import org.apache.hc.core5.ssl.SSLContexts;
 import org.cryptacular.util.CertUtil;
 import org.cryptacular.util.KeyPairUtil;
 import org.opensaml.core.xml.XMLObject;
@@ -328,12 +332,20 @@ public class SAML1Controller extends BaseSAMLController {
         keyStore.setKeyEntry("sp", clientPrivateKey, clientTLSPassword.toCharArray(), new Certificate[] {clientCert});
 
         final SSLContextBuilder sslContextBuilder = SSLContexts.custom();
-        sslContextBuilder.loadTrustMaterial(trustStore);
+        sslContextBuilder.loadTrustMaterial(trustStore, null);
         sslContextBuilder.loadKeyMaterial(keyStore, clientTLSPassword.toCharArray());
 
         final SSLContext sslcontext = sslContextBuilder.build();
+        
+        final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
+                .setSslContext(sslcontext)
+                .build();
 
-        final CloseableHttpClient httpClient = HttpClients.custom().setSslcontext(sslcontext).build();
+        final PoolingHttpClientConnectionManager connMgr = PoolingHttpClientConnectionManagerBuilder.create()
+                .setSSLSocketFactory(sslSocketFactory)
+                .build();
+
+        final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connMgr).build();
 
         return httpClient;
     }
diff --git a/src/main/java/sp/SAML2Controller.java b/src/main/java/sp/SAML2Controller.java
index d305d4e..4463200 100644
--- a/src/main/java/sp/SAML2Controller.java
+++ b/src/main/java/sp/SAML2Controller.java
@@ -13,11 +13,15 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.net.ssl.SSLContext;
 
-import org.apache.http.client.HttpClient;
-import org.apache.http.conn.ssl.SSLContextBuilder;
-import org.apache.http.conn.ssl.SSLContexts;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.classic.HttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.core5.ssl.SSLContextBuilder;
+import org.apache.hc.core5.ssl.SSLContexts;
 import org.cryptacular.util.CertUtil;
 import org.cryptacular.util.KeyPairUtil;
 import org.opensaml.core.xml.XMLObject;
@@ -1094,12 +1098,20 @@ public class SAML2Controller extends BaseSAMLController {
         keyStore.setKeyEntry("sp", clientPrivateKey, clientTLSPassword.toCharArray(), new Certificate[] {clientCert});
 
         final SSLContextBuilder sslContextBuilder = SSLContexts.custom();
-        sslContextBuilder.loadTrustMaterial(trustStore);
+        sslContextBuilder.loadTrustMaterial(trustStore, null);
         sslContextBuilder.loadKeyMaterial(keyStore, clientTLSPassword.toCharArray());
 
         final SSLContext sslcontext = sslContextBuilder.build();
 
-        final CloseableHttpClient httpClient = HttpClients.custom().setSslcontext(sslcontext).build();
+        final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
+                .setSslContext(sslcontext)
+                .build();
+
+        final PoolingHttpClientConnectionManager connMgr = PoolingHttpClientConnectionManagerBuilder.create()
+                .setSSLSocketFactory(sslSocketFactory)
+                .build();
+
+        final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connMgr).build();
 
         return httpClient;
     }

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


More information about the commits mailing list