From d6c9e9fe6c8c35fa74db79c74a6db9d71bb33912 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 21 Nov 2011 11:06:15 -0500 Subject: 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 | 25 ++++--- .../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, 72 insertions(+), 72 deletions(-) (limited to 'pki') 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 249bb4420..471371f9c 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 mArgs = new Hashtable(); /** * Returns a list of argument names. * * @return list of argument names */ - public Enumeration getNames() { + public Enumeration 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 e0a37eb4b..4cfe9a457 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 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 avas = new Vector(); 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 0b8bad8f3..270d1fa20 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 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 6438dc4ae..90e81ed4b 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,7 +66,6 @@ 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; @@ -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 mParamNames; + protected static Hashtable mParamDefault; + protected Hashtable mParamValue = null; static { - mParamNames = new Vector(); - mParamDefault = new Hashtable(); + mParamNames = new Vector(); + mParamDefault = new Hashtable(); 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(); 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 getInstanceParams() { + Vector params = new Vector(); - Enumeration e = mParamNames.elements(); + Enumeration 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 getDefaultParams() { + Vector params = new Vector(); - Enumeration e = mParamNames.elements(); + Enumeration 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 fd89ceaf1..b90278fa6 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 e = null; + Enumeration 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 8d6c325fa..7cd563f99 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 v = new Vector(); /** * 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 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 6f1b77650..471868816 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 permissionSet = new Vector(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 permissions() { return permissionSet.elements(); } @@ -144,7 +144,7 @@ public class AclEntryImpl implements AclEntry { else s.append("User."); s.append(user + "="); - Enumeration e = permissions(); + Enumeration 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(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 5624b75f1..6a5d4fd2d 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 allowedUsersTable = new Hashtable(23); + private Hashtable allowedGroupsTable = new Hashtable(23); + private Hashtable deniedUsersTable = new Hashtable(23); + private Hashtable deniedGroupsTable = new Hashtable(23); private String aclName = null; - private Vector zeroSet = new Vector(1,1); + private Vector zeroSet = new Vector(1,1); /** @@ -100,7 +100,7 @@ public class AclImpl extends OwnerImpl implements Acl { if (!isOwner(caller)) throw new NotOwnerException(); - Hashtable aclTable = findTable(entry); + Hashtable 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 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 getPermissions(Principal user) { - Enumeration individualPositive; - Enumeration individualNegative; - Enumeration groupPositive; - Enumeration groupNegative; + Enumeration individualPositive; + Enumeration individualNegative; + Enumeration groupPositive; + Enumeration 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 temp1 = subtract(groupPositive, individualNegative); + Enumeration 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 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 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 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 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 findTable(AclEntry entry) { + Hashtable 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 Enumeration union(Enumeration e1, Enumeration e2) { + Vector v = new Vector(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 Enumeration subtract(Enumeration e1, Enumeration e2) { + Vector v = new Vector (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 getGroupPositive(Principal user) { + Enumeration groupPositive = zeroSet.elements(); + Enumeration 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 getGroupNegative(Principal user) { + Enumeration groupNegative = zeroSet.elements(); + Enumeration 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 getIndividualPositive(Principal user) { + Enumeration 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 getIndividualNegative(Principal user) { + Enumeration 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 { Acl acl; - Enumeration u1, u2, g1, g2; + Enumeration u1, u2, g1, g2; - AclEnumerator(Acl acl, Hashtable u1, Hashtable g1, - Hashtable u2, Hashtable g2) { + AclEnumerator(Acl acl, Hashtable u1, Hashtable g1, + Hashtable u2, Hashtable 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 7ced59efd..7296590ee 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 e = ownerGroup.members(); // // check if there is atleast 2 members left. // -- cgit