>From 324608833237f2664ba9fe26bf42caac27aa5444 Mon Sep 17 00:00:00 2001
From: Adam Young <ayoung@redhat.com>
Date: Thu, 17 Nov 2011 11:52:24 -0500
Subject: [PATCH 37/38] type safety for certserv.authorization

---
 .../certsrv/authorization/AuthzMgrPlugin.java      |    1 -
 .../netscape/certsrv/authorization/AuthzToken.java |   12 ++---
 .../certsrv/authorization/IAuthzManager.java       |    7 ++-
 .../certsrv/authorization/IAuthzSubsystem.java     |    8 ++--
 .../com/netscape/cms/authorization/AAclAuthz.java  |   52 ++++++++++----------
 .../netscape/cms/authorization/DirAclAuthz.java    |    7 ++-
 .../cmscore/authorization/AuthzSubsystem.java      |   22 ++++----
 7 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/pki/base/common/src/com/netscape/certsrv/authorization/AuthzMgrPlugin.java b/pki/base/common/src/com/netscape/certsrv/authorization/AuthzMgrPlugin.java
index b9d9bb96c22de874421575376b7e2523173d42cc..aebe917097855a221895444ff051d76c6ab11ead 100644
--- a/pki/base/common/src/com/netscape/certsrv/authorization/AuthzMgrPlugin.java
+++ b/pki/base/common/src/com/netscape/certsrv/authorization/AuthzMgrPlugin.java
@@ -29,7 +29,6 @@ package com.netscape.certsrv.authorization;
 public class AuthzMgrPlugin {
     protected String mId = null;
     protected String mClassPath = null;
-    protected Class mClass = null;
     protected boolean mVisible = true;
 
     /**
diff --git a/pki/base/common/src/com/netscape/certsrv/authorization/AuthzToken.java b/pki/base/common/src/com/netscape/certsrv/authorization/AuthzToken.java
index a0f7133a717983cf8da10680652ba705a9531af1..0b5db00aa6a3e2c530f5b0954cc66a356054b468 100644
--- a/pki/base/common/src/com/netscape/certsrv/authorization/AuthzToken.java
+++ b/pki/base/common/src/com/netscape/certsrv/authorization/AuthzToken.java
@@ -35,12 +35,8 @@ import com.netscape.certsrv.base.IAttrSet;
  * @version $Revision$, $Date$
  */
 public class AuthzToken implements IAttrSet {
-    /**
-     *
-     */
     private static final long serialVersionUID = 4716145610877112054L;
-
-    private Hashtable mAttrs = null;
+    private Hashtable<String, Object> mAttrs = null;
 
     /**
      * Plugin name of the authorization manager that created the 
@@ -90,7 +86,7 @@ public class AuthzToken implements IAttrSet {
      * @param authzMgr The authorization manager that created this Token.
      */
     public AuthzToken(IAuthzManager authzMgr) {
-        mAttrs = new Hashtable();
+        mAttrs = new Hashtable<String, Object>();
         mAttrs.put(TOKEN_AUTHZMGR_INST_NAME, authzMgr.getName()); 
         mAttrs.put(TOKEN_AUTHZMGR_IMPL_NAME, authzMgr.getImplName()); 
         mAttrs.put(TOKEN_AUTHZTIME, new Date());
@@ -127,7 +123,7 @@ public class AuthzToken implements IAttrSet {
      * Enumerate all attribute names in the AuthzToken.
      * @return Enumeration of all attribute names in this AuthzToken.
      */
-    public Enumeration getElements() {
+    public Enumeration<String> getElements() {
         return (mAttrs.keys());
     }
 
@@ -135,7 +131,7 @@ public class AuthzToken implements IAttrSet {
      * Enumerate all attribute values in the AuthzToken.
      * @return Enumeration of all attribute names in this AuthzToken.
      */
-    public Enumeration getVals() {
+    public Enumeration<Object> getVals() {
         return (mAttrs.elements());
     }
 
diff --git a/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzManager.java b/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzManager.java
index 167911c4091a54b9c3eaf9b40271fae3c3a59199..25a665052f4cfe3682b426ad75f22211007d7381 100644
--- a/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzManager.java
+++ b/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzManager.java
@@ -21,6 +21,7 @@ package com.netscape.certsrv.authorization;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
+import com.netscape.certsrv.acls.ACL;
 import com.netscape.certsrv.acls.EACLsException;
 import com.netscape.certsrv.acls.IACL;
 import com.netscape.certsrv.authentication.IAuthToken;
@@ -131,7 +132,7 @@ public interface IAuthzManager {
      * Get ACL entries
      * @return enumeration of ACL entries.
      */
-    public Enumeration getACLs();
+    public Enumeration<ACL> getACLs();
 
     /**
      * Get individual ACL entry for the given name of entry.
@@ -155,7 +156,7 @@ public interface IAuthzManager {
      * Get all registered evaluators.
      * @return All registered evaluators.
      */
-    public Enumeration aclEvaluatorElements();
+    public Enumeration<IAccessEvaluator> aclEvaluatorElements();
 
     /**
      * Register new evaluator
@@ -168,6 +169,6 @@ public interface IAuthzManager {
      * Return a table of evaluators
      * @return A table of evaluators
      */
-    public Hashtable getAccessEvaluators();
+    public Hashtable<String, IAccessEvaluator>  getAccessEvaluators();
 }
 
diff --git a/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzSubsystem.java b/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzSubsystem.java
index f6fc3547febc8d2c58dd6227e619d36c551e734d..281a11a2d8f30374653029dc063bb2b16a511059 100644
--- a/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzSubsystem.java
+++ b/pki/base/common/src/com/netscape/certsrv/authorization/IAuthzSubsystem.java
@@ -99,7 +99,7 @@ public interface IAuthzSubsystem extends ISubsystem {
      * authorization component.
      * @return a list of authorization managers
      */
-    public Enumeration getAuthzManagers();
+    public Enumeration<IAuthzManager> getAuthzManagers();
 
     /**
      * Initialize authz info - usually used for BasicAclAuthz
@@ -114,7 +114,7 @@ public interface IAuthzSubsystem extends ISubsystem {
      * Gets an enumeration of authorization manager plugins.
      * @return list of authorization manager plugins
      */
-    public Enumeration getAuthzManagerPlugins();
+    public Enumeration<AuthzMgrPlugin>  getAuthzManagerPlugins();
 
     /**
      * Gets a single authorization manager plugin implementation
@@ -134,13 +134,13 @@ public interface IAuthzSubsystem extends ISubsystem {
      * Get a hashtable containing all authentication plugins.
      * @return all authentication plugins.
      */
-    public Hashtable getPlugins();
+    public Hashtable<String, AuthzMgrPlugin> getPlugins();
 
     /**
      * Get a hashtable containing all authentication instances.
      * @return all authentication instances.
      */
-    public Hashtable getInstances();
+    public Hashtable<String, AuthzManagerProxy> getInstances();
 
     /**
      * Get an authorization manager interface for the given name.
diff --git a/pki/base/common/src/com/netscape/cms/authorization/AAclAuthz.java b/pki/base/common/src/com/netscape/cms/authorization/AAclAuthz.java
index c3b0a8535a6b92ad45b95d04d1adeaac4706c434..0bb36f2881ad8d4ef1369fb3227dec3136fc506d 100644
--- a/pki/base/common/src/com/netscape/cms/authorization/AAclAuthz.java
+++ b/pki/base/common/src/com/netscape/cms/authorization/AAclAuthz.java
@@ -72,17 +72,17 @@ public abstract class AAclAuthz {
 
     private IConfigStore mConfig = null;
 
-    private Hashtable mACLs = new Hashtable();
-    private Hashtable mEvaluators = new Hashtable();
+    private Hashtable<String, ACL> mACLs = new Hashtable<String, ACL>();
+    private Hashtable<String, IAccessEvaluator> mEvaluators = new Hashtable<String, IAccessEvaluator>();
     private ILogger mLogger = null;
 
     /* Vector of extendedPluginInfo strings */
-    protected static Vector mExtendedPluginInfo = null;
+    protected static Vector<String> mExtendedPluginInfo = null;
 
     protected static String[] mConfigParams = null;
 
     static {
-        mExtendedPluginInfo = new Vector();
+        mExtendedPluginInfo = new Vector<String>();
     }
 
     /**
@@ -108,7 +108,7 @@ public abstract class AAclAuthz {
         IConfigStore i = evalConfig.getSubStore(PROP_IMPL);
 
         IAccessEvaluator evaluator = null;
-        Enumeration mImpls = i.getSubStoreNames();
+        Enumeration<String> mImpls = i.getSubStoreNames();
 
         while (mImpls.hasMoreElements()) {
             String type = (String) mImpls.nextElement();
@@ -181,11 +181,11 @@ public abstract class AAclAuthz {
         return (ACL) mACLs.get(target);
     }
 	
-    protected Enumeration getTargetNames() {
+    protected Enumeration<String> getTargetNames() {
         return mACLs.keys();
     }
 
-    public Enumeration getACLs() {
+    public Enumeration<ACL> getACLs() {
         return mACLs.elements();
     }
 
@@ -343,7 +343,7 @@ public abstract class AAclAuthz {
             return false; 
         }
 
-        Enumeration e = acl.entries();
+        Enumeration<ACLEntry> e = acl.entries();
 
         if ((e == null) || (e.hasMoreElements() == false)) {
             // no acis for node, pass down to next node
@@ -391,7 +391,7 @@ public abstract class AAclAuthz {
 
         CMS.debug("evaluating expressions: " + s);
 
-        Vector v = new Vector();
+        Vector<Object> v = new Vector<Object>();
 
         while (s.length() > 0) {
             int orIndex = s.indexOf("||");
@@ -503,10 +503,10 @@ public abstract class AAclAuthz {
         String perm) 
         throws EACLsException {
  
-        Vector nodev = getNodes(name);
-        Enumeration nodes = nodev.elements();
+        Vector<String> nodev = getNodes(name);
+        Enumeration<String> nodes = nodev.elements();
         String order = getOrder();
-        Enumeration entries = null;
+        Enumeration<ACLEntry> entries = null;
 
         if (order.equals("deny")) 
             entries = getDenyEntries(nodes, perm);
@@ -567,11 +567,11 @@ public abstract class AAclAuthz {
         }
     }
 
-    protected Enumeration getAllowEntries(Enumeration nodes, String operation) {
+    protected Enumeration<ACLEntry> getAllowEntries(Enumeration<String> nodes, String operation) {
         String name = "";
         ACL acl = null;
-        Enumeration e = null;
-        Vector v = new Vector();
+        Enumeration<ACLEntry> e = null;
+        Vector<ACLEntry> v = new Vector<ACLEntry>();
 
         while (nodes.hasMoreElements()) {
             name = (String) nodes.nextElement();
@@ -592,11 +592,11 @@ public abstract class AAclAuthz {
         return v.elements();
     }
 
-    protected Enumeration getDenyEntries(Enumeration nodes, String operation) {
+    protected Enumeration<ACLEntry> getDenyEntries(Enumeration<String> nodes, String operation) {
         String name = "";
         ACL acl = null;
-        Enumeration e = null;
-        Vector v = new Vector();
+        Enumeration<ACLEntry> e = null;
+        Vector<ACLEntry> v = new Vector<ACLEntry>();
 
         while (nodes.hasMoreElements()) {
             name = (String) nodes.nextElement();
@@ -605,7 +605,7 @@ public abstract class AAclAuthz {
                 continue;
             e = acl.entries();
             while (e.hasMoreElements()) {
-                ACLEntry entry = (ACLEntry) e.nextElement();
+                ACLEntry entry = e.nextElement();
 
                 if (entry.isNegative() && 
                     entry.containPermission(operation)) {
@@ -628,7 +628,7 @@ public abstract class AAclAuthz {
         // XXX - could use some optimization ... later
         CMS.debug("evaluating expressions: " + s);
 
-        Vector v = new Vector();
+        Vector<Object> v = new Vector<Object>();
 
         while (s.length() > 0) {
             int orIndex = s.indexOf("||");
@@ -688,9 +688,9 @@ public abstract class AAclAuthz {
         return left;
     }
 
-    public Vector getNodes(String resourceID) {
-        Enumeration parents = getTargetNames();
-        Vector v = new Vector();
+    public Vector<String> getNodes(String resourceID) {
+        Enumeration<String> parents = getTargetNames();
+        Vector<String> v = new Vector<String>();
 
         if (resourceID != null && !resourceID.equals("")) {
             v.addElement(resourceID);
@@ -808,7 +808,7 @@ public abstract class AAclAuthz {
      * gets an enumeration of resources
      * @return an enumeration of resources contained in the ACL table
      */
-    public Enumeration aclResElements() {
+    public Enumeration<ACL> aclResElements() {
         return (mACLs.elements());
     }
 
@@ -816,7 +816,7 @@ public abstract class AAclAuthz {
      * gets an enumeration of access evaluators
      * @return an enumeraton of access evaluators
      */
-    public Enumeration aclEvaluatorElements() {
+    public Enumeration<IAccessEvaluator> aclEvaluatorElements() {
         return (mEvaluators.elements());
     }
 
@@ -824,7 +824,7 @@ public abstract class AAclAuthz {
      * gets the access evaluators
      * @return handle to the access evaluators table
      */
-    public Hashtable getAccessEvaluators() {
+    public Hashtable<String, IAccessEvaluator> getAccessEvaluators() {
         return mEvaluators;
     }
 
diff --git a/pki/base/common/src/com/netscape/cms/authorization/DirAclAuthz.java b/pki/base/common/src/com/netscape/cms/authorization/DirAclAuthz.java
index ee22bb592d91461a894e13838123d7a39e1b9e57..820bf97bf7365d9e0927b7b1da6944944dc78fad 100644
--- a/pki/base/common/src/com/netscape/cms/authorization/DirAclAuthz.java
+++ b/pki/base/common/src/com/netscape/cms/authorization/DirAclAuthz.java
@@ -164,10 +164,11 @@ public class DirAclAuthz extends AAclAuthz
                 LDAPEntry entry = (LDAPEntry) res.nextElement();
                 LDAPAttribute aclRes = entry.getAttribute("resourceACLS");
 
-                Enumeration en = aclRes.getStringValues();
+                @SuppressWarnings("unchecked")
+				Enumeration<String> en = (Enumeration<String> )aclRes.getStringValues();
 
                 for (; en != null && en.hasMoreElements();) {
-                    addACLs((String) en.nextElement());
+                    addACLs(en.nextElement());
                 }
             } else {
                 log(ILogger.LL_INFO, "ldap search found no cn=aclResources");
@@ -295,7 +296,7 @@ public class DirAclAuthz extends AAclAuthz
             LDAPAttribute attrs = new LDAPAttribute("resourceACLS");
             LDAPModificationSet mod = new LDAPModificationSet();
 
-            Enumeration en = aclResElements();
+            Enumeration<ACL> en = aclResElements();
 
             if (en.hasMoreElements() == true) {
                 while (en.hasMoreElements()) {
diff --git a/pki/base/common/src/com/netscape/cmscore/authorization/AuthzSubsystem.java b/pki/base/common/src/com/netscape/cmscore/authorization/AuthzSubsystem.java
index db1f593cd187cac5b41f72b4b723dbeca3d88799..62351f1ac3b32fda30f71baeb07b507cd8fc8e1b 100644
--- a/pki/base/common/src/com/netscape/cmscore/authorization/AuthzSubsystem.java
+++ b/pki/base/common/src/com/netscape/cmscore/authorization/AuthzSubsystem.java
@@ -49,8 +49,8 @@ import com.netscape.cmscore.util.Debug;
 public class AuthzSubsystem implements IAuthzSubsystem {
     public static final String ID = "authz";
 
-    public Hashtable mAuthzMgrPlugins = new Hashtable();
-    public Hashtable mAuthzMgrInsts = new Hashtable();
+    public Hashtable<String, AuthzMgrPlugin> mAuthzMgrPlugins = new Hashtable<String, AuthzMgrPlugin>();
+    public Hashtable<String, AuthzManagerProxy> mAuthzMgrInsts = new Hashtable<String, AuthzManagerProxy>();
     private String mId = "authz";
     private IConfigStore mConfig = null;
 
@@ -85,7 +85,7 @@ public class AuthzSubsystem implements IAuthzSubsystem {
             // get authz manager plugins.
 
             IConfigStore c = config.getSubStore(PROP_IMPL);
-            Enumeration mImpls = c.getSubStoreNames();
+            Enumeration<String> mImpls = c.getSubStoreNames();
 
             while (mImpls.hasMoreElements()) {
                 String id = (String) mImpls.nextElement();
@@ -102,7 +102,7 @@ public class AuthzSubsystem implements IAuthzSubsystem {
             // get authz manager instances.
 
             c = config.getSubStore(PROP_INSTANCE);
-            Enumeration instances = c.getSubStoreNames();
+            Enumeration<String> instances = c.getSubStoreNames();
 
             while (instances.hasMoreElements()) {
                 String insName = (String) instances.nextElement();
@@ -333,9 +333,9 @@ public class AuthzSubsystem implements IAuthzSubsystem {
     /**
      * Enumerate all authorization manager instances.
      */
-    public Enumeration getAuthzManagers() {
-        Vector inst = new Vector();
-        Enumeration e = mAuthzMgrInsts.keys();
+    public Enumeration<IAuthzManager> getAuthzManagers() {
+        Vector<IAuthzManager> inst = new Vector<IAuthzManager>();
+        Enumeration<String> e = mAuthzMgrInsts.keys();
 
         while (e.hasMoreElements()) {
             IAuthzManager p = get((String) e.nextElement());
@@ -350,7 +350,7 @@ public class AuthzSubsystem implements IAuthzSubsystem {
     /**
      * Enumerate all registered authorization manager plugins.
      */
-    public Enumeration getAuthzManagerPlugins() {
+    public Enumeration<AuthzMgrPlugin> getAuthzManagerPlugins() {
         return (mAuthzMgrPlugins.elements());
     }
 
@@ -412,7 +412,7 @@ public class AuthzSubsystem implements IAuthzSubsystem {
      * <P>
      */
     public void shutdown() {
-        for (Enumeration e = mAuthzMgrInsts.keys();
+        for (Enumeration<String> e = mAuthzMgrInsts.keys();
             e.hasMoreElements();) {
 
             IAuthzManager mgr = (IAuthzManager) get((String) e.nextElement());
@@ -430,11 +430,11 @@ public class AuthzSubsystem implements IAuthzSubsystem {
         mAuthzMgrInsts = null;
     }
 
-    public Hashtable getPlugins() {
+    public Hashtable<String, AuthzMgrPlugin> getPlugins() {
         return mAuthzMgrPlugins;
     }
 
-    public Hashtable getInstances() {
+    public Hashtable<String, AuthzManagerProxy> getInstances() {
         return mAuthzMgrInsts;
     }
 
-- 
1.7.7.3

