0N/A/*
2362N/A * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.rmi.rmid;
0N/A
0N/Aimport java.security.*;
0N/Aimport java.io.*;
0N/Aimport java.util.*;
0N/A
0N/A/**
0N/A * The ExecPermission class represents permission for rmid to execute
0N/A * a specific command to launch an activation group. An ExecPermission
0N/A * consists of a pathname of a command to launch an activation group.
0N/A * <P>
0N/A * Pathname is the pathname of the file or directory to grant rmid
0N/A * execute permission. A pathname that ends in "/*" (where "/" is
0N/A * the file separator character, <code>File.separatorChar</code>) indicates
0N/A * all the files and directories contained in that directory. A pathname
0N/A * that ends with "/-" indicates (recursively) all files
0N/A * and subdirectories contained in that directory. A pathname consisting of
0N/A * the special token "&lt;&lt;ALL FILES&gt;&gt;" matches <bold>any</bold> file.
0N/A * <P>
0N/A * Note: A pathname consisting of a single "*" indicates all the files
0N/A * in the current directory, while a pathname consisting of a single "-"
0N/A * indicates all the files in the current directory and
0N/A * (recursively) all files and subdirectories contained in the current
0N/A * directory.
0N/A * <P>
0N/A *
0N/A *
0N/A * @author Ann Wollrath
0N/A *
0N/A * @serial exclude
0N/A */
0N/Apublic final class ExecPermission extends Permission
0N/A{
0N/A /**
0N/A * UID for serialization
0N/A */
0N/A private static final long serialVersionUID = -6208470287358147919L;
0N/A
0N/A private transient FilePermission fp;
0N/A
0N/A /**
0N/A * Creates a new ExecPermission object with the specified path.
0N/A * <i>path</i> is the pathname of a file or directory.
0N/A *
0N/A * <p>A pathname that ends in "/*" (where "/" is
0N/A * the file separator character, <code>File.separatorChar</code>) indicates
0N/A * a directory and all the files contained in that directory. A pathname
0N/A * that ends with "/-" indicates a directory and (recursively) all files
0N/A * and subdirectories contained in that directory. The special pathname
0N/A * "&lt;&lt;ALL FILES&gt;&gt;" matches all files.
0N/A *
0N/A * <p>A pathname consisting of a single "*" indicates all the files
0N/A * in the current directory, while a pathname consisting of a single "-"
0N/A * indicates all the files in the current directory and
0N/A * (recursively) all files and subdirectories contained in the current
0N/A * directory.
0N/A *
0N/A * @param path the pathname of the file/directory.
0N/A */
0N/A public ExecPermission(String path) {
0N/A super(path);
0N/A init(path);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new ExecPermission object with the specified path.
0N/A * <i>path</i> is the pathname of a file or directory.
0N/A *
0N/A * <p>A pathname that ends in "/*" (where "/" is
0N/A * the file separator character, <code>File.separatorChar</code>) indicates
0N/A * a directory and all the files contained in that directory. A pathname
0N/A * that ends with "/-" indicates a directory and (recursively) all files
0N/A * and subdirectories contained in that directory. The special pathname
0N/A * "&lt;&lt;ALL FILES&gt;&gt;" matches all files.
0N/A *
0N/A * <p>A pathname consisting of a single "*" indicates all the files
0N/A * in the current directory, while a pathname consisting of a single "-"
0N/A * indicates all the files in the current directory and
0N/A * (recursively) all files and subdirectories contained in the current
0N/A * directory.
0N/A *
0N/A * @param path the pathname of the file/directory.
0N/A * @param actions the action string (unused)
0N/A */
0N/A public ExecPermission(String path, String actions) {
0N/A this(path);
0N/A }
0N/A
0N/A /**
0N/A * Checks if this ExecPermission object "implies" the specified permission.
0N/A * <P>
0N/A * More specifically, this method returns true if:<p>
0N/A * <ul>
0N/A * <li> <i>p</i> is an instanceof ExecPermission,<p> and
0N/A * <li> <i>p</i>'s pathname is implied by this object's
0N/A * pathname. For example, "/tmp/*" implies "/tmp/foo", since
0N/A * "/tmp/*" encompasses the "/tmp" directory and all files in that
0N/A * directory, including the one named "foo".
0N/A * </ul>
0N/A * @param p the permission to check against.
0N/A *
0N/A * @return true if the specified permission is implied by this object,
0N/A * false if not.
0N/A */
0N/A public boolean implies(Permission p) {
0N/A if (!(p instanceof ExecPermission))
0N/A return false;
0N/A
0N/A ExecPermission that = (ExecPermission) p;
0N/A
0N/A return fp.implies(that.fp);
0N/A }
0N/A
0N/A /**
0N/A * Checks two ExecPermission objects for equality.
0N/A * Checks that <i>obj</i>'s class is the same as this object's class
0N/A * and has the same name as this object.
0N/A * <P>
0N/A * @param obj the object we are testing for equality with this object.
0N/A * @return true if <i>obj</i> is an ExecPermission, and has the same
0N/A * pathname as this ExecPermission object, false otherwise.
0N/A */
0N/A public boolean equals(Object obj) {
0N/A if (obj == this)
0N/A return true;
0N/A
0N/A if (! (obj instanceof ExecPermission))
0N/A return false;
0N/A
0N/A ExecPermission that = (ExecPermission) obj;
0N/A
0N/A return fp.equals(that.fp);
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code value for this object.
0N/A *
0N/A * @return a hash code value for this object.
0N/A */
0N/A public int hashCode() {
0N/A return this.fp.hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Returns the canonical string representation of the actions.
0N/A *
0N/A * @return the canonical string representation of the actions.
0N/A */
0N/A public String getActions() {
0N/A return "";
0N/A }
0N/A
0N/A /**
0N/A * Returns a new PermissionCollection object for storing
0N/A * ExecPermission objects.
0N/A * <p>
0N/A * A ExecPermissionCollection stores a collection of
0N/A * ExecPermission permissions.
0N/A *
0N/A * <p>ExecPermission objects must be stored in a manner that allows
0N/A * them to be inserted in any order, but that also enables the
0N/A * PermissionCollection <code>implies</code> method
0N/A * to be implemented in an efficient (and consistent) manner.
0N/A *
0N/A * @return a new PermissionCollection object suitable for
0N/A * storing ExecPermissions.
0N/A */
0N/A public PermissionCollection newPermissionCollection() {
0N/A return new ExecPermissionCollection();
0N/A }
0N/A
0N/A /**
0N/A * readObject is called to restore the state of the ExecPermission
0N/A * from a stream.
0N/A */
0N/A private synchronized void readObject(java.io.ObjectInputStream s)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A s.defaultReadObject();
0N/A // init is called to initialize the rest of the values.
0N/A init(getName());
0N/A }
0N/A
0N/A /**
0N/A * Initialize a ExecPermission object. Common to all constructors.
0N/A * Also called during de-serialization.
0N/A */
0N/A private void init(String path) {
0N/A this.fp = new FilePermission(path, "execute");
0N/A }
0N/A
0N/A /**
0N/A * A ExecPermissionCollection stores a collection
0N/A * of ExecPermission permissions. ExecPermission objects
0N/A * must be stored in a manner that allows them to be inserted in any
0N/A * order, but enable the implies function to evaluate the implies
0N/A * method in an efficient (and consistent) manner.
0N/A *
0N/A * @serial include
0N/A */
0N/A private static class ExecPermissionCollection
0N/A extends PermissionCollection
0N/A implements java.io.Serializable
0N/A {
5559N/A private Vector<Permission> permissions;
0N/A
0N/A private static final long serialVersionUID = -3352558508888368273L;
0N/A
0N/A /**
0N/A * Create an empty ExecPermissionCollection.
0N/A */
0N/A public ExecPermissionCollection() {
5559N/A permissions = new Vector<>();
0N/A }
0N/A
0N/A /**
0N/A * Adds a permission to the collection.
0N/A *
0N/A * @param permission the Permission object to add.
0N/A *
0N/A * @exception IllegalArgumentException - if the permission is not a
0N/A * ExecPermission
0N/A *
0N/A * @exception SecurityException - if this ExecPermissionCollection
0N/A * object has been marked readonly
0N/A */
0N/A public void add(Permission permission)
0N/A {
0N/A if (! (permission instanceof ExecPermission))
0N/A throw new IllegalArgumentException("invalid permission: "+
0N/A permission);
0N/A if (isReadOnly())
0N/A throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
0N/A
0N/A permissions.addElement(permission);
0N/A }
0N/A
0N/A /**
0N/A * Check and see if this set of permissions implies the permissions
0N/A * expressed in "permission".
0N/A *
0N/A * @param p the Permission object to compare
0N/A *
0N/A * @return true if "permission" is a proper subset of a permission in
0N/A * the set, false if not.
0N/A */
0N/A public boolean implies(Permission permission)
0N/A {
0N/A if (! (permission instanceof ExecPermission))
0N/A return false;
0N/A
5559N/A Enumeration<Permission> e = permissions.elements();
0N/A
0N/A while (e.hasMoreElements()) {
5559N/A ExecPermission x = (ExecPermission)e.nextElement();
0N/A if (x.implies(permission)) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns an enumeration of all the ExecPermission objects in the
0N/A * container.
0N/A *
0N/A * @return an enumeration of all the ExecPermission objects.
0N/A */
5559N/A public Enumeration<Permission> elements()
0N/A {
0N/A return permissions.elements();
0N/A }
0N/A }
0N/A}