equal
deleted
inserted
replaced
66 * @author Marianne Mueller |
66 * @author Marianne Mueller |
67 * @author Roland Schemers |
67 * @author Roland Schemers |
68 */ |
68 */ |
69 |
69 |
70 public abstract class BasicPermission extends Permission |
70 public abstract class BasicPermission extends Permission |
71 implements java.io.Serializable |
71 implements java.io.Serializable |
72 { |
72 { |
73 |
73 |
74 private static final long serialVersionUID = 6279438298436773498L; |
74 private static final long serialVersionUID = 6279438298436773498L; |
75 |
75 |
76 // does this permission have a wildcard at the end? |
76 // does this permission have a wildcard at the end? |
82 // is this permission the old-style exitVM permission (pre JDK 1.6)? |
82 // is this permission the old-style exitVM permission (pre JDK 1.6)? |
83 private transient boolean exitVM; |
83 private transient boolean exitVM; |
84 |
84 |
85 /** |
85 /** |
86 * initialize a BasicPermission object. Common to all constructors. |
86 * initialize a BasicPermission object. Common to all constructors. |
87 * |
87 */ |
88 */ |
88 private void init(String name) { |
89 private void init(String name) |
|
90 { |
|
91 if (name == null) |
89 if (name == null) |
92 throw new NullPointerException("name can't be null"); |
90 throw new NullPointerException("name can't be null"); |
93 |
91 |
94 int len = name.length(); |
92 int len = name.length(); |
95 |
93 |
127 * @param name the name of the BasicPermission. |
125 * @param name the name of the BasicPermission. |
128 * |
126 * |
129 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
127 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
130 * @throws IllegalArgumentException if <code>name</code> is empty. |
128 * @throws IllegalArgumentException if <code>name</code> is empty. |
131 */ |
129 */ |
132 |
130 public BasicPermission(String name) { |
133 public BasicPermission(String name) |
|
134 { |
|
135 super(name); |
131 super(name); |
136 init(name); |
132 init(name); |
137 } |
133 } |
138 |
134 |
139 |
135 |
146 * @param actions ignored. |
142 * @param actions ignored. |
147 * |
143 * |
148 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
144 * @throws NullPointerException if <code>name</code> is <code>null</code>. |
149 * @throws IllegalArgumentException if <code>name</code> is empty. |
145 * @throws IllegalArgumentException if <code>name</code> is empty. |
150 */ |
146 */ |
151 public BasicPermission(String name, String actions) |
147 public BasicPermission(String name, String actions) { |
152 { |
|
153 super(name); |
148 super(name); |
154 init(name); |
149 init(name); |
155 } |
150 } |
156 |
151 |
157 /** |
152 /** |
236 * which currently is the empty string "", since there are no actions for |
231 * which currently is the empty string "", since there are no actions for |
237 * a BasicPermission. |
232 * a BasicPermission. |
238 * |
233 * |
239 * @return the empty string "". |
234 * @return the empty string "". |
240 */ |
235 */ |
241 public String getActions() |
236 public String getActions() { |
242 { |
|
243 return ""; |
237 return ""; |
244 } |
238 } |
245 |
239 |
246 /** |
240 /** |
247 * Returns a new PermissionCollection object for storing BasicPermission |
241 * Returns a new PermissionCollection object for storing BasicPermission |
294 * A BasicPermissionCollection handles comparing a permission like "a.b.c.d.e" |
288 * A BasicPermissionCollection handles comparing a permission like "a.b.c.d.e" |
295 * with a Permission such as "a.b.*", or "*". |
289 * with a Permission such as "a.b.*", or "*". |
296 * |
290 * |
297 * @see java.security.Permission |
291 * @see java.security.Permission |
298 * @see java.security.Permissions |
292 * @see java.security.Permissions |
299 * @see java.security.PermissionsImpl |
|
300 * |
293 * |
301 * |
294 * |
302 * @author Roland Schemers |
295 * @author Roland Schemers |
303 * |
296 * |
304 * @serial include |
297 * @serial include |
305 */ |
298 */ |
306 |
299 |
307 final class BasicPermissionCollection |
300 final class BasicPermissionCollection |
308 extends PermissionCollection |
301 extends PermissionCollection |
309 implements java.io.Serializable |
302 implements java.io.Serializable |
310 { |
303 { |
311 |
304 |
312 private static final long serialVersionUID = 739301742472979399L; |
305 private static final long serialVersionUID = 739301742472979399L; |
313 |
306 |
314 /** |
307 /** |
358 * permissions in this collection. |
351 * permissions in this collection. |
359 * |
352 * |
360 * @exception SecurityException - if this BasicPermissionCollection object |
353 * @exception SecurityException - if this BasicPermissionCollection object |
361 * has been marked readonly |
354 * has been marked readonly |
362 */ |
355 */ |
363 |
356 public void add(Permission permission) { |
364 public void add(Permission permission) |
|
365 { |
|
366 if (! (permission instanceof BasicPermission)) |
357 if (! (permission instanceof BasicPermission)) |
367 throw new IllegalArgumentException("invalid permission: "+ |
358 throw new IllegalArgumentException("invalid permission: "+ |
368 permission); |
359 permission); |
369 if (isReadOnly()) |
360 if (isReadOnly()) |
370 throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); |
361 throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); |
396 |
387 |
397 /** |
388 /** |
398 * Check and see if this set of permissions implies the permissions |
389 * Check and see if this set of permissions implies the permissions |
399 * expressed in "permission". |
390 * expressed in "permission". |
400 * |
391 * |
401 * @param p the Permission object to compare |
392 * @param permission the Permission object to compare |
402 * |
393 * |
403 * @return true if "permission" is a proper subset of a permission in |
394 * @return true if "permission" is a proper subset of a permission in |
404 * the set, false if not. |
395 * the set, false if not. |
405 */ |
396 */ |
406 |
397 public boolean implies(Permission permission) { |
407 public boolean implies(Permission permission) |
|
408 { |
|
409 if (! (permission instanceof BasicPermission)) |
398 if (! (permission instanceof BasicPermission)) |
410 return false; |
399 return false; |
411 |
400 |
412 BasicPermission bp = (BasicPermission) permission; |
401 BasicPermission bp = (BasicPermission) permission; |
413 |
402 |
414 // random subclasses of BasicPermission do not imply each other |
403 // random subclasses of BasicPermission do not imply each other |
415 if (bp.getClass() != permClass) |
404 if (bp.getClass() != permClass) |
466 * Returns an enumeration of all the BasicPermission objects in the |
455 * Returns an enumeration of all the BasicPermission objects in the |
467 * container. |
456 * container. |
468 * |
457 * |
469 * @return an enumeration of all the BasicPermission objects. |
458 * @return an enumeration of all the BasicPermission objects. |
470 */ |
459 */ |
471 |
|
472 public Enumeration<Permission> elements() { |
460 public Enumeration<Permission> elements() { |
473 // Convert Iterator of Map values into an Enumeration |
461 // Convert Iterator of Map values into an Enumeration |
474 synchronized (this) { |
462 synchronized (this) { |
475 return Collections.enumeration(perms.values()); |
463 return Collections.enumeration(perms.values()); |
476 } |
464 } |