From e610d9002373ce979d2f8ac3fe1973ec0a1b5175 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 10 Oct 2013 10:10:28 -0400
Subject: [PATCH] Fixed problem running GroupMemberProcessor on non-CA.

Previously the GroupMemberProcessor class inherits from CAProcessor that
can only run on CA. To fix the problem a generic Processor has been
created as a super class of the CAProcessor and some of the fields and
methods that are not CA-specific have been moved into the super class.
The GroupMemberProcessor will now inherit directly from the super class.
---
 .../netscape/cms/servlet/admin/GroupService.java   |  4 +
 .../netscape/cms/servlet/admin/UserService.java    |  3 +
 .../cms/servlet/processors/CAProcessor.java        | 70 +-----------------
 .../netscape/cms/servlet/processors/Processor.java | 86 ++++++++++++++++++++++
 4 files changed, 96 insertions(+), 67 deletions(-)
 create mode 100644 base/server/cms/src/com/netscape/cms/servlet/processors/Processor.java

diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
index 91fec08c417047d2fe37aa1a05bdb71dcf05fc78..3fd84da6c0a31e320b7b44319376269b0f7259fb 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
@@ -345,6 +345,7 @@ public class GroupService extends PKIService implements GroupResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
@@ -360,6 +361,7 @@ public class GroupService extends PKIService implements GroupResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
@@ -382,6 +384,7 @@ public class GroupService extends PKIService implements GroupResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
@@ -397,6 +400,7 @@ public class GroupService extends PKIService implements GroupResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java b/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
index c14605c5404edc620a48081c5afb2aad5c475ec0..827541e2f7a90a10a2b0d988658970673d4d1c3b 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/UserService.java
@@ -1021,6 +1021,7 @@ public class UserService extends PKIService implements UserResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
@@ -1048,6 +1049,7 @@ public class UserService extends PKIService implements UserResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
@@ -1063,6 +1065,7 @@ public class UserService extends PKIService implements UserResource {
             throw e;
 
         } catch (Exception e) {
+            e.printStackTrace();
             throw new PKIException(e.getMessage(), e);
         }
     }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/processors/CAProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/processors/CAProcessor.java
index deddd2b4e68a16eeb10bed1c51065cde21ee4324..28b1b5130901297ad6eac199f32f5de588bee94d 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/processors/CAProcessor.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/processors/CAProcessor.java
@@ -18,7 +18,6 @@
 
 package com.netscape.cms.servlet.processors;
 
-import java.lang.reflect.Method;
 import java.math.BigInteger;
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateException;
@@ -34,7 +33,6 @@ import java.util.Map.Entry;
 import java.util.StringTokenizer;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.FormParam;
 
 import netscape.security.x509.X509CertImpl;
 
@@ -54,7 +52,6 @@ import com.netscape.certsrv.base.SessionContext;
 import com.netscape.certsrv.ca.ICertificateAuthority;
 import com.netscape.certsrv.dbs.certdb.ICertRecord;
 import com.netscape.certsrv.dbs.certdb.ICertificateRepository;
-import com.netscape.certsrv.logging.IAuditor;
 import com.netscape.certsrv.logging.ILogger;
 import com.netscape.certsrv.profile.IEnrollProfile;
 import com.netscape.certsrv.profile.IProfile;
@@ -72,7 +69,7 @@ import com.netscape.cms.servlet.common.CMSGateway;
 import com.netscape.cms.servlet.common.ServletUtils;
 import com.netscape.cmsutil.util.Utils;
 
-public class CAProcessor {
+public class CAProcessor extends Processor {
 
     public final static String ARG_AUTH_TOKEN = "auth_token";
     public final static String ARG_REQUEST_OWNER = "requestOwner";
@@ -142,8 +139,6 @@ public class CAProcessor {
     protected String authzResourceName;
     protected String authMgr;
     protected String getClientCert = "false";
-    protected Locale locale;
-
     // subsystems
     protected ICertificateAuthority authority = (ICertificateAuthority) CMS.getSubsystem("ca");
     protected IAuthzSubsystem authz = (IAuthzSubsystem) CMS.getSubsystem(CMS.SUBSYSTEM_AUTHZ);
@@ -155,14 +150,13 @@ public class CAProcessor {
 
     //logging and stats
 
-    protected ILogger logger = CMS.getLogger();
-    protected IAuditor auditor = CMS.getAuditor();
     protected ILogger signedAuditLogger = CMS.getSignedAuditLogger();
     protected LinkedHashSet<String> statEvents = new LinkedHashSet<String>();
 
     public CAProcessor(String id, Locale locale) throws EPropertyNotFound, EBaseException {
+        super(id, locale);
+
         IConfigStore cs = CMS.getConfigStore().getSubStore("processor." + id);
-        this.locale = locale;
         this.profileID = cs.getString(PROFILE_ID, "").isEmpty() ? null : cs.getString(PROFILE_ID);
         this.authzResourceName = cs.getString(AUTHZ_RESOURCE_NAME, "").isEmpty() ? null :
             cs.getString(AUTHZ_RESOURCE_NAME);
@@ -337,17 +331,6 @@ public class CAProcessor {
         return cert;
     }
 
-    public void log(int source, int level, String message) {
-
-        if (logger == null) return;
-
-        logger.log(ILogger.EV_SYSTEM,
-                null,
-                source,
-                level,
-                getClass().getSimpleName() + ": " + message);
-    }
-
     protected static Hashtable<String, String> toHashtable(HttpServletRequest req) {
         Hashtable<String, String> httpReqHash = new Hashtable<String, String>();
         Enumeration<?> names = req.getParameterNames();
@@ -1262,51 +1245,4 @@ public class CAProcessor {
 
         CMS.debug("Processor: Nonce verified");
     }
-
-    public String getUserMessage(String messageId, String... params) {
-        return CMS.getUserMessage(locale, messageId, params);
-    }
-
-    public void audit(String message, String scope, String type, String id, Map<String, String> params, String status) {
-
-        if (auditor == null) return;
-
-        String auditMessage = CMS.getLogMessage(
-                message,
-                auditor.getSubjectID(),
-                status,
-                auditor.getParamString(scope, type, id, params));
-
-        auditor.log(auditMessage);
-    }
-
-    /**
-     * Get the values of the fields annotated with @FormParam.
-     */
-    public Map<String, String> getParams(Object object) {
-
-        Map<String, String> map = new HashMap<String, String>();
-
-        // for each fields in the object
-        for (Method method : object.getClass().getMethods()) {
-            FormParam element = method.getAnnotation(FormParam.class);
-            if (element == null) continue;
-
-            String name = element.value();
-
-            try {
-                // get the value from the object
-                Object value = method.invoke(object);
-
-                // put the value in the map
-                map.put(name, value == null ? null : value.toString());
-
-            } catch (Exception e) {
-                // ignore inaccessible fields
-                e.printStackTrace();
-            }
-        }
-
-        return map;
-    }
 }
diff --git a/base/server/cms/src/com/netscape/cms/servlet/processors/Processor.java b/base/server/cms/src/com/netscape/cms/servlet/processors/Processor.java
new file mode 100644
index 0000000000000000000000000000000000000000..64344d212d408e727771e961c48daf5f604132ed
--- /dev/null
+++ b/base/server/cms/src/com/netscape/cms/servlet/processors/Processor.java
@@ -0,0 +1,86 @@
+package com.netscape.cms.servlet.processors;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.ws.rs.FormParam;
+
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.base.EPropertyNotFound;
+import com.netscape.certsrv.logging.IAuditor;
+import com.netscape.certsrv.logging.ILogger;
+
+public class Processor {
+
+    protected ILogger logger = CMS.getLogger();
+    protected IAuditor auditor = CMS.getAuditor();
+
+    protected String id;
+    protected Locale locale;
+
+    public Processor(String id, Locale locale) throws EPropertyNotFound, EBaseException {
+        this.id = id;
+        this.locale = locale;
+    }
+
+    public String getUserMessage(String messageId, String... params) {
+        return CMS.getUserMessage(locale, messageId, params);
+    }
+
+    /**
+     * Get the values of the fields annotated with @FormParam.
+     */
+    public Map<String, String> getParams(Object object) {
+
+        Map<String, String> map = new HashMap<String, String>();
+
+        // for each fields in the object
+        for (Method method : object.getClass().getMethods()) {
+            FormParam element = method.getAnnotation(FormParam.class);
+            if (element == null) continue;
+
+            String name = element.value();
+
+            try {
+                // get the value from the object
+                Object value = method.invoke(object);
+
+                // put the value in the map
+                map.put(name, value == null ? null : value.toString());
+
+            } catch (Exception e) {
+                // ignore inaccessible fields
+                e.printStackTrace();
+            }
+        }
+
+        return map;
+    }
+
+    public void audit(String message, String scope, String type, String id, Map<String, String> params, String status) {
+
+        if (auditor == null) return;
+
+        String auditMessage = CMS.getLogMessage(
+                message,
+                auditor.getSubjectID(),
+                status,
+                auditor.getParamString(scope, type, id, params));
+
+        auditor.log(auditMessage);
+    }
+
+    public void log(int source, int level, String message) {
+
+        if (logger == null) return;
+
+        logger.log(ILogger.EV_SYSTEM,
+                null,
+                source,
+                level,
+                getClass().getSimpleName() + ": " + message);
+    }
+}
-- 
1.8.1.4

