You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/05/13 07:45:29 UTC

[syncope] 02/02: [SYNCOPE-1561] Propagating TLSClientParameters to BatchRequest and Batch Response

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit ec10c7b4249515faee7614c8affe4c60f1cf08fb
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Wed May 13 09:43:16 2020 +0200

    [SYNCOPE-1561] Propagating TLSClientParameters to BatchRequest and Batch Response
---
 .../apache/syncope/client/lib/SyncopeClient.java   |  3 ++-
 .../syncope/client/lib/batch/BatchRequest.java     | 20 ++++++++++++++----
 .../syncope/client/lib/batch/BatchResponse.java    | 24 +++++++++++++++++++---
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/SyncopeClient.java b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/SyncopeClient.java
index 2979c9b..bf6ea23 100644
--- a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/SyncopeClient.java
+++ b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/SyncopeClient.java
@@ -406,6 +406,7 @@ public class SyncopeClient {
                 mediaType,
                 restClientFactory.getAddress(),
                 restClientFactory.getProviders(),
-                getJWT());
+                getJWT(),
+                tlsClientParameters);
     }
 }
diff --git a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchRequest.java b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchRequest.java
index bc62a93..c3c33c9 100644
--- a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchRequest.java
+++ b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchRequest.java
@@ -22,8 +22,11 @@ import java.util.List;
 import java.util.UUID;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.jaxrs.client.Client;
+import org.apache.cxf.jaxrs.client.ClientConfiguration;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.syncope.common.rest.api.Preference;
 import org.apache.syncope.common.rest.api.RESTHeaders;
 import org.apache.syncope.common.rest.api.batch.BatchPayloadGenerator;
@@ -46,18 +49,22 @@ public class BatchRequest {
 
     private final List<?> providers;
 
+    private final TLSClientParameters tlsClientParameters;
+
     private BatchClientFactoryBean bcfb;
 
     public BatchRequest(
             final MediaType mediaType,
             final String address,
             final List<?> providers,
-            final String jwt) {
+            final String jwt,
+            final TLSClientParameters tlsClientParameters) {
 
         this.mediaType = mediaType;
         this.jwt = jwt;
         this.address = address;
         this.providers = providers;
+        this.tlsClientParameters = tlsClientParameters;
         initBatchClientFactoryBean();
     }
 
@@ -85,7 +92,7 @@ public class BatchRequest {
      * Sends the current request, with items accumulated by invoking methods on proxies obtained via
      * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for synchronous response.
      * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests.
-     * 
+     *
      * @return batch response
      */
     public BatchResponse commit() {
@@ -97,7 +104,7 @@ public class BatchRequest {
      * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous
      * response, depending on the {@code async} parameter.
      * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests.
-     * 
+     *
      * @param async whether asynchronous Batch process is requested, or not
      * @return batch response
      */
@@ -110,12 +117,17 @@ public class BatchRequest {
         if (async) {
             webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC);
         }
+        if (tlsClientParameters != null) {
+            ClientConfiguration config = WebClient.getConfig(webClient);
+            HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
+            httpConduit.setTlsClientParameters(tlsClientParameters);
+        }
 
         String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary);
         LOG.debug("Batch request body:\n{}", body);
 
         initBatchClientFactoryBean();
 
-        return new BatchResponse(boundary, jwt, webClient.post(body));
+        return new BatchResponse(boundary, jwt, tlsClientParameters, webClient.post(body));
     }
 }
diff --git a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
index 80a32e8..5b6ee8b 100644
--- a/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
+++ b/client/idrepo/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
@@ -26,8 +26,11 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.client.ClientConfiguration;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.syncope.common.rest.api.RESTHeaders;
 import org.apache.syncope.common.rest.api.batch.BatchPayloadParser;
 import org.apache.syncope.common.rest.api.batch.BatchResponseItem;
@@ -47,11 +50,19 @@ public class BatchResponse {
 
     private final URI monitor;
 
+    private final TLSClientParameters tlsClientParameters;
+
     private Response response;
 
-    public BatchResponse(final String boundary, final String jwt, final Response response) {
+    public BatchResponse(
+            final String boundary,
+            final String jwt,
+            final TLSClientParameters tlsClientParameters,
+            final Response response) {
+
         this.boundary = boundary;
         this.jwt = jwt;
+        this.tlsClientParameters = tlsClientParameters;
         this.monitor = response.getLocation();
         this.response = response;
     }
@@ -72,9 +83,16 @@ public class BatchResponse {
      */
     public Response poll() {
         if (monitor != null) {
-            response = WebClient.create(monitor).
+            WebClient webClient = WebClient.create(monitor).
                     header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt).
-                    type(RESTHeaders.multipartMixedWith(boundary.substring(2))).get();
+                    type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
+            if (tlsClientParameters != null) {
+                ClientConfiguration config = WebClient.getConfig(webClient);
+                HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
+                httpConduit.setTlsClientParameters(tlsClientParameters);
+            }
+
+            response = webClient.get();
         }
 
         return response;