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