From 87ca5033293f40a7c7a286e400d859c3f421a739 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Fri, 2 Sep 2016 16:08:02 -0400
Subject: [PATCH] Fix CertRequestInfo URLs

The URLs were generated by a UriBuilder that referred to the resource's
annotated path.  This top-level path changed though, even if the underlying
paths did not.  Replace this with a reference to the getX methods instead.

Also fixed a few eclipse flagged warnings (unused imports etc).

Ticket 2447
---
 .../com/netscape/ca/ExternalProcessKeyRetriever.java    |  7 +------
 .../src/com/netscape/cmstools/HttpClient.java           |  2 --
 .../com/netscape/cms/servlet/cert/CertRequestDAO.java   | 17 ++++++++++++++---
 .../cms/servlet/cert/CertRequestInfoFactory.java        | 15 ++++++++-------
 .../src/com/netscape/cms/servlet/cert/DoRevokeTPS.java  | 15 +++++++--------
 .../cms/servlet/profile/ProfileReviewServlet.java       |  1 -
 .../dogtagpki/server/tps/rest/TPSInstallerService.java  |  2 +-
 7 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/base/ca/src/com/netscape/ca/ExternalProcessKeyRetriever.java b/base/ca/src/com/netscape/ca/ExternalProcessKeyRetriever.java
index a1b77485284d699bbb524bfc64b3c348663c4c1e..736d8709b8a38c92a231c5f382edda95dd1db7ab 100644
--- a/base/ca/src/com/netscape/ca/ExternalProcessKeyRetriever.java
+++ b/base/ca/src/com/netscape/ca/ExternalProcessKeyRetriever.java
@@ -20,16 +20,11 @@ package com.netscape.ca;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.Process;
-import java.lang.ProcessBuilder;
 import java.util.Collection;
 import java.util.Stack;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.ArrayUtils;
-
-import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
diff --git a/base/java-tools/src/com/netscape/cmstools/HttpClient.java b/base/java-tools/src/com/netscape/cmstools/HttpClient.java
index 432be9c15c271e1739d14f31f9d6d695e2782023..594ec69a4f4aef6c4549407a55b3d390ca17a93f 100644
--- a/base/java-tools/src/com/netscape/cmstools/HttpClient.java
+++ b/base/java-tools/src/com/netscape/cmstools/HttpClient.java
@@ -126,8 +126,6 @@ public class HttpClient {
                 Password pass = new Password(password.toCharArray());
                 token.login(pass);
 
-                int i;
-
                 SSLHandshakeCompletedListener listener = new ClientHandshakeCB(this);
                 org.mozilla.jss.ssl.SSLSocket.SSLVersionRange stream_range =
                     new org.mozilla.jss.ssl.SSLSocket.SSLVersionRange(
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
index 6fbcd3c37ae46dd8ea71673d3c862890cbc9f3e4..306fbf570103daf09401faa0b615ae11f6b18953 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
@@ -197,8 +197,13 @@ public class CertRequestDAO extends CMSRequestDAO {
 
         IRequest reqs[] = (IRequest[]) results.get(CAProcessor.ARG_REQUESTS);
         for (IRequest req : reqs) {
-            CertRequestInfo info = CertRequestInfoFactory.create(req, uriInfo);
-            ret.addEntry(info);
+            try {
+                CertRequestInfo info = CertRequestInfoFactory.create(req, uriInfo);
+                ret.addEntry(info);
+            } catch (NoSuchMethodException e) {
+                CMS.debug("Error in creating certrequestinfo - no such method");
+                e.printStackTrace();
+            }
         }
 
         ret.setTotal(ret.getEntries().size());
@@ -221,7 +226,13 @@ public class CertRequestDAO extends CMSRequestDAO {
 
     @Override
     public CertRequestInfo createCMSRequestInfo(IRequest request, UriInfo uriInfo) {
-        return CertRequestInfoFactory.create(request, uriInfo);
+        try {
+            return CertRequestInfoFactory.create(request, uriInfo);
+        } catch (NoSuchMethodException e) {
+            CMS.debug("Error in creating certrequestinfo - no such method");
+            e.printStackTrace();
+        }
+        return null;
     }
 
 }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestInfoFactory.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestInfoFactory.java
index 68f65bc9cc70c299710b15d69b0cafda8c6a4dae..e8c44b33f8a5e5695d5356c90d2b2d92bc1aba74 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestInfoFactory.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestInfoFactory.java
@@ -37,7 +37,7 @@ import netscape.security.x509.X509CertImpl;
 
 public class CertRequestInfoFactory {
 
-    public static CertRequestInfo create(IRequest request, UriInfo uriInfo) {
+    public static CertRequestInfo create(IRequest request, UriInfo uriInfo) throws SecurityException, NoSuchMethodException {
 
         CertRequestInfo info = new CertRequestInfo();
 
@@ -49,12 +49,12 @@ public class CertRequestInfoFactory {
 
         info.setCertRequestType(request.getExtDataInString("cert_request_type"));
 
-        Path certRequestPath = CertRequestResource.class.getAnnotation(Path.class);
+        Path certRequestPath = CertRequestResource.class.getMethod("getRequestInfo", RequestId.class ).getAnnotation(Path.class);
         RequestId requestId = request.getRequestId();
 
         UriBuilder reqBuilder = uriInfo.getBaseUriBuilder();
-        reqBuilder.path(certRequestPath.value() + "/" + requestId);
-        info.setRequestURL(reqBuilder.build().toString());
+        reqBuilder.path(certRequestPath.value());
+        info.setRequestURL(reqBuilder.build(requestId).toString());
 
         Integer result = request.getExtDataInInteger(IRequest.RESULT);
         if (result == null || result.equals(IRequest.RES_SUCCESS)) {
@@ -84,11 +84,12 @@ public class CertRequestInfoFactory {
         BigInteger serialNo = impl.getSerialNumber();
         info.setCertId(new CertId(serialNo));
 
-        Path certPath = CertResource.class.getAnnotation(Path.class);
+
+        Path certPath = CertResource.class.getMethod("getCert", CertId.class).getAnnotation(Path.class);
         UriBuilder certBuilder = uriInfo.getBaseUriBuilder();
-        certBuilder.path(certPath.value() + "/" + serialNo);
+        certBuilder.path(certPath.value());
 
-        info.setCertURL(certBuilder.build().toString());
+        info.setCertURL(certBuilder.build(serialNo).toString());
 
         return info;
     }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java b/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
index 30bd2cde04309dfb86329821b3335036bbd944ee..79eba99d557119551539a72805eedd567373714b 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/DoRevokeTPS.java
@@ -30,12 +30,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import netscape.security.x509.CRLExtensions;
-import netscape.security.x509.CRLReasonExtension;
-import netscape.security.x509.InvalidityDateExtension;
-import netscape.security.x509.RevocationReason;
-import netscape.security.x509.RevokedCertImpl;
-import netscape.security.x509.X509CertImpl;
+import org.dogtagpki.server.connector.IRemoteRequest;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.authentication.AuthToken;
@@ -51,7 +46,6 @@ import com.netscape.certsrv.ca.ICertificateAuthority;
 import com.netscape.certsrv.common.ICMSRequest;
 import com.netscape.certsrv.dbs.certdb.ICertRecord;
 import com.netscape.certsrv.dbs.certdb.ICertificateRepository;
-import com.netscape.certsrv.dbs.certdb.IRevocationInfo;
 import com.netscape.certsrv.logging.AuditFormat;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.publish.IPublisherProcessor;
@@ -64,7 +58,12 @@ import com.netscape.cms.servlet.common.CMSTemplate;
 import com.netscape.cms.servlet.common.CMSTemplateParams;
 import com.netscape.cms.servlet.common.ECMSGWException;
 
-import org.dogtagpki.server.connector.IRemoteRequest;
+import netscape.security.x509.CRLExtensions;
+import netscape.security.x509.CRLReasonExtension;
+import netscape.security.x509.InvalidityDateExtension;
+import netscape.security.x509.RevocationReason;
+import netscape.security.x509.RevokedCertImpl;
+import netscape.security.x509.X509CertImpl;
 
 /**
  * Revoke a Certificate
diff --git a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileReviewServlet.java b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileReviewServlet.java
index 0073bd2efd2ea98c3fe85ab42acd4401c028d442..dc6560d066be6fb677ff47344d6aee79295da48a 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileReviewServlet.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileReviewServlet.java
@@ -43,7 +43,6 @@ import com.netscape.certsrv.profile.IProfileInput;
 import com.netscape.certsrv.profile.IProfileOutput;
 import com.netscape.certsrv.profile.IProfilePolicy;
 import com.netscape.certsrv.profile.IProfileSubsystem;
-import com.netscape.certsrv.property.EPropertyException;
 import com.netscape.certsrv.property.IDescriptor;
 import com.netscape.certsrv.request.IRequest;
 import com.netscape.certsrv.request.IRequestQueue;
diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TPSInstallerService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TPSInstallerService.java
index 068293e603a294c90954d3f53f4b5e2fa5e12917..8fd24c8d8607b45651c6a926a56b45209791633d 100644
--- a/base/tps/src/org/dogtagpki/server/tps/rest/TPSInstallerService.java
+++ b/base/tps/src/org/dogtagpki/server/tps/rest/TPSInstallerService.java
@@ -50,7 +50,7 @@ public class TPSInstallerService extends SystemConfigService  {
 
         // get token prefix, if applicable
         String tokPrefix = "";
-        if (!request.getToken().equals(request.TOKEN_DEFAULT) &&
+        if (!request.getToken().equals(ConfigurationRequest.TOKEN_DEFAULT) &&
                 !request.getToken().equals("internal")) {
             tokPrefix = request.getToken() + ":";
         }
-- 
2.4.3

