>From 59174491e0b65d614e4b8e48c139391660c213cc Mon Sep 17 00:00:00 2001
From: Adam Young <ayoung@redhat.com>
Date: Mon, 21 Nov 2011 11:06:15 -0500
Subject: [PATCH 45/45] typesafety  ACL Impls Random type safety cleanups.

---
 .../src/com/netscape/certsrv/template/ArgSet.java  |    4 +-
 .../netscape/cms/authentication/AVAPattern.java    |    5 +-
 .../authentication/AgentCertAuthentication.java    |    2 +-
 .../constraints/AttributePresentConstraints.java   |   27 +++----
 .../netscape/cms/servlet/common/CMSTemplate.java   |   11 ++-
 .../com/netscape/cmscore/dbs/BigIntegerMapper.java |    4 +-
 .../src/netscape/security/acl/AclEntryImpl.java    |    8 +-
 .../util/src/netscape/security/acl/AclImpl.java    |   83 ++++++++++----------
 .../util/src/netscape/security/acl/OwnerImpl.java  |    2 +-
 9 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/pki/base/common/src/com/netscape/certsrv/template/ArgSet.java b/pki/base/common/src/com/netscape/certsrv/template/ArgSet.java
index 249bb442006949c4720cea4e29aa7d7f24c5310c..471371f9cc13a20150973078ad811b59f0d91bf0 100644
--- a/pki/base/common/src/com/netscape/certsrv/template/ArgSet.java
+++ b/pki/base/common/src/com/netscape/certsrv/template/ArgSet.java
@@ -32,14 +32,14 @@ import java.util.Hashtable;
  * @version $Revision$, $Date$
  */
 public class ArgSet implements IArgValue {
-    private Hashtable mArgs = new Hashtable();
+    private Hashtable<String, IArgValue> mArgs = new Hashtable<String, IArgValue>();
 
     /**
      * Returns a list of argument names.
      *
      * @return list of argument names
      */
-    public Enumeration getNames() {
+    public Enumeration<String> getNames() {
         return mArgs.keys();
     }
 
diff --git a/pki/base/common/src/com/netscape/cms/authentication/AVAPattern.java b/pki/base/common/src/com/netscape/cms/authentication/AVAPattern.java
index e0a37eb4b68fabd6af154fa25287d94074906a4c..4cfe9a4578f4e7257bb87f070346b7144dd439b4 100644
--- a/pki/base/common/src/com/netscape/cms/authentication/AVAPattern.java
+++ b/pki/base/common/src/com/netscape/cms/authentication/AVAPattern.java
@@ -444,7 +444,8 @@ class AVAPattern {
             if (ldapAttr == null) 
                 return null;
             String value = null;
-            Enumeration ldapValues = ldapAttr.getStringValues();
+            @SuppressWarnings("unchecked")
+			Enumeration<String> ldapValues = ldapAttr.getStringValues();
 
             for (int i = 0; ldapValues.hasMoreElements(); i++) {
                 String val = (String) ldapValues.nextElement();
@@ -522,7 +523,7 @@ class AVAPattern {
 
         if (plus == -1) 
             return new String[] { rdn };
-        Vector avas = new Vector();
+        Vector<String> avas = new Vector<String>();
         StringTokenizer token = new StringTokenizer(rdn, "+");
 
         while (token.hasMoreTokens()) 
diff --git a/pki/base/common/src/com/netscape/cms/authentication/AgentCertAuthentication.java b/pki/base/common/src/com/netscape/cms/authentication/AgentCertAuthentication.java
index 0b8bad8f347ef4e9a7cc566d9f5967f750786add..270d1fa20191dae0e80de46b52b8333aa0b17294 100644
--- a/pki/base/common/src/com/netscape/cms/authentication/AgentCertAuthentication.java
+++ b/pki/base/common/src/com/netscape/cms/authentication/AgentCertAuthentication.java
@@ -309,7 +309,7 @@ public class AgentCertAuthentication implements IAuthManager,
     /**
      * Retrieves a list of names of the value parameter.
      */
-    public Enumeration getValueNames() {
+    public Enumeration<String> getValueNames() {
         return null;
     }
 
diff --git a/pki/base/common/src/com/netscape/cms/policy/constraints/AttributePresentConstraints.java b/pki/base/common/src/com/netscape/cms/policy/constraints/AttributePresentConstraints.java
index 6438dc4aee827e6890469f97136a3ea7f54de58f..a4d4f6f914909d247011328e39dad579e71a1bd6 100644
--- a/pki/base/common/src/com/netscape/cms/policy/constraints/AttributePresentConstraints.java
+++ b/pki/base/common/src/com/netscape/cms/policy/constraints/AttributePresentConstraints.java
@@ -66,8 +66,7 @@ public class AttributePresentConstraints extends APolicyRule
 
     private boolean mEnabled = false;
     private ILogger mLogger = CMS.getLogger();
-    private Hashtable mContentParams = new Hashtable();
-
+    
     private ICertAuthority mSub = null;
     private IConfigStore mConfig = null;
     private IConfigStore mLdapConfig = null;
@@ -180,13 +179,13 @@ public class AttributePresentConstraints extends APolicyRule
     protected static final String PROP_VALUE = "value";
     protected static final String DEF_VALUE = "";
 
-    protected static Vector    mParamNames;
-    protected static Hashtable mParamDefault;
-    protected        Hashtable mParamValue = null;
+    protected static Vector<String>    mParamNames;
+    protected static Hashtable<String, Object> mParamDefault;
+    protected        Hashtable<String, Object> mParamValue = null;
 
     static {
-        mParamNames = new Vector();
-        mParamDefault = new Hashtable();
+        mParamNames = new Vector<String>();
+        mParamDefault = new Hashtable<String, Object>();
         addParam(PROP_LDAP_HOST, DEF_LDAP_HOST);
         addParam(PROP_LDAP_PORT, DEF_LDAP_PORT);
         addParam(PROP_LDAP_SSL, DEF_LDAP_SSL);
@@ -246,7 +245,7 @@ public class AttributePresentConstraints extends APolicyRule
         throws EBaseException {
         mConfig = config;
 
-        mParamValue = new Hashtable();
+        mParamValue = new Hashtable<String, Object>();
 
         getStringConfigParam(mConfig, PROP_LDAP_HOST);
         getIntConfigParam(mConfig, PROP_LDAP_PORT);
@@ -345,10 +344,10 @@ public class AttributePresentConstraints extends APolicyRule
         return res;
     }
 
-    public Vector getInstanceParams() {
-        Vector params = new Vector();
+    public Vector<String>  getInstanceParams() {
+        Vector<String> params = new Vector<String>();
 
-        Enumeration e = mParamNames.elements();
+        Enumeration<String> e = mParamNames.elements();
 
         while (e.hasMoreElements()) {
             try {
@@ -364,10 +363,10 @@ public class AttributePresentConstraints extends APolicyRule
         return params;
     }
 
-    public Vector getDefaultParams() {
-        Vector params = new Vector();
+    public Vector<String> getDefaultParams() {
+        Vector<String> params = new Vector<String>();
 
-        Enumeration e = mParamNames.elements();
+        Enumeration<String> e = mParamNames.elements();
 
         while (e.hasMoreElements()) {
             try {
diff --git a/pki/base/common/src/com/netscape/cms/servlet/common/CMSTemplate.java b/pki/base/common/src/com/netscape/cms/servlet/common/CMSTemplate.java
index fd89ceaf1e0a55f49fd2b11511fe4536172b4f7e..b90278fa6aa54f61944e36d17392dae2609fc3f3 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/common/CMSTemplate.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/common/CMSTemplate.java
@@ -154,7 +154,8 @@ public class CMSTemplate extends CMSFile {
      */
     public void renderOutput(OutputStream rout, CMSTemplateParams input)
         throws IOException {
-        Enumeration e = null, q = null;
+        Enumeration<String> e = null;
+        Enumeration<IArgBlock>  q = null;
         IArgBlock r = null;
         boolean headerBlock = false, fixedBlock = false, queryBlock = false;
         CMSTemplateParams data = (CMSTemplateParams) input;
@@ -193,7 +194,7 @@ public class CMSTemplate extends CMSFile {
                 e = r.elements();
                 while (e.hasMoreElements()) {
                     headerBlock = true;
-                    String n = (String) e.nextElement();
+                    String n =  e.nextElement();
                     Object v = r.getValue(n);
 
                     out.println("header." + n + " = " + renderValue(v) + ";");
@@ -206,7 +207,7 @@ public class CMSTemplate extends CMSFile {
                 e = r.elements();
                 while (e.hasMoreElements()) {
                     fixedBlock = true;
-                    String n = (String) e.nextElement();
+                    String n = e.nextElement();
                     Object v = r.getValue(n);
 
                     out.println("fixed." + n + " = " + renderValue(v) + ";");
@@ -227,10 +228,10 @@ public class CMSTemplate extends CMSFile {
                     out.println("record.SERVER_ATTRS = new Array;");
 
                     // Get a query record
-                    r = (IArgBlock) q.nextElement();
+                    r =  q.nextElement();
                     e = r.elements();
                     while (e.hasMoreElements()) {
-                        String n = (String) e.nextElement();
+                        String n = e.nextElement();
                         Object v = r.getValue(n);
 
                         out.println("record." + n + "=" + renderValue(v) + ";");
diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java b/pki/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
index 8d6c325fa6929fd4b00e747a9a72d765187da28b..7cd563f99a9a26075eb99e4b713a609f68c39a3f 100644
--- a/pki/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
+++ b/pki/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
@@ -41,7 +41,7 @@ import com.netscape.certsrv.dbs.IDBObj;
 public class BigIntegerMapper implements IDBAttrMapper {
 
     private String mLdapName = null;
-    private Vector v = new Vector();
+    private Vector<String> v = new Vector<String>();
 
     /**
      * Constructs BigInteger mapper.
@@ -54,7 +54,7 @@ public class BigIntegerMapper implements IDBAttrMapper {
     /**
      * Returns a list of supported ldap attribute names.
      */
-    public Enumeration getSupportedLDAPAttributeNames() {
+    public Enumeration<String> getSupportedLDAPAttributeNames() {
         return v.elements();
     }
 
diff --git a/pki/base/util/src/netscape/security/acl/AclEntryImpl.java b/pki/base/util/src/netscape/security/acl/AclEntryImpl.java
index 6f1b77650bd59db4ae18cd8dad7e9d228222528d..47186881685a1fb9edaaf72392063b1402db1617 100644
--- a/pki/base/util/src/netscape/security/acl/AclEntryImpl.java
+++ b/pki/base/util/src/netscape/security/acl/AclEntryImpl.java
@@ -32,7 +32,7 @@ import java.util.Vector;
  */
 public class AclEntryImpl implements AclEntry {
     private Principal user = null;
-    private Vector permissionSet = new Vector(10, 10);
+    private Vector<Permission> permissionSet = new Vector<Permission>(10, 10);
     private boolean negative = false;
 
     /**
@@ -126,7 +126,7 @@ public class AclEntryImpl implements AclEntry {
     /**
      * return an enumeration of the permissions in this ACL entry.
      */
-    public Enumeration permissions() {
+    public Enumeration<Permission> permissions() {
 	return permissionSet.elements();
     }
 
@@ -144,7 +144,7 @@ public class AclEntryImpl implements AclEntry {
 	else
 	    s.append("User.");
 	s.append(user + "=");
-	Enumeration e = permissions();
+	Enumeration<Permission> e = permissions();
 	while(e.hasMoreElements()) {
 	    Permission p = (Permission) e.nextElement();
 	    s.append(p);
@@ -160,7 +160,7 @@ public class AclEntryImpl implements AclEntry {
     public synchronized Object clone() {
 	AclEntryImpl cloned;
 	cloned = new AclEntryImpl(user);
-	cloned.permissionSet = (Vector) permissionSet.clone();
+	cloned.permissionSet = new Vector<Permission>(permissionSet);
 	cloned.negative = negative;
 	return cloned;
     }
diff --git a/pki/base/util/src/netscape/security/acl/AclImpl.java b/pki/base/util/src/netscape/security/acl/AclImpl.java
index 5624b75f1e162f765a988bcd31834d900a98345a..15ea92de9cfc091e898ea0071ac4a8787cb65790 100644
--- a/pki/base/util/src/netscape/security/acl/AclImpl.java
+++ b/pki/base/util/src/netscape/security/acl/AclImpl.java
@@ -38,12 +38,12 @@ public class AclImpl extends OwnerImpl implements Acl {
     // ACLs. One each depending on whether the entity is a group
     // or principal.
     //
-    private Hashtable allowedUsersTable = new Hashtable(23);
-    private Hashtable allowedGroupsTable = new Hashtable(23);
-    private Hashtable deniedUsersTable = new Hashtable(23);
-    private Hashtable deniedGroupsTable = new Hashtable(23);
+    private Hashtable<Principal, AclEntry> allowedUsersTable = new Hashtable<Principal, AclEntry>(23);
+    private Hashtable<Principal, AclEntry> allowedGroupsTable = new Hashtable<Principal, AclEntry>(23);
+    private Hashtable<Principal, AclEntry> deniedUsersTable = new Hashtable<Principal, AclEntry>(23);
+    private Hashtable<Principal, AclEntry> deniedGroupsTable = new Hashtable<Principal, AclEntry>(23);
     private String aclName = null;
-    private Vector zeroSet = new Vector(1,1);
+    private Vector<Permission> zeroSet = new Vector<Permission>(1,1);
 
 
     /**
@@ -100,7 +100,7 @@ public class AclImpl extends OwnerImpl implements Acl {
 	if (!isOwner(caller))
 	    throw new NotOwnerException();
 
-	Hashtable aclTable = findTable(entry); 
+	Hashtable<Principal, AclEntry> aclTable = findTable(entry); 
 	Principal key = entry.getPrincipal();
 
 	if (aclTable.get(key) != null)
@@ -126,7 +126,7 @@ public class AclImpl extends OwnerImpl implements Acl {
 	if (!isOwner(caller))
 	    throw new NotOwnerException();
 
-	Hashtable aclTable = findTable(entry);
+	Hashtable<Principal, AclEntry> aclTable = findTable(entry);
 	Object key = entry.getPrincipal();
 
 	Object o = aclTable.remove(key);
@@ -163,12 +163,12 @@ public class AclImpl extends OwnerImpl implements Acl {
      * @param user the principal for which the ACL entry is returned.
      * @return The resulting permission set that the principal is allowed. 
      */
-    public synchronized Enumeration getPermissions(Principal user) {
+    public synchronized Enumeration<Permission> getPermissions(Principal user) {
 
-	Enumeration individualPositive;
-	Enumeration individualNegative;
-	Enumeration groupPositive;
-	Enumeration groupNegative;
+	Enumeration<Permission> individualPositive;
+	Enumeration<Permission> individualNegative;
+	Enumeration<Permission> groupPositive;
+	Enumeration<Permission> groupNegative;
 
 	//
 	// canonicalize the sets. That is remove common permissions from
@@ -183,8 +183,8 @@ public class AclImpl extends OwnerImpl implements Acl {
 	// net positive permissions is individual positive permissions
 	// plus (group positive - individual negative).
 	//
-	Enumeration temp1 = subtract(groupPositive, individualNegative);
-	Enumeration netPositive = union(individualPositive, temp1);
+	Enumeration<Permission> temp1 = subtract(groupPositive, individualNegative);
+	Enumeration<Permission> netPositive = union(individualPositive, temp1);
 
 	// recalculate the enumeration since we lost it in performing the
 	// subtraction
@@ -197,7 +197,7 @@ public class AclImpl extends OwnerImpl implements Acl {
 	// plus (group negative - individual positive).
 	//
 	temp1 = subtract(groupNegative, individualPositive);
-	Enumeration netNegative = union(individualNegative, temp1);
+	Enumeration<Permission> netNegative = union(individualNegative, temp1);
 
 	return subtract(netPositive, netNegative);
     }
@@ -215,7 +215,7 @@ public class AclImpl extends OwnerImpl implements Acl {
      */
     public boolean checkPermission(Principal principal, Permission permission) 
     {
-	Enumeration permSet = getPermissions(principal);
+	Enumeration<Permission> permSet = getPermissions(principal);
 	while (permSet.hasMoreElements()) {
 	    Permission p = (Permission) permSet.nextElement();
 	    if (p.equals(permission)) 
@@ -227,7 +227,7 @@ public class AclImpl extends OwnerImpl implements Acl {
     /**
      * returns an enumeration of the entries in this ACL.
      */
-    public synchronized Enumeration entries() {
+    public synchronized Enumeration<AclEntry> entries() {
 	return new AclEnumerator(this, 
 				 allowedUsersTable, allowedGroupsTable, 
 				 deniedUsersTable, deniedGroupsTable);
@@ -239,7 +239,7 @@ public class AclImpl extends OwnerImpl implements Acl {
      */
     public String toString() {
 	StringBuffer sb = new StringBuffer();
-	Enumeration entries = entries();
+	Enumeration<AclEntry> entries = entries();
 	while (entries.hasMoreElements()) {
 	    AclEntry entry = (AclEntry) entries.nextElement();
 	    sb.append(entry.toString().trim());
@@ -256,8 +256,8 @@ public class AclImpl extends OwnerImpl implements Acl {
     // This method figures out which 
     // table is the one that this AclEntry belongs to.
     //
-    private Hashtable findTable(AclEntry entry) {
-	Hashtable aclTable = null;
+    private Hashtable<Principal, AclEntry> findTable(AclEntry entry) {
+	Hashtable<Principal, AclEntry> aclTable = null;
 
 	Principal p = entry.getPrincipal();
 	if (p instanceof Group) {
@@ -277,14 +277,14 @@ public class AclImpl extends OwnerImpl implements Acl {
     //
     // returns the set e1 U e2.
     //
-    private static Enumeration union(Enumeration e1, Enumeration e2) {
-	Vector v = new Vector(20, 20);
+    private <T>  Enumeration<T> union(Enumeration<T> e1, Enumeration<T> e2) {
+	Vector<T> v = new Vector<T>(20, 20);
 
 	while (e1.hasMoreElements()) 
 	    v.addElement(e1.nextElement());
 
 	while (e2.hasMoreElements()) {
-	    Object o = e2.nextElement();
+	    T o = e2.nextElement();
 	    if (!v.contains(o))
 		v.addElement(o);
 	}
@@ -295,14 +295,14 @@ public class AclImpl extends OwnerImpl implements Acl {
     //
     // returns the set e1 - e2.
     //
-    private Enumeration subtract(Enumeration e1, Enumeration e2) {
-	Vector v = new Vector (20, 20);
+    private <T> Enumeration<T> subtract(Enumeration<T> e1, Enumeration<T> e2) {
+	Vector<T> v = new Vector<T> (20, 20);
 
 	while (e1.hasMoreElements()) 
 	    v.addElement(e1.nextElement());
 
 	while (e2.hasMoreElements()) {
-	    Object o = e2.nextElement();
+	    T o = e2.nextElement();
 	    if (v.contains(o))
 		v.removeElement(o);
 	}
@@ -310,9 +310,9 @@ public class AclImpl extends OwnerImpl implements Acl {
 	return v.elements();
     }
 
-    private Enumeration getGroupPositive(Principal user) {
-	Enumeration groupPositive = zeroSet.elements();
-	Enumeration e = allowedGroupsTable.keys();
+    private Enumeration<Permission> getGroupPositive(Principal user) {
+	Enumeration<Permission>  groupPositive = zeroSet.elements();
+	Enumeration<Principal> e = allowedGroupsTable.keys();
 	while (e.hasMoreElements()) {
 	    Group g = (Group) e.nextElement();
 	    if (g.isMember(user)) {
@@ -323,9 +323,9 @@ public class AclImpl extends OwnerImpl implements Acl {
 	return groupPositive;
     }
 
-    private Enumeration getGroupNegative(Principal user) {
-	Enumeration groupNegative = zeroSet.elements();
-	Enumeration e = deniedGroupsTable.keys();
+    private Enumeration<Permission> getGroupNegative(Principal user) {
+	Enumeration<Permission> groupNegative = zeroSet.elements();
+	Enumeration<Principal> e = deniedGroupsTable.keys();
 	while (e.hasMoreElements()) {
 	    Group g = (Group) e.nextElement();
 	    if (g.isMember(user)) {
@@ -336,16 +336,16 @@ public class AclImpl extends OwnerImpl implements Acl {
 	return groupNegative;
     }
 
-    private Enumeration getIndividualPositive(Principal user) {
-	Enumeration individualPositive = zeroSet.elements();
+    private Enumeration<Permission> getIndividualPositive(Principal user) {
+	Enumeration<Permission> individualPositive = zeroSet.elements();
 	AclEntry ae = (AclEntry) allowedUsersTable.get(user);
 	if (ae != null)
 	    individualPositive = ae.permissions();
 	return individualPositive;
     }
 
-    private Enumeration getIndividualNegative(Principal user) {
-	Enumeration individualNegative = zeroSet.elements();
+    private Enumeration<Permission> getIndividualNegative(Principal user) {
+	Enumeration<Permission> individualNegative = zeroSet.elements();
 	AclEntry ae  = (AclEntry) deniedUsersTable.get(user);
 	if (ae != null)
 	    individualNegative = ae.permissions();
@@ -353,12 +353,12 @@ public class AclImpl extends OwnerImpl implements Acl {
     }
 }
 
-final class AclEnumerator implements Enumeration {
+final class AclEnumerator implements Enumeration<AclEntry> {
     Acl acl;
-    Enumeration u1, u2, g1, g2;
+    Enumeration<AclEntry> u1, u2, g1, g2;
 
-    AclEnumerator(Acl acl, Hashtable u1, Hashtable g1, 
-		  Hashtable u2, Hashtable g2) {
+    AclEnumerator(Acl acl, Hashtable<Principal, AclEntry> u1, Hashtable<Principal, AclEntry> g1, 
+		  Hashtable<Principal, AclEntry> u2, Hashtable<Principal, AclEntry> g2) {
 	this.acl = acl;
 	this.u1 = u1.elements();
 	this.u2 = u2.elements();
@@ -373,9 +373,8 @@ final class AclEnumerator implements Enumeration {
 		g2.hasMoreElements());
     }
 
-    public Object nextElement() 
+    public AclEntry nextElement() 
     {
-	Object o;
 	synchronized (acl) {
 	    if (u1.hasMoreElements())
 		return u1.nextElement();
diff --git a/pki/base/util/src/netscape/security/acl/OwnerImpl.java b/pki/base/util/src/netscape/security/acl/OwnerImpl.java
index 7ced59efdd53caac042c8f7c460f4838b9d1ac8f..7296590ee1ddff0be6b347830ffddfaa9940e914 100644
--- a/pki/base/util/src/netscape/security/acl/OwnerImpl.java
+++ b/pki/base/util/src/netscape/security/acl/OwnerImpl.java
@@ -80,7 +80,7 @@ public class OwnerImpl implements Owner {
 	if (!isOwner(caller))
 	    throw new NotOwnerException();
 	
-	Enumeration e = ownerGroup.members();
+	Enumeration<? extends Principal> e = ownerGroup.members();
 	//
 	// check if there is atleast 2 members left.
 	//
-- 
1.7.7.3

