jdk/src/java.rmi/share/classes/com/sun/rmi/rmid/ExecPermission.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 14342 jdk/src/share/classes/com/sun/rmi/rmid/ExecPermission.java@8435a30053c1
child 30655 d83f50188ca9
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12040
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.rmi.rmid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The ExecPermission class represents permission for rmid to execute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * a specific command to launch an activation group.  An ExecPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * consists of a pathname of a command to launch an activation group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Pathname is the pathname of the file or directory to grant rmid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * execute permission.  A pathname that ends in "/*" (where "/" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the file separator character, <code>File.separatorChar</code>) indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * all the files and directories contained in that directory. A pathname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * that ends with "/-" indicates (recursively) all files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and subdirectories contained in that directory. A pathname consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the special token "&lt;&lt;ALL FILES&gt;&gt;" matches <bold>any</bold> file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Note: A pathname consisting of a single "*" indicates all the files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * in the current directory, while a pathname consisting of a single "-"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * indicates all the files in the current directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * (recursively) all files and subdirectories contained in the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @serial exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public final class ExecPermission extends Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * UID for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final long serialVersionUID = -6208470287358147919L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private transient FilePermission fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Creates a new ExecPermission object with the specified path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <i>path</i> is the pathname of a file or directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <p>A pathname that ends in "/*" (where "/" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the file separator character, <code>File.separatorChar</code>) indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * a directory and all the files contained in that directory. A pathname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * that ends with "/-" indicates a directory and (recursively) all files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * and subdirectories contained in that directory. The special pathname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * "&lt;&lt;ALL FILES&gt;&gt;" matches all files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <p>A pathname consisting of a single "*" indicates all the files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * in the current directory, while a pathname consisting of a single "-"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * indicates all the files in the current directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * (recursively) all files and subdirectories contained in the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param path the pathname of the file/directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public ExecPermission(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        super(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        init(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Creates a new ExecPermission object with the specified path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <i>path</i> is the pathname of a file or directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <p>A pathname that ends in "/*" (where "/" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * the file separator character, <code>File.separatorChar</code>) indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * a directory and all the files contained in that directory. A pathname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * that ends with "/-" indicates a directory and (recursively) all files
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * and subdirectories contained in that directory. The special pathname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * "&lt;&lt;ALL FILES&gt;&gt;" matches all files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <p>A pathname consisting of a single "*" indicates all the files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * in the current directory, while a pathname consisting of a single "-"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * indicates all the files in the current directory and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * (recursively) all files and subdirectories contained in the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param path the pathname of the file/directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param actions the action string (unused)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public ExecPermission(String path, String actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Checks if this ExecPermission object "implies" the specified permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * More specifically, this method returns true if:<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <li> <i>p</i> is an instanceof ExecPermission,<p> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <li> <i>p</i>'s pathname is implied by this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *      pathname. For example, "/tmp/*" implies "/tmp/foo", since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *      "/tmp/*" encompasses the "/tmp" directory and all files in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *      directory, including the one named "foo".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param p the permission to check against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return true if the specified permission is implied by this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean implies(Permission p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (!(p instanceof ExecPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        ExecPermission that = (ExecPermission) p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return fp.implies(that.fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Checks two ExecPermission objects for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Checks that <i>obj</i>'s class is the same as this object's class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * and has the same name as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param obj the object we are testing for equality with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return true if <i>obj</i> is an ExecPermission, and has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * pathname as this ExecPermission object, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (obj == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (! (obj instanceof ExecPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        ExecPermission that = (ExecPermission) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return fp.equals(that.fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return this.fp.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Returns the canonical string representation of the actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the canonical string representation of the actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public String getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Returns a new PermissionCollection object for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * ExecPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * A ExecPermissionCollection stores a collection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * ExecPermission permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <p>ExecPermission objects must be stored in a manner that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * them to be inserted in any order, but that also enables the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * PermissionCollection <code>implies</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * to be implemented in an efficient (and consistent) manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @return a new PermissionCollection object suitable for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * storing ExecPermissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public PermissionCollection newPermissionCollection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return new ExecPermissionCollection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * readObject is called to restore the state of the ExecPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * from a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private synchronized void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // init is called to initialize the rest of the values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        init(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Initialize a ExecPermission object. Common to all constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Also called during de-serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private void init(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this.fp = new FilePermission(path, "execute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * A ExecPermissionCollection stores a collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * of ExecPermission permissions. ExecPermission objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * must be stored in a manner that allows them to be inserted in any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * order, but enable the implies function to evaluate the implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * method in an efficient (and consistent) manner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @serial include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private static class ExecPermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        extends PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        implements java.io.Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   230
        private Vector<Permission> permissions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        private static final long serialVersionUID = -3352558508888368273L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * Create an empty ExecPermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        public ExecPermissionCollection() {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   238
            permissions = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         * Adds a permission to the collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         * @exception IllegalArgumentException - if the permission is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         *                                       ExecPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         * @exception SecurityException - if this ExecPermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         *                                object has been marked readonly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public void add(Permission permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (! (permission instanceof ExecPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                throw new IllegalArgumentException("invalid permission: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                                   permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (isReadOnly())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            permissions.addElement(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * Check and see if this set of permissions implies the permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * expressed in "permission".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * @param p the Permission object to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         * @return true if "permission" is a proper subset of a permission in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * the set, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        public boolean implies(Permission permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if (! (permission instanceof ExecPermission))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   277
            Enumeration<Permission> e = permissions.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            while (e.hasMoreElements()) {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   280
                ExecPermission x = (ExecPermission)e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (x.implies(permission)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * Returns an enumeration of all the ExecPermission objects in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
         * @return an enumeration of all the ExecPermission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
         */
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 5506
diff changeset
   294
        public Enumeration<Permission> elements()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return permissions.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}