Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java
38923 views
/*1* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.rmi.rmid;2627import java.security.*;28import java.io.*;29import java.util.*;3031/**32* The ExecPermission class represents permission for rmid to execute33* a specific command to launch an activation group. An ExecPermission34* consists of a pathname of a command to launch an activation group.35* <P>36* Pathname is the pathname of the file or directory to grant rmid37* execute permission. A pathname that ends in "/*" (where "/" is38* the file separator character, <code>File.separatorChar</code>) indicates39* all the files and directories contained in that directory. A pathname40* that ends with "/-" indicates (recursively) all files41* and subdirectories contained in that directory. A pathname consisting of42* the special token "<<ALL FILES>>" matches <bold>any</bold> file.43* <P>44* Note: A pathname consisting of a single "*" indicates all the files45* in the current directory, while a pathname consisting of a single "-"46* indicates all the files in the current directory and47* (recursively) all files and subdirectories contained in the current48* directory.49* <P>50*51*52* @author Ann Wollrath53*54* @serial exclude55*/56public final class ExecPermission extends Permission57{58/**59* UID for serialization60*/61private static final long serialVersionUID = -6208470287358147919L;6263private transient FilePermission fp;6465/**66* Creates a new ExecPermission object with the specified path.67* <i>path</i> is the pathname of a file or directory.68*69* <p>A pathname that ends in "/*" (where "/" is70* the file separator character, <code>File.separatorChar</code>) indicates71* a directory and all the files contained in that directory. A pathname72* that ends with "/-" indicates a directory and (recursively) all files73* and subdirectories contained in that directory. The special pathname74* "<<ALL FILES>>" matches all files.75*76* <p>A pathname consisting of a single "*" indicates all the files77* in the current directory, while a pathname consisting of a single "-"78* indicates all the files in the current directory and79* (recursively) all files and subdirectories contained in the current80* directory.81*82* @param path the pathname of the file/directory.83*/84public ExecPermission(String path) {85super(path);86init(path);87}8889/**90* Creates a new ExecPermission object with the specified path.91* <i>path</i> is the pathname of a file or directory.92*93* <p>A pathname that ends in "/*" (where "/" is94* the file separator character, <code>File.separatorChar</code>) indicates95* a directory and all the files contained in that directory. A pathname96* that ends with "/-" indicates a directory and (recursively) all files97* and subdirectories contained in that directory. The special pathname98* "<<ALL FILES>>" matches all files.99*100* <p>A pathname consisting of a single "*" indicates all the files101* in the current directory, while a pathname consisting of a single "-"102* indicates all the files in the current directory and103* (recursively) all files and subdirectories contained in the current104* directory.105*106* @param path the pathname of the file/directory.107* @param actions the action string (unused)108*/109public ExecPermission(String path, String actions) {110this(path);111}112113/**114* Checks if this ExecPermission object "implies" the specified permission.115* <P>116* More specifically, this method returns true if:<p>117* <ul>118* <li> <i>p</i> is an instanceof ExecPermission,<p> and119* <li> <i>p</i>'s pathname is implied by this object's120* pathname. For example, "/tmp/*" implies "/tmp/foo", since121* "/tmp/*" encompasses the "/tmp" directory and all files in that122* directory, including the one named "foo".123* </ul>124* @param p the permission to check against.125*126* @return true if the specified permission is implied by this object,127* false if not.128*/129public boolean implies(Permission p) {130if (!(p instanceof ExecPermission))131return false;132133ExecPermission that = (ExecPermission) p;134135return fp.implies(that.fp);136}137138/**139* Checks two ExecPermission objects for equality.140* Checks that <i>obj</i>'s class is the same as this object's class141* and has the same name as this object.142* <P>143* @param obj the object we are testing for equality with this object.144* @return true if <i>obj</i> is an ExecPermission, and has the same145* pathname as this ExecPermission object, false otherwise.146*/147public boolean equals(Object obj) {148if (obj == this)149return true;150151if (! (obj instanceof ExecPermission))152return false;153154ExecPermission that = (ExecPermission) obj;155156return fp.equals(that.fp);157}158159/**160* Returns the hash code value for this object.161*162* @return a hash code value for this object.163*/164public int hashCode() {165return this.fp.hashCode();166}167168/**169* Returns the canonical string representation of the actions.170*171* @return the canonical string representation of the actions.172*/173public String getActions() {174return "";175}176177/**178* Returns a new PermissionCollection object for storing179* ExecPermission objects.180* <p>181* A ExecPermissionCollection stores a collection of182* ExecPermission permissions.183*184* <p>ExecPermission objects must be stored in a manner that allows185* them to be inserted in any order, but that also enables the186* PermissionCollection <code>implies</code> method187* to be implemented in an efficient (and consistent) manner.188*189* @return a new PermissionCollection object suitable for190* storing ExecPermissions.191*/192public PermissionCollection newPermissionCollection() {193return new ExecPermissionCollection();194}195196/**197* readObject is called to restore the state of the ExecPermission198* from a stream.199*/200private synchronized void readObject(java.io.ObjectInputStream s)201throws IOException, ClassNotFoundException202{203s.defaultReadObject();204// init is called to initialize the rest of the values.205init(getName());206}207208/**209* Initialize a ExecPermission object. Common to all constructors.210* Also called during de-serialization.211*/212private void init(String path) {213this.fp = new FilePermission(path, "execute");214}215216/**217* A ExecPermissionCollection stores a collection218* of ExecPermission permissions. ExecPermission objects219* must be stored in a manner that allows them to be inserted in any220* order, but enable the implies function to evaluate the implies221* method in an efficient (and consistent) manner.222*223* @serial include224*/225private static class ExecPermissionCollection226extends PermissionCollection227implements java.io.Serializable228{229private Vector<Permission> permissions;230231private static final long serialVersionUID = -3352558508888368273L;232233/**234* Create an empty ExecPermissionCollection.235*/236public ExecPermissionCollection() {237permissions = new Vector<>();238}239240/**241* Adds a permission to the collection.242*243* @param permission the Permission object to add.244*245* @exception IllegalArgumentException - if the permission is not a246* ExecPermission247*248* @exception SecurityException - if this ExecPermissionCollection249* object has been marked readonly250*/251public void add(Permission permission)252{253if (! (permission instanceof ExecPermission))254throw new IllegalArgumentException("invalid permission: "+255permission);256if (isReadOnly())257throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");258259permissions.addElement(permission);260}261262/**263* Check and see if this set of permissions implies the permissions264* expressed in "permission".265*266* @param p the Permission object to compare267*268* @return true if "permission" is a proper subset of a permission in269* the set, false if not.270*/271public boolean implies(Permission permission)272{273if (! (permission instanceof ExecPermission))274return false;275276Enumeration<Permission> e = permissions.elements();277278while (e.hasMoreElements()) {279ExecPermission x = (ExecPermission)e.nextElement();280if (x.implies(permission)) {281return true;282}283}284return false;285}286287/**288* Returns an enumeration of all the ExecPermission objects in the289* container.290*291* @return an enumeration of all the ExecPermission objects.292*/293public Enumeration<Permission> elements()294{295return permissions.elements();296}297}298}299300301