|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package java.security; |
|
|
|
import java.security.*; |
|
import java.util.Enumeration; |
|
import java.util.Hashtable; |
|
import java.util.StringTokenizer; |
|
import sun.security.util.SecurityConstants; |
|
|
|
/** |
|
* The AllPermission is a permission that implies all other permissions. |
|
* <p> |
|
* <b>Note:</b> Granting AllPermission should be done with extreme care, |
|
* as it implies all other permissions. Thus, it grants code the ability |
|
* to run with security |
|
* disabled. Extreme caution should be taken before granting such |
|
* a permission to code. This permission should be used only during testing, |
|
* or in extremely rare cases where an application or applet is |
|
* completely trusted and adding the necessary permissions to the policy |
|
* is prohibitively cumbersome. |
|
* |
|
* @see java.security.Permission |
|
* @see java.security.AccessController |
|
* @see java.security.Permissions |
|
* @see java.security.PermissionCollection |
|
* @see java.lang.SecurityManager |
|
* |
|
* |
|
* @author Roland Schemers |
|
* @since 1.2 |
|
* |
|
* @serial exclude |
|
*/ |
|
|
|
public final class AllPermission extends Permission { |
|
|
|
private static final long serialVersionUID = -2916474571451318075L; |
|
|
|
|
|
|
|
*/ |
|
public AllPermission() { |
|
super("<all permissions>"); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public AllPermission(String name, String actions) { |
|
this(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean implies(Permission p) { |
|
return true; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public boolean equals(Object obj) { |
|
return (obj instanceof AllPermission); |
|
} |
|
|
|
/** |
|
* Returns the hash code value for this object. |
|
* |
|
* @return a hash code value for this object. |
|
*/ |
|
|
|
public int hashCode() { |
|
return 1; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public String getActions() { |
|
return "<all actions>"; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public PermissionCollection newPermissionCollection() { |
|
return new AllPermissionCollection(); |
|
} |
|
|
|
} |
|
|
|
/** |
|
* A AllPermissionCollection stores a collection |
|
* of AllPermission permissions. AllPermission objects |
|
* must be stored in a manner that allows them to be inserted in any |
|
* order, but enable the implies function to evaluate the implies |
|
* method in an efficient (and consistent) manner. |
|
* |
|
* @see java.security.Permission |
|
* @see java.security.Permissions |
|
* |
|
* |
|
* @author Roland Schemers |
|
* |
|
* @serial include |
|
*/ |
|
|
|
final class AllPermissionCollection |
|
extends PermissionCollection |
|
implements java.io.Serializable |
|
{ |
|
|
|
|
|
private static final long serialVersionUID = -4023755556366636806L; |
|
|
|
private boolean all_allowed; |
|
|
|
/** |
|
* Create an empty AllPermissions object. |
|
* |
|
*/ |
|
|
|
public AllPermissionCollection() { |
|
all_allowed = false; |
|
} |
|
|
|
/** |
|
* Adds a permission to the AllPermissions. The key for the hash is |
|
* permission.path. |
|
* |
|
* @param permission the Permission object to add. |
|
* |
|
* @exception IllegalArgumentException - if the permission is not a |
|
* AllPermission |
|
* |
|
* @exception SecurityException - if this AllPermissionCollection object |
|
* has been marked readonly |
|
*/ |
|
|
|
public void add(Permission permission) { |
|
if (! (permission instanceof AllPermission)) |
|
throw new IllegalArgumentException("invalid permission: "+ |
|
permission); |
|
if (isReadOnly()) |
|
throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection"); |
|
|
|
all_allowed = true; |
|
} |
|
|
|
/** |
|
* Check and see if this set of permissions implies the permissions |
|
* expressed in "permission". |
|
* |
|
* @param permission the Permission object to compare |
|
* |
|
* @return always returns true. |
|
*/ |
|
|
|
public boolean implies(Permission permission) { |
|
return all_allowed; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public Enumeration<Permission> elements() { |
|
return new Enumeration<>() { |
|
private boolean hasMore = all_allowed; |
|
|
|
public boolean hasMoreElements() { |
|
return hasMore; |
|
} |
|
|
|
public Permission nextElement() { |
|
hasMore = false; |
|
return SecurityConstants.ALL_PERMISSION; |
|
} |
|
}; |
|
} |
|
} |