Blob Blame History Raw
From b408cbc053d02f462b87fc3648b181ce318a5b0a Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 23 Nov 2016 04:30:00 +0100
Subject: [PATCH 1/2] Refactored PKIConnection.get().

The PKIConnection has been modified to provide two get() methods:
one returning a generic Response object wnd the other returning an
object with the specified type. The ConfigurationUtils has been
modified accordingly.

https://fedorahosted.org/pki/ticket/1517
(cherry picked from commit 20656a1a0bb3fa402494fb5c1374c2b14dd29f2d)
---
 base/common/src/com/netscape/certsrv/client/PKIConnection.java    | 8 ++++++--
 .../src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java  | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/client/PKIConnection.java b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
index 88a2089..301c4c6 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIConnection.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIConnection.java
@@ -458,13 +458,17 @@ public class PKIConnection {
         }
     }
 
-    public String get(String path) throws Exception {
+    public Response get(String path) throws Exception {
+        return get(path, Response.class);
+    }
+
+    public <T> T get(String path, Class<T> responseType) throws Exception {
         String uri = config.getServerURI().toString();
         if (path != null) {
             uri += path;
         }
         ResteasyWebTarget target = resteasyClient.target(uri);
-        return target.request().get(String.class);
+        return target.request().get(responseType);
     }
 
     public String post(String path, MultivaluedMap<String, String> content) throws Exception {
diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
index afd8d28..bc6431c 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
@@ -234,7 +234,7 @@ public class ConfigurationUtils {
         PKIConnection connection = new PKIConnection(config);
         if (certApprovalCallback == null) certApprovalCallback = ConfigurationUtils.certApprovalCallback;
         connection.setCallback(certApprovalCallback);
-        return connection.get(path);
+        return connection.get(path, String.class);
     }
 
     public static String post(String hostname, int port, boolean secure,
-- 
1.8.3.1


From 222fd9bd489dbf6605c228353ac7c5bbef0eb5f7 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Wed, 23 Nov 2016 05:17:43 +0100
Subject: [PATCH 2/2] Fixed problem with pki user-cert-add.

Previously the pki user-cert-add fails to check whether the server
has a CA subsystem when it's invoked over SSL. That is because the
CLI tries to establish a new but improperly set up SSL connection.
Now the CLI has been modified to use the existing server
connection.

https://fedorahosted.org/pki/ticket/1517
(cherry picked from commit 2cc925cad40b5ec65e4c1c553c25e4165ee955f4)
---
 .../netscape/certsrv/client/SubsystemClient.java   | 26 +++++-----------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/client/SubsystemClient.java b/base/common/src/com/netscape/certsrv/client/SubsystemClient.java
index 3d44bce..bf329af 100644
--- a/base/common/src/com/netscape/certsrv/client/SubsystemClient.java
+++ b/base/common/src/com/netscape/certsrv/client/SubsystemClient.java
@@ -17,12 +17,9 @@
 // --- END COPYRIGHT BLOCK ---
 package com.netscape.certsrv.client;
 
-import java.net.URI;
 import java.net.URISyntaxException;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
+import javax.ws.rs.core.Response;
 
 import com.netscape.certsrv.account.AccountClient;
 
@@ -51,23 +48,12 @@ public class SubsystemClient extends Client {
 
     public boolean exists() throws Exception {
 
-        ClientConfig config = client.getConfig();
-        URI serverURI = config.getServerURI();
 
-        URI subsystemURI = new URI(
-                serverURI.getScheme(),
-                null,
-                serverURI.getHost(),
-                serverURI.getPort(),
-                "/" + name,
-                null,
-                null);
+        PKIConnection connection = client.getConnection();
+        Response response = connection.get("/" + name);
 
-        DefaultHttpClient client = new DefaultHttpClient();
-        HttpGet method = new HttpGet(subsystemURI);
         try {
-            HttpResponse response = client.execute(method);
-            int code = response.getStatusLine().getStatusCode();
+            int code = response.getStatus();
 
             if (code == 200) {
                 return true;
@@ -76,11 +62,11 @@ public class SubsystemClient extends Client {
                 return false;
 
             } else {
-                throw new Exception("Error: " + response.getStatusLine());
+                throw new Exception("Error: " + response.getStatusInfo());
             }
 
         } finally {
-            method.releaseConnection();
+            response.close();
         }
     }
 
-- 
1.8.3.1