>From f2b68e2c057458c06059ec4d900b16d208d88bed Mon Sep 17 00:00:00 2001
From: Adam Young <ayoung@redhat.com>
Date: Fri, 18 Nov 2011 14:53:08 -0500
Subject: [PATCH 42/45] Typesafety for certsrv.kra

---
 .../certsrv/kra/IKeyRecoveryAuthority.java         |    8 ++--
 .../src/com/netscape/certsrv/kra/IKeyService.java  |    4 +-
 .../com/netscape/certsrv/kra/ProofOfArchival.java  |    6 +-
 .../src/com/netscape/kra/KeyRecoveryAuthority.java |   56 ++++++++++---------
 4 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/pki/base/common/src/com/netscape/certsrv/kra/IKeyRecoveryAuthority.java b/pki/base/common/src/com/netscape/certsrv/kra/IKeyRecoveryAuthority.java
index b268073e0193e2dc387743bbc85e792f6a7d8e61..7be3f165fd0efb504348fb4b141971cc41b287d3 100644
--- a/pki/base/common/src/com/netscape/certsrv/kra/IKeyRecoveryAuthority.java
+++ b/pki/base/common/src/com/netscape/certsrv/kra/IKeyRecoveryAuthority.java
@@ -164,7 +164,7 @@ public interface IKeyRecoveryAuthority extends ISubsystem {
      *
      * @return list of auto recovery identifiers
      */
-    public Enumeration getAutoRecoveryIDs();
+    public Enumeration<String> getAutoRecoveryIDs();
 
     /**
      * Returns the storage key unit that manages the
@@ -259,7 +259,7 @@ public interface IKeyRecoveryAuthority extends ISubsystem {
      * @param id request id
      * @return volatile requests
      */
-    public Hashtable createVolatileRequest(RequestId id);
+    public Hashtable<String, Object> createVolatileRequest(RequestId id);
 
     /**
      * Retrieves the request object.
@@ -267,7 +267,7 @@ public interface IKeyRecoveryAuthority extends ISubsystem {
      * @param id request id
      * @return volatile requests
      */
-    public Hashtable getVolatileRequest(RequestId id);
+    public Hashtable<String, Object> getVolatileRequest(RequestId id);
 
     /**
      * Destroys the request object.
@@ -276,7 +276,7 @@ public interface IKeyRecoveryAuthority extends ISubsystem {
      */
     public void destroyVolatileRequest(RequestId id);
 
-    public Vector getAppAgents(
+    public Vector<Credential> getAppAgents(
         String recoveryID) throws EBaseException;
 
     /**
diff --git a/pki/base/common/src/com/netscape/certsrv/kra/IKeyService.java b/pki/base/common/src/com/netscape/certsrv/kra/IKeyService.java
index 5785aeb0663bdc5fc830e80d79615e2906338302..23b3f9ac26839fc095b7754e05536e64b73136fb 100644
--- a/pki/base/common/src/com/netscape/certsrv/kra/IKeyService.java
+++ b/pki/base/common/src/com/netscape/certsrv/kra/IKeyService.java
@@ -133,7 +133,7 @@ public interface IKeyService {
      * @return recovery parameters
      * @exception EBaseException failed to create
      */
-    public Hashtable createRecoveryParams(String recoveryID) 
+    public Hashtable<String, Object> createRecoveryParams(String recoveryID) 
         throws EBaseException;
 
     /**
@@ -152,7 +152,7 @@ public interface IKeyService {
      * @return recovery parameters
      * @exception EBaseException failed to retrieve
      */
-    public Hashtable getRecoveryParams(String recoveryID) 
+    public Hashtable<String, Object> getRecoveryParams(String recoveryID) 
         throws EBaseException;
 
     /**
diff --git a/pki/base/common/src/com/netscape/certsrv/kra/ProofOfArchival.java b/pki/base/common/src/com/netscape/certsrv/kra/ProofOfArchival.java
index a2742809ef37867d4da11bc805a68d08d34ceaa9..ca5753967794436a38551bc373474687ce755daa 100644
--- a/pki/base/common/src/com/netscape/certsrv/kra/ProofOfArchival.java
+++ b/pki/base/common/src/com/netscape/certsrv/kra/ProofOfArchival.java
@@ -94,7 +94,7 @@ public class ProofOfArchival implements IDBObj, IProofOfArchival, Serializable {
     protected String mIssuer = null;
     protected Date mDateOfArchival = null;
 
-    protected static Vector mNames = new Vector();
+    protected static Vector<String> mNames = new Vector<String>();
     static {
         mNames.addElement(ATTR_VERSION);
         mNames.addElement(ATTR_SERIALNO);
@@ -195,7 +195,7 @@ public class ProofOfArchival implements IDBObj, IProofOfArchival, Serializable {
      *
      * @return a list of names
      */
-    public Enumeration getElements() {
+    public Enumeration<String> getElements() {
         return mNames.elements();
     }
 
@@ -204,7 +204,7 @@ public class ProofOfArchival implements IDBObj, IProofOfArchival, Serializable {
      * 
      * @return a list of serializable attribute names
      */
-    public Enumeration getSerializableAttrNames() {
+    public Enumeration<String> getSerializableAttrNames() {
         return mNames.elements();
     }
 	
diff --git a/pki/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java b/pki/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
index 3339d31fb8811cfc1c306cf1073770aac5a8f678..09466c84245f319c7104d681c8745952d6e2e427 100644
--- a/pki/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
+++ b/pki/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
@@ -103,7 +103,6 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     private final static String KEY_RESP_NAME = "keyRepository";
     private static final String PROP_REPLICAID_DN = "dbs.replicadn";
 
-    private Hashtable mRequestProcessor = new Hashtable();
 
     protected boolean mInitialized = false;
     protected IConfigStore mConfig = null;
@@ -115,7 +114,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     protected IRequestQueue mRequestQueue = null;
     protected TransportKeyUnit mTransportKeyUnit = null;
     protected StorageKeyUnit mStorageKeyUnit = null;
-    protected Hashtable mAutoRecovery = new Hashtable();
+    protected Hashtable<String, Credential[]> mAutoRecovery = new Hashtable<String, Credential[]>();
     protected boolean mAutoRecoveryOn = false;
     protected KeyRepository mKeyDB = null;
     protected ReplicaIDRepository mReplicaRepot = null;
@@ -123,7 +122,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     protected IRequestNotifier mPNotify = null;
     protected ISubsystem mOwner = null;
     protected int mRecoveryIDCounter = 0;
-    protected Hashtable mRecoveryParams = new Hashtable();
+    protected Hashtable<String, Hashtable<String, Object>> mRecoveryParams = new Hashtable<String, Hashtable<String, Object>>();
     protected org.mozilla.jss.crypto.X509Certificate mJssCert = null;
     protected CryptoToken mKeygenToken = null;
 
@@ -524,7 +523,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
      * @return list of user IDs that are accepted in the
      * auto recovery mode
      */
-    public Enumeration getAutoRecoveryIDs() {
+    public Enumeration<String> getAutoRecoveryIDs() {
         return mAutoRecovery.keys();
     }
 
@@ -599,11 +598,11 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
         return Integer.toString(mRecoveryIDCounter++);
     }
 
-    public Hashtable createRecoveryParams(String recoveryID) 
+    public Hashtable<String, Object> createRecoveryParams(String recoveryID) 
         throws EBaseException {
-        Hashtable h = new Hashtable();
+        Hashtable<String, Object> h = new Hashtable<String, Object>();
 
-        h.put(PARAM_CREDS, new Vector());
+        h.put(PARAM_CREDS, new Vector<Credential>());
         h.put(PARAM_LOCK, new Object());
         mRecoveryParams.put(recoveryID, h);
         return h;
@@ -614,14 +613,14 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
         mRecoveryParams.remove(recoveryID);
     }
 
-    public Hashtable getRecoveryParams(String recoveryID) 
+    public Hashtable<String, Object> getRecoveryParams(String recoveryID) 
         throws EBaseException {
-        return (Hashtable) mRecoveryParams.get(recoveryID);
+        return (Hashtable<String, Object>) mRecoveryParams.get(recoveryID);
     }
 
     public void createPk12(String recoveryID, byte[] pk12)
         throws EBaseException {
-        Hashtable h = getRecoveryParams(recoveryID);
+        Hashtable<String, Object> h = getRecoveryParams(recoveryID);
 
         h.put(PARAM_PK12, pk12);
     }
@@ -633,7 +632,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
 
     public void createError(String recoveryID, String error)
         throws EBaseException {
-        Hashtable h = getRecoveryParams(recoveryID);
+        Hashtable<String, Object> h = getRecoveryParams(recoveryID);
 
         h.put(PARAM_ERROR, error);
     }
@@ -646,10 +645,11 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     /**
      * Retrieve the current approval agents
      */
-    public Vector getAppAgents(
+    public Vector<Credential> getAppAgents(
         String recoveryID) throws EBaseException {
-        Hashtable h = getRecoveryParams(recoveryID);
-        Vector dc = (Vector) h.get(PARAM_CREDS);
+        Hashtable<String, Object> h = getRecoveryParams(recoveryID);
+        @SuppressWarnings("unchecked")
+		Vector<Credential> dc = (Vector<Credential>) h.get(PARAM_CREDS);
 
         return dc;
     }
@@ -662,8 +662,9 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     public Credential[] getDistributedCredentials(
         String recoveryID) 
         throws EBaseException {
-        Hashtable h = getRecoveryParams(recoveryID);
-        Vector dc = (Vector) h.get(PARAM_CREDS);
+        Hashtable<String, Object> h = getRecoveryParams(recoveryID);
+        @SuppressWarnings("unchecked")
+		Vector<Credential> dc = (Vector<Credential>) h.get(PARAM_CREDS);
         Object lock = (Object) h.get(PARAM_LOCK);
 
         synchronized (lock) {
@@ -684,7 +685,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     /**
      * Verifies credential.
      */
-    private void verifyCredential(Vector creds, String uid, 
+    private void verifyCredential(Vector<Credential>  creds, String uid, 
         String pwd) throws EBaseException {
             // see if we have the uid already
 
@@ -698,7 +699,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
         }
 
         for (int i = 0; i < creds.size(); i++) {
-            Credential c = (Credential) creds.elementAt(i);
+            Credential c =  creds.elementAt(i);
 
             if (c.getIdentifier().equals(uid)) {
                 // duplicated uid
@@ -715,8 +716,9 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
      */
     public void addDistributedCredential(String recoveryID, 
         String uid, String pwd) throws EBaseException {
-        Hashtable h = getRecoveryParams(recoveryID);
-        Vector dc = (Vector) h.get(PARAM_CREDS);
+        Hashtable<String, Object> h = getRecoveryParams(recoveryID);
+        @SuppressWarnings("unchecked")
+		Vector<Credential> dc = (Vector<Credential> ) h.get(PARAM_CREDS);
         Object lock = (Object) h.get(PARAM_LOCK);
 
         synchronized (lock) {
@@ -1014,7 +1016,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
 
         IRequestQueue queue = null;
         IRequest r = null;
-        Hashtable params = null;
+        Hashtable<String, Object> params = null;
 
         CMS.debug("KeyRecoveryAuthority: in synchronous doKeyRecovery()");
         // ensure that any low-level exceptions are reported
@@ -1148,7 +1150,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
 
         IRequestQueue queue = null;
         IRequest r = null;
-        Hashtable params = null;
+        Hashtable<String, Object> params = null;
 
         CMS.debug("KeyRecoveryAuthority: in asynchronous doKeyRecovery()");
         queue = getRequestQueue();
@@ -1492,7 +1494,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
     }
 	*/
 
-    public Hashtable mVolatileRequests = new Hashtable();
+    public Hashtable<String, Hashtable<String, Object>> mVolatileRequests = new Hashtable<String, Hashtable<String, Object>>();
 
     /**
      * Creates a request object to store attributes that
@@ -1501,15 +1503,15 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
      * persistent storage. Things like passwords are not
      * desirable to be stored.
      */
-    public Hashtable createVolatileRequest(RequestId id) {
-        Hashtable params = new Hashtable();
+    public Hashtable<String, Object> createVolatileRequest(RequestId id) {
+        Hashtable<String, Object> params = new Hashtable<String, Object>();
 
         mVolatileRequests.put(id.toString(), params);
         return params;
     }
 
-    public Hashtable getVolatileRequest(RequestId id) {
-        return (Hashtable) mVolatileRequests.get(id.toString());
+    public Hashtable<String, Object> getVolatileRequest(RequestId id) {
+        return (Hashtable<String, Object>) mVolatileRequests.get(id.toString());
     }
 
     public void destroyVolatileRequest(RequestId id) {
-- 
1.7.7.3

