This is an abstract class for representing the system policy for Subject-based authorization. A subclass implementation of this class provides a means to specify a Subject-based access control {@code Policy}.
A {@code Policy} object can be queried for the set ofPermissions granted to code running as a {@code Principal} in the following manner:
policy = Policy.getPolicy(); PermissionCollection perms = policy.getPermissions(subject, codeSource);The {@code Policy} object consults the local policy and returnsand appropriate {@code Permissions} object with thePermissions granted to the Principals associated with the provided subject, and granted to the code specified by the provided codeSource.
A {@code Policy} contains the following information.Note that this example only represents the syntax for the default {@code Policy} implementation. Subclass implementations of this classmay implement alternative syntaxes and may retrieve the {@code Policy} from any source such as files, databases,or servers.
Each entry in the {@code Policy} is represented asa grant entry. Each grant entry specifies a codebase, code signers, and Principals triplet, as well as the Permissions granted to that triplet.
grant CodeBase ["URL"], Signedby ["signers"], Principal [Principal_Class] "Principal_Name" { Permission Permission_Class ["Target_Name"] [, "Permission_Actions"] [, signedBy "SignerName"]; };The CodeBase and Signedby components of the triplet name/value pairs are optional. If they are not present, then any any codebase will match, and any signer (including unsigned code) will match. For Example,
grant CodeBase "foo.com", Signedby "foo", Principal com.sun.security.auth.SolarisPrincipal "duke" { permission java.io.FilePermission "/home/duke", "read, write"; };This grant entry specifies that code from "foo.com", signed by "foo', and running as a {@code SolarisPrincipal} with thename, duke, has one {@code Permission}. This {@code Permission}permits the executing code to read and write files in the directory, "/home/duke".
To "run" as a particular {@code Principal}, code invokes the {@code Subject.doAs(subject, ...)} method.After invoking that method, the code runs as all the Principals associated with the specified {@code Subject}. Note that this {@code Policy} (and the Permissionsgranted in this {@code Policy}) only become effective after the call to {@code Subject.doAs} has occurred.
Multiple Principals may be listed within one grant entry. All the Principals in the grant entry must be associated with the {@code Subject} provided to {@code Subject.doAs}for that {@code Subject} to be granted the specified Permissions.
grant Principal com.sun.security.auth.SolarisPrincipal "duke", Principal com.sun.security.auth.SolarisNumericUserPrincipal "0" { permission java.io.FilePermission "/home/duke", "read, write"; permission java.net.SocketPermission "duke.com", "connect"; };This entry grants any code running as both "duke" and "0" permission to read and write files in duke's home directory, as well as permission to make socket connections to "duke.com".
Note that non Principal-based grant entries are not permitted in this {@code Policy}. Therefore, grant entries such as:
grant CodeBase "foo.com", Signedby "foo" { permission java.io.FilePermission "/tmp/scratch", "read, write"; };are rejected. Such permission must be listed in the {@code java.security.Policy}.
The default {@code Policy} implementation can be changed bysetting the value of the {@code auth.policy.provider} security property tothe fully qualified name of the desired {@code Policy} implementation class. @deprecated as of JDK version 1.4 -- Replaced by java.security.Policy.java.security.Policy has a method:
public PermissionCollection getPermissions (java.security.ProtectionDomain pd)and ProtectionDomain has a constructor:
public ProtectionDomain (CodeSource cs, PermissionCollection permissions, ClassLoader loader, Principal[] principals)These two APIs provide callers the means to query the Policy for Principal-based Permission entries. @see java.security.Security security properties
|
|