1237 lines · 39.9 KB · Java
RawDownload
                return "*";            }            else {                if (addQuote) return "\"" + principalName + "\"";                else return principalName;            }        }         public String toString() {            if (!principalClass.equals(REPLACE_NAME)) {                return getDisplayClass() + "/" + getDisplayName();            } else {                return getDisplayName();            }        }         /**         * Test for equality between the specified object and this object.         * Two PrincipalEntries are equal if their PrincipalClass and         * PrincipalName values are equal.         *         * <p>         *         * @param obj the object to test for equality with this object.         *         * @return true if the objects are equal, false otherwise.         */        public boolean equals(Object obj) {            if (this == obj)                return true;             if (!(obj instanceof PrincipalEntry))                return false;             PrincipalEntry that = (PrincipalEntry)obj;            if (this.principalClass.equals(that.principalClass) &&                this.principalName.equals(that.principalName)) {                return true;            }             return false;        }         /**         * Return a hashcode for this <code>PrincipalEntry</code>.         *         * <p>         *         * @return a hashcode for this <code>PrincipalEntry</code>.         */        public int hashCode() {            return principalClass.hashCode();        }        public void write(PrintWriter out) {            out.print("principal " + getDisplayClass() + " " +                getDisplayName(true));        }    }     /**     * Each permission entry in the policy configuration file is     * represented by a     * PermissionEntry object.  <p>     *     * <p>     * For example, the entry     * <pre>     *          permission java.io.FilePermission "/tmp", "read,write";     * </pre>     * is represented internally     * <pre>     *     * pe = new PermissionEntry("java.io.FilePermission",     *                           "/tmp", "read,write");     * </pre>     *     * @author Roland Schemers     *     * version 1.19, 05/21/98     */     public static class PermissionEntry {         public String permission;        public String name;        public String action;        public String signedBy;         public PermissionEntry() {        }         public PermissionEntry(String permission,                        String name,                        String action) {            this.permission = permission;            this.name = name;            this.action = action;        }         /**         * Calculates a hash code value for the object.  Objects         * which are equal will also have the same hashcode.         */        public int hashCode() {            int retval = permission.hashCode();            if (name != null) retval ^= name.hashCode();            if (action != null) retval ^= action.hashCode();            return retval;        }         public boolean equals(Object obj) {            if (obj == this)                return true;             if (! (obj instanceof PermissionEntry))                return false;             PermissionEntry that = (PermissionEntry) obj;             if (this.permission == null) {                if (that.permission != null) return false;            } else {                if (!this.permission.equals(that.permission)) return false;            }             if (this.name == null) {                if (that.name != null) return false;            } else {                if (!this.name.equals(that.name)) return false;            }             if (this.action == null) {                if (that.action != null) return false;            } else {                if (!this.action.equals(that.action)) return false;            }             if (this.signedBy == null) {                if (that.signedBy != null) return false;            } else {                if (!this.signedBy.equals(that.signedBy)) return false;            }             // everything matched -- the 2 objects are equal            return true;        }         public void write(PrintWriter out) {            out.print("permission ");            out.print(permission);            if (name != null) {                out.print(" \"");                 // ATTENTION: regex with double escaping,                // the normal forms look like:                // $name =~ s/\\/\\\\/g; and                // $name =~ s/\"/\\\"/g;                // and then in a java string, it's escaped again                 out.print(name.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\\\""));                out.print('"');            }            if (action != null) {                out.print(", \"");                out.print(action);                out.print('"');            }            if (signedBy != null) {                out.print(", signedBy \"");                out.print(signedBy);                out.print('"');            }            out.println(";");        }    }     public static class ParsingException extends GeneralSecurityException {         private static final long serialVersionUID = -4330692689482574072L;         private String i18nMessage;         /**         * Constructs a ParsingException with the specified         * detail message. A detail message is a String that describes         * this particular exception, which may, for example, specify which         * algorithm is not available.         *         * @param msg the detail message.         */        public ParsingException(String msg) {            super(msg);            i18nMessage = msg;        }         public ParsingException(int line, String msg) {            super("line " + line + ": " + msg);            MessageFormat form = new MessageFormat                (ResourcesMgr.getString("line.number.msg"));            Object[] source = {new Integer(line), msg};            i18nMessage = form.format(source);        }         public ParsingException(int line, String expect, String actual) {            super("line " + line + ": expected [" + expect +                "], found [" + actual + "]");            MessageFormat form = new MessageFormat(ResourcesMgr.getString                ("line.number.expected.expect.found.actual."));            Object[] source = {new Integer(line), expect, actual};            i18nMessage = form.format(source);        }         public String getLocalizedMessage() {            return i18nMessage;        }    }     public static void main(String arg[]) throws Exception {        FileReader fr = null;        FileWriter fw = null;        try {            PolicyParser pp = new PolicyParser(true);            fr = new FileReader(arg[0]);            pp.read(fr);            fw = new FileWriter(arg[1]);            pp.write(fw);        } finally {            if (fr != null) {                fr.close();            }             if (fw != null) {                fw.close();            }        }    }}

Lines 1001–1237 of 1237. Previous lines