From 02fb0b431b375c4b68ab82d8a6813a52a316ea8a Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Thu, 31 Oct 2013 21:35:49 -0400
Subject: [PATCH] Removed duplicate ACL classes.

The ACL and ACLEntry in com.netscape.cmscore.realm are duplicates
of the ones in com.netscape.certsrv.acls. They have been removed
since they are no longer used. All differences have been merged
into the remaining copy.
---
 base/common/src/com/netscape/certsrv/acls/ACL.java |  42 ++--
 .../src/com/netscape/certsrv/acls/ACLEntry.java    |  18 +-
 .../src/com/netscape/cmscore/realm/ACL.java        | 193 ----------------
 .../src/com/netscape/cmscore/realm/ACLEntry.java   | 243 ---------------------
 4 files changed, 30 insertions(+), 466 deletions(-)
 delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/realm/ACL.java
 delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/realm/ACLEntry.java

diff --git a/base/common/src/com/netscape/certsrv/acls/ACL.java b/base/common/src/com/netscape/certsrv/acls/ACL.java
index 83be047e724affab78c656b386ca64f0f17ffabd..292be4cddc1c864e2cff8494f047295cd142b40f 100644
--- a/base/common/src/com/netscape/certsrv/acls/ACL.java
+++ b/base/common/src/com/netscape/certsrv/acls/ACL.java
@@ -39,11 +39,11 @@ public class ACL implements IACL, java.io.Serializable {
     */
     private static final long serialVersionUID = -1867465948611161868L;
 
-    protected Vector<ACLEntry> mEntries = new Vector<ACLEntry>(); // ACL entries
-    protected Vector<String> mRights = null; // possible rights entries
-    protected String mResourceACLs = null; // exact resourceACLs string on ldap server
-    protected String mName = null; // resource name
-    protected String mDescription = null; // resource description
+    protected Vector<ACLEntry> entries = new Vector<ACLEntry>(); // ACL entries
+    protected Vector<String> rights = null; // possible rights entries
+    protected String resourceACLs = null; // exact resourceACLs string on ldap server
+    protected String name = null; // resource name
+    protected String description = null; // resource description
 
     /**
      * Class constructor.
@@ -68,11 +68,11 @@ public class ACL implements IACL, java.io.Serializable {
     public ACL(String name, Vector<String> rights, String resourceACLs) {
         setName(name);
         if (rights != null) {
-            mRights = rights;
+            this.rights = rights;
         } else {
-            mRights = new Vector<String>();
+            this.rights = new Vector<String>();
         }
-        mResourceACLs = resourceACLs;
+        this.resourceACLs = resourceACLs;
 
     }
 
@@ -83,7 +83,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @param name name of the resource
      */
     public void setName(String name) {
-        mName = name;
+        this.name = name;
     }
 
     /**
@@ -93,7 +93,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @return name of the resource
      */
     public String getName() {
-        return mName;
+        return name;
     }
 
     /**
@@ -102,7 +102,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @return resource's acl
      */
     public String getResourceACLs() {
-        return mResourceACLs;
+        return resourceACLs;
     }
 
     /**
@@ -112,7 +112,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @param description Description of the protected resource
      */
     public void setDescription(String description) {
-        mDescription = description;
+        this.description = description;
     }
 
     /**
@@ -122,7 +122,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @return Description of the protected resource
      */
     public String getDescription() {
-        return mDescription;
+        return description;
     }
 
     /**
@@ -131,7 +131,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @param entry the <code>ACLEntry</code> to be added to this resource
      */
     public void addEntry(ACLEntry entry) {
-        mEntries.addElement(entry);
+        entries.addElement(entry);
     }
 
     /**
@@ -140,7 +140,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @return enumeration for the <code>ACLEntry</code> vector
      */
     public Enumeration<ACLEntry> entries() {
-        return mEntries.elements();
+        return entries.elements();
     }
 
     /**
@@ -151,17 +151,17 @@ public class ACL implements IACL, java.io.Serializable {
      *         <resource name>[<ACLEntry1>,<ACLEntry 2>,...<ACLEntry N>]
      */
     public String toString() {
-        StringBuffer entries = new StringBuffer();
+        StringBuilder entries = new StringBuilder();
         Enumeration<ACLEntry> e = entries();
 
         for (; e.hasMoreElements();) {
             ACLEntry entry = e.nextElement();
 
-            entries.append(entry.toString());
+            entries.append(entry);
             if (e.hasMoreElements())
                 entries.append(",");
         }
-        return getName() + "[" + entries.toString() + "]";
+        return getName() + "[" + entries + "]";
     }
 
     /**
@@ -170,7 +170,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @param right The right to be added for this ACL
      */
     public void addRight(String right) {
-        mRights.addElement(right);
+        rights.addElement(right);
     }
 
     /**
@@ -180,7 +180,7 @@ public class ACL implements IACL, java.io.Serializable {
      * @return true if it's one of the "rights"; false otherwise
      */
     public boolean checkRight(String permission) {
-        return mRights.contains(permission);
+        return rights.contains(permission);
     }
 
     /**
@@ -189,6 +189,6 @@ public class ACL implements IACL, java.io.Serializable {
      * @return enumeration of rights defined for this ACL
      */
     public Enumeration<String> rights() {
-        return mRights.elements();
+        return rights.elements();
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/acls/ACLEntry.java b/base/common/src/com/netscape/certsrv/acls/ACLEntry.java
index ca08fb551ee3c47d0094f410f43a21d7b9fd357a..23f85962761f71347785f381a8358bfc74ed8133 100644
--- a/base/common/src/com/netscape/certsrv/acls/ACLEntry.java
+++ b/base/common/src/com/netscape/certsrv/acls/ACLEntry.java
@@ -34,9 +34,9 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
     private static final long serialVersionUID = 422656406529200393L;
 
     protected Hashtable<String, String> mPerms = new Hashtable<String, String>();
-    protected String mExpressions = null;
-    protected boolean mNegative = false;
-    protected String mACLEntryString = null;
+    protected String expressions = null;
+    protected boolean negative = false;
+    protected String aclEntryString = null;
 
     /**
      * Class Constructor
@@ -51,14 +51,14 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
      *         false if this ACL entry expression is for "allow"
      */
     public boolean isNegative() {
-        return mNegative;
+        return negative;
     }
 
     /**
      * Sets this ACL entry negative. This ACL entry expression is for "deny".
      */
     public void setNegative() {
-        mNegative = true;
+        negative = true;
     }
 
     /**
@@ -71,7 +71,7 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
      * </PRE>
      */
     public void setACLEntryString(String s) {
-        mACLEntryString = s;
+        aclEntryString = s;
     }
 
     /**
@@ -84,7 +84,7 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
      * </PRE>
      */
     public String getACLEntryString() {
-        return mACLEntryString;
+        return aclEntryString;
     }
 
     /**
@@ -120,7 +120,7 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
      *            group="Administrators"
      */
     public void setAttributeExpressions(String expressions) {
-        mExpressions = expressions;
+        this.expressions = expressions;
     }
 
     /**
@@ -130,7 +130,7 @@ public class ACLEntry implements IACLEntry, java.io.Serializable {
      *         group="Administrators"
      */
     public String getAttributeExpressions() {
-        return mExpressions;
+        return expressions;
     }
 
     /**
diff --git a/base/server/cmscore/src/com/netscape/cmscore/realm/ACL.java b/base/server/cmscore/src/com/netscape/cmscore/realm/ACL.java
deleted file mode 100644
index 13fcdac448903b79f7df703968346590f6b443df..0000000000000000000000000000000000000000
--- a/base/server/cmscore/src/com/netscape/cmscore/realm/ACL.java
+++ /dev/null
@@ -1,193 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2007 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package com.netscape.cmscore.realm;
-
-import java.util.Enumeration;
-import java.util.Vector;
-
-/**
- * A class represents an access control list (ACL). An ACL
- * is associated with an protected resources. The policy
- * enforcer can verify the ACLs with the current
- * context to see if the corresponding resource is accessible.
- * <P>
- * An <code>ACL</code> may contain one or more <code>ACLEntry</code>. However, in case of multiple <code>ACLEntry</code>
- * , a subject must pass ALL of the <code>ACLEntry</code> evaluation for permission to be granted
- * <P>
- *
- * @version $Revision$, $Date$
- */
-public class ACL  {
-
-    /**
-    *
-    */
-
-    protected Vector<ACLEntry> entries = new Vector<ACLEntry>(); // ACL entries
-    protected Vector<String> rights = null; // possible rights entries
-    protected String resourceACLs = null; // exact resourceACLs string on ldap server
-    protected String name = null; // resource name
-    protected String description = null; // resource description
-
-    /**
-     * Class constructor.
-     */
-    public ACL() {
-    }
-
-    /**
-     * Class constructor.
-     * Constructs an access control list associated
-     * with a resource name
-     *
-     * @param name resource name
-     * @param rights applicable rights defined for this resource
-     * @param resourceACLs the entire ACL specification. For example:
-     *            "certServer.log.configuration:read,modify:
-     *            allow (read,modify)
-     *            group=\"Administrators\":
-     *            Allow administrators to read and modify log
-     *            configuration"
-     */
-    public ACL(String name, Vector<String> rights, String resourceACLs) {
-        setName(name);
-        if (rights != null) {
-            this.rights = rights;
-        } else {
-            this.rights = new Vector<String>();
-        }
-        this.resourceACLs = resourceACLs;
-
-    }
-
-    /**
-     * Sets the name of the resource governed by this
-     * access control.
-     *
-     * @param name name of the resource
-     */
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    /**
-     * Retrieves the name of the resource governed by
-     * this access control.
-     *
-     * @return name of the resource
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Retrieves the exact string of the resourceACLs
-     *
-     * @return resource's acl
-     */
-    public String getResourceACLs() {
-        return resourceACLs;
-    }
-
-    /**
-     * Sets the description of the resource governed by this
-     * access control.
-     *
-     * @param description Description of the protected resource
-     */
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-    /**
-     * Retrieves the description of the resource governed by
-     * this access control.
-     *
-     * @return Description of the protected resource
-     */
-    public String getDescription() {
-        return description;
-    }
-
-    /**
-     * Adds an ACL entry to this list.
-     *
-     * @param entry the <code>ACLEntry</code> to be added to this resource
-     */
-    public void addEntry(ACLEntry entry) {
-        entries.addElement(entry);
-    }
-
-    /**
-     * Returns ACL entries.
-     *
-     * @return enumeration for the <code>ACLEntry</code> vector
-     */
-    public Enumeration<ACLEntry> entries() {
-        return entries.elements();
-    }
-
-    /**
-     * Returns the string reprsentation.
-     *
-     * @return the string representation of the ACL entries in the
-     *         following format:
-     *         <resource name>[<ACLEntry1>,<ACLEntry 2>,...<ACLEntry N>]
-     */
-    public String toString() {
-        StringBuilder entries = new StringBuilder();
-        Enumeration<ACLEntry> e = entries();
-
-        for (; e.hasMoreElements();) {
-            ACLEntry entry = e.nextElement();
-
-            entries.append(entry);
-            if (e.hasMoreElements())
-                entries.append(",");
-        }
-        return getName() + "[" + entries + "]";
-    }
-
-    /**
-     * Adds an rights entry to this list.
-     *
-     * @param right The right to be added for this ACL
-     */
-    public void addRight(String right) {
-        rights.addElement(right);
-    }
-
-    /**
-     * Tells if the permission is one of the defined "rights"
-     *
-     * @param permission permission to be checked
-     * @return true if it's one of the "rights"; false otherwise
-     */
-    public boolean checkRight(String permission) {
-        return (rights.contains(permission));
-    }
-
-    /**
-     * Returns rights entries.
-     *
-     * @return enumeration of rights defined for this ACL
-     */
-    public Enumeration<String> rights() {
-        return rights.elements();
-    }
-}
diff --git a/base/server/cmscore/src/com/netscape/cmscore/realm/ACLEntry.java b/base/server/cmscore/src/com/netscape/cmscore/realm/ACLEntry.java
deleted file mode 100644
index 1e13ad682fd28db002e4d9350b3d23e483709867..0000000000000000000000000000000000000000
--- a/base/server/cmscore/src/com/netscape/cmscore/realm/ACLEntry.java
+++ /dev/null
@@ -1,243 +0,0 @@
-// --- BEGIN COPYRIGHT BLOCK ---
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// (C) 2007 Red Hat, Inc.
-// All rights reserved.
-// --- END COPYRIGHT BLOCK ---
-package com.netscape.cmscore.realm;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
-
-/**
- * A class represents an ACI entry of an access control list.
- * <P>
- *
- * @version $Revision$, $Date$
- */
-public class ACLEntry {
-    /**
-    *
-    */
-    protected Hashtable<String, String> mPerms = new Hashtable<String, String>();
-    protected String expressions = null;
-    protected boolean negative = false;
-    protected String ACLEntryString = null;
-
-    /**
-     * Class Constructor
-     */
-    public ACLEntry() {
-    }
-
-    /**
-     * Checks if this ACL entry is set to negative.
-     *
-     * @return true if this ACL entry expression is for "deny";
-     *         false if this ACL entry expression is for "allow"
-     */
-    public boolean isNegative() {
-        return negative;
-    }
-
-    /**
-     * Sets this ACL entry negative. This ACL entry expression is for "deny".
-     */
-    public void setNegative() {
-        negative = true;
-    }
-
-    /**
-     * Sets the ACL entry string
-     *
-     * @param s string in the following format:
-     *
-     *            <PRE>
-     *   allow|deny (right[,right...]) attribute_expression
-     * </PRE>
-     */
-    public void setACLEntryString(String s) {
-        ACLEntryString = s;
-    }
-
-    /**
-     * Gets the ACL Entry String
-     *
-     * @return ACL Entry string in the following format:
-     *
-     *         <PRE>
-     *   allow|deny (right[,right...]) attribute_expression
-     * </PRE>
-     */
-    public String getACLEntryString() {
-        return ACLEntryString;
-    }
-
-    /**
-     * Adds permission to this entry. Permission must be one of the
-     * "rights" defined for each protected resource in its ACL
-     *
-     * @param acl the acl instance that this aclEntry is associated with
-     * @param permission one of the "rights" defined for each
-     *            protected resource in its ACL
-     */
-    public void addPermission(ACL acl, String permission) {
-        if (acl.checkRight(permission) == true) {
-            mPerms.put(permission, permission);
-        } else {
-            // not a valid right...log it later
-        }
-    }
-
-    /**
-     * Returns a list of permissions associated with
-     * this entry.
-     *
-     * @return a list of permissions for this ACL entry
-     */
-    public Enumeration<String> permissions() {
-        return mPerms.elements();
-    }
-
-    /**
-     * Sets the expression associated with this entry.
-     *
-     * @param expressions the evaluator expressions. For example,
-     *            group="Administrators"
-     */
-    public void setAttributeExpressions(String expressions) {
-        this.expressions = expressions;
-    }
-
-    /**
-     * Retrieves the expression associated with this entry.
-     *
-     * @return the evaluator expressions. For example,
-     *         group="Administrators"
-     */
-    public String getAttributeExpressions() {
-        return expressions;
-    }
-
-    /**
-     * Checks to see if this <code>ACLEntry</code> contains a
-     * particular permission
-     *
-     * @param permission one of the "rights" defined for each
-     *            protected resource in its ACL
-     * @return true if permission contained in the permission list
-     *         for this <code>ACLEntry</code>; false otherwise.
-     */
-    public boolean containPermission(String permission) {
-        return (mPerms.get(permission) != null);
-    }
-
-    /**
-     * Checks if this entry has the given permission.
-     *
-     * @param permission one of the "rights" defined for each
-     *            protected resource in its ACL
-     * @return true if the permission is allowed; false if the
-     *         permission is denied. If a permission is not
-     *         recognized by this ACL, it is considered denied
-     */
-    public boolean checkPermission(String permission) {
-        // default - if we dont know about the requested permission,
-        //           don't grant permission
-        if (mPerms.get(permission) == null)
-            return false;
-        if (isNegative()) {
-            return false;
-        } else {
-            return true;
-        }
-    }
-
-    /**
-     * Parse string in the following format:
-     *
-     * <PRE>
-     *   allow|deny (right[,right...]) attribute_expression
-     * </PRE>
-     *
-     * into an instance of the <code>ACLEntry</code> class
-     *
-     * @param acl the acl instance associated with this aclentry
-     * @param aclEntryString aclEntryString in the specified format
-     * @return an instance of the <code>ACLEntry</code> class
-     */
-    public static ACLEntry parseACLEntry(ACL acl, String aclEntryString) {
-        if (aclEntryString == null) {
-            return null;
-        }
-
-        String te = aclEntryString.trim();
-
-        // locate first space
-        int i = te.indexOf(' ');
-        // prefix should be "allowed" or "deny"
-        String prefix = te.substring(0, i);
-        String suffix = te.substring(i + 1).trim();
-        ACLEntry entry = new ACLEntry();
-
-        if (prefix.equals("allow")) {
-            // do nothing
-        } else if (prefix.equals("deny")) {
-            entry.setNegative();
-        } else {
-            return null;
-        }
-        // locate the second space
-        i = suffix.indexOf(' ');
-        // this prefix should be rights list, delimited by ","
-        prefix = suffix.substring(1, i - 1);
-        // the suffix is the rest, which is the "expressions"
-        suffix = suffix.substring(i + 1).trim();
-
-        StringTokenizer st = new StringTokenizer(prefix, ",");
-
-        for (; st.hasMoreTokens();) {
-            entry.addPermission(acl, st.nextToken());
-        }
-        entry.setAttributeExpressions(suffix);
-        return entry;
-    }
-
-    /**
-     * Returns the string representation of this ACLEntry
-     *
-     * @return string representation of this ACLEntry
-     */
-    public String toString() {
-        StringBuffer entry = new StringBuffer();
-
-        if (isNegative()) {
-            entry.append("deny (");
-        } else {
-            entry.append("allow (");
-        }
-        Enumeration<String> e = permissions();
-
-        for (; e.hasMoreElements();) {
-            String p = e.nextElement();
-
-            entry.append(p);
-            if (e.hasMoreElements())
-                entry.append(",");
-        }
-        entry.append(") " + getAttributeExpressions());
-        return entry.toString();
-    }
-}
-- 
1.8.1.4

