References Deprecated
Policy
is deprecated or references (maybe indirectly) at least one deprecated element.
See corresponding docs for further information.
This object stores the policy for the entire Java runtime,
and is the amalgamation of multiple static policy
configurations that resides in files.
The algorithm for locating the policy file(s) and reading their
information into this Policy
object is:
java.security.Security
properties,
and policy.url.1, policy.url.2, ...,
policy.url.X". These properties are set
in the Java security properties file, which is located in the file named
<JAVA_HOME>/conf/security/java.security.
Each property value specifies a URL
pointing to a
policy file to be loaded. Read in and load each policy.
If none of these could be loaded, use a builtin static policy
equivalent to the conf/security/java.policy file.
java.lang.System
property java.security.policy
may also be set to a URL
pointing to another policy file
(which is the case when a user uses the -D switch at runtime).
If this property is defined, and its use is allowed by the
security property file (the Security property,
policy.allowSystemProperty is set to true),
also load that policy.
If the java.security.policy property is defined using
"==" (rather than "="), then load the specified policy file and ignore
all other configured policies. Note, that the default.policy file is
also loaded, as specified in the first step of the algorithm above.
If the specified policy file cannot be loaded, use a builtin static policy
equivalent to the default conf/security/java.policy file.
grant signedBy "alias", codeBase "URL", principal principalClass "principalName", principal principalClass "principalName", ... { permission Type "name "action", signedBy "alias"; permission Type "name "action", signedBy "alias"; .... };All non-bold items above must appear as is (although case doesn't matter and some are optional, as noted below). principal entries are optional and need not be present. Italicized items represent variable values.
A grant entry must begin with the word grant
.
The signedBy
,codeBase
and principal
name/value pairs are optional.
If they are not present, then any signer (including unsigned code)
will match, and any codeBase will match.
Note that the principalClass
may be set to the wildcard value, *, which allows it to match
any Principal
class. In addition, the principalName
may also be set to the wildcard value, *, allowing it to match
any Principal
name. When setting the principalName
to the *, do not surround the * with quotes.
A permission entry must begin with the word permission
.
The word Type
in the template above is
a specific permission type, such as java.io.FilePermission
or java.lang.RuntimePermission
.
The "action" is required for
many permission types, such as java.io.FilePermission
(where it specifies what type of file access that is permitted).
It is not required for categories such as
java.lang.RuntimePermission
where it is not necessary - you either have the
permission specified by the "name"
value following the type name or you don't.
The signedBy
name/value pair for a permission entry
is optional. If present, it indicates a signed permission. That is,
the permission class itself must be signed by the given alias in
order for it to be granted. For example,
suppose you have the following grant entry:
grant principal foo.com.Principal "Duke" { permission Foo "foobar", signedBy "FooSoft"; }
Then this permission of type Foo is granted if the
Foo.class
permission has been signed by the
"FooSoft" alias, or if XXX Foo.class
is a
system class (i.e., is found on the CLASSPATH).
Items that appear in an entry must appear in the specified order
(permission
, Type, "name", and
"action"). An entry is terminated with a semicolon.
Case is unimportant for the identifiers (permission
,
signedBy
, codeBase
, etc.) but is
significant for the Type
or for any string that is passed in as a value.
An example of two entries in a policy configuration file is
// if the code is comes from "foo.com" and is running as "Duke", // grant it read/write to all files in /tmp. grant codeBase "foo.com", principal foo.com.Principal "Duke" { permission java.io.FilePermission "/tmp/*", "read,write"; }; // grant any code running as "Duke" permission to read // the "java.vendor" Property. grant principal foo.com.Principal "Duke" { permission java.util.PropertyPermission "java.vendor";This Policy implementation supports special handling of any permission that contains the string, "${{self}}", as part of its target name. When such a permission is evaluated (such as during a security check), ${{self}} is replaced with one or more Principal class/name pairs. The exact replacement performed depends upon the contents of the grant clause to which the permission belongs.
If the grant clause does not contain any principal information, the permission will be ignored (permissions containing ${{self}} in their target names are only valid in the context of a principal-based grant clause). For example, BarPermission will always be ignored in the following grant clause:
grant codebase "www.foo.com", signedby "duke" { permission BarPermission "... ${{self}} ..."; };If the grant clause contains principal information, ${{self}} will be replaced with that same principal information. For example, ${{self}} in BarPermission will be replaced by javax.security.auth.x500.X500Principal "cn=Duke" in the following grant clause:
grant principal javax.security.auth.x500.X500Principal "cn=Duke" { permission BarPermission "... ${{self}} ..."; };If there is a comma-separated list of principals in the grant clause, then ${{self}} will be replaced by the same comma-separated list or principals. In the case where both the principal class and name are wildcarded in the grant clause, ${{self}} is replaced with all the principals associated with the
Subject
in the current AccessControlContext
.
For PrivateCredentialPermissions, you can also use "self" instead of "${{self}}". However the use of "self" is deprecated in favour of "${{self}}".
java.security.CodeSource
, java.security.Permissions
, java.security.ProtectionDomain
Modifier and Type | Class and Description |
---|---|
private static class | PolicyFile.
Each entry in the policy configuration file is represented by a PolicyEntry object. |
private static class | PolicyFile.
holds policy information that we need to synch on |
private static class |
Modifier and Type | Field and Description |
---|---|
private boolean | |
private static Set | badPolicyURLs
When a policy file has a syntax error, the exception code may generate another permission check and this can cause the policy file to be parsed repeatedly, leading to a StackOverflowError or ClassCircularityError. |
private static final FileSystem | builtInFS
Use the platform's default file system to avoid recursive initialization issues when the VM is configured to use a custom file system provider. |
private static final Debug | |
private static final int | |
private boolean | |
private boolean | |
private static final Class | |
private static final Class | |
private static final Class | |
private static final String | |
private static final String | |
private volatile PolicyFile. | |
private static final String | |
private URL | |
private static final String |
Access | Constructor and Description |
---|---|
public | PolicyFile()
Initializes the Policy object and reads the default policy configuration file(s) into the Policy object. |
public | PolicyFile(URL url)
Initializes the Policy object and reads the default policy from the specified URL only. |
Modifier and Type | Method and Description |
---|---|
private void | addGrantEntry(PolicyParser.
Add one policy entry to the list. |
private void | addPermissions(Permissions perms, final CodeSource cs, Principal[] principals, final PolicyFile.
|
private void | |
private CodeSource | |
private static String | |
private void | |
private void | expandSelf(PolicyFile.
the SelfPermission that needs to be expanded. sp,list of principals for the Policy entry. entryPs,Principal array from the current ProtectionDomain. pdp, Permissions the PermissionCollection where the individual
Permissions will be added after expansion. perms)
|
private Certificate[] | getCertificates(KeyStore keyStore, String aliases, PolicyFile.
Fetch all certs associated with this alias. |
private CodeSource | Returns: null if signedBy alias is not recognizedGiven a GrantEntry, create a codeSource. |
private String | |
private InputStreamReader | |
private static final Permission | getInstance(String
the type of Permission being created. type, String the name of the Permission being created. name, String the actions of the Permission being created. actions)Returns a new Permission object of the given Type. |
private static Permission | getKnownPermission(Class<?> claz, String name, String actions)
Creates one of the well-known permissions in the java.base module directly instead of via reflection. |
private static Principal | getKnownPrincipal(Class<?> claz, String name)
Creates one of the well-known principals in the java.base module directly instead of via reflection. |
public PermissionCollection | Returns: the Permissions granted to the providedProtectionDomain .the Permissions granted to this
domain)ProtectionDomain are returned.Overrides java. Examines this |
public PermissionCollection | Returns: the set of permissions according to the policy.the CodeSource associated with the caller.
This encapsulates the original location of the code (where the code
came from) and the public key(s) of its signer. codesource)Overrides java. Examines this Policy and creates a PermissionCollection object with the set of permissions for the specified CodeSource. |
private PermissionCollection | Returns: the set of Permissions according to the policy.the Permissions to populate perms, ProtectionDomain the ProtectionDomain associated with the caller. pd)Examines the global policy and returns the provided Permissions object with additional permissions granted to the specified ProtectionDomain. |
private PermissionCollection | Returns: the set of permissions according to the policy.the permissions to populate perms, final CodeSource the codesource associated with the caller.
This encapsulates the original location of the code (where the code
came from) and the public key(s) of its signer. cs)Examines the global policy and returns the provided Permissions object with additional permissions granted to the specified CodeSource. |
private Permissions | |
private String[][] | getPrincipalInfo(PolicyParser.
return the principal class/name pair in the 2D array. |
protected Certificate[] | |
public boolean | Returns: true if "permission" is a proper subset of a permission granted to this ProtectionDomain.the ProtectionDomain to test pd, Permission the Permission object to be tested for implication. p)Overrides java. Evaluates the global policy for the permissions granted to the ProtectionDomain and tests whether the permission is granted. |
private void | |
private boolean | init(URL policy, PolicyFile.
Reads a policy configuration into the Policy object using a Reader object. |
private void | |
private void | |
private boolean | |
private void | |
private static URL | |
private String | |
public void | refresh()
Overrides java. Refreshes the policy object by re-reading all the policy files. |
private boolean | replacePrincipals(List<PolicyParser.
return true if no replacement was performed, or if replacement succeeded. |
private static boolean | wildcardPrincipalNameImplies(String principalClass, Principal[] principals)
Returns true if the array of principals contains at least one principal of the specified class. |
allowSystemProperties | back to summary |
---|---|
private boolean allowSystemProperties |
badPolicyURLs | back to summary |
---|---|
private static Set<URL> badPolicyURLs When a policy file has a syntax error, the exception code may generate another permission check and this can cause the policy file to be parsed repeatedly, leading to a StackOverflowError or ClassCircularityError. To avoid this, this set is populated with policy files that have been previously parsed and have syntax errors, so that they can be subsequently ignored. |
builtInFS | back to summary |
---|---|
private static final FileSystem builtInFS Use the platform's default file system to avoid recursive initialization issues when the VM is configured to use a custom file system provider. |
debug | back to summary |
---|---|
private static final Debug debug Hides java. |
DEFAULT_CACHE_SIZE | back to summary |
---|---|
private static final int DEFAULT_CACHE_SIZE |
expandProperties | back to summary |
---|---|
private boolean expandProperties |
notUtf8 | back to summary |
---|---|
private boolean notUtf8 |
PARAMS0 | back to summary |
---|---|
private static final Class<?>[] PARAMS0 |
PARAMS1 | back to summary |
---|---|
private static final Class<?>[] PARAMS1 |
PARAMS2 | back to summary |
---|---|
private static final Class<?>[] PARAMS2 |
POLICY | back to summary |
---|---|
private static final String POLICY |
POLICY_URL | back to summary |
---|---|
private static final String POLICY_URL |
policyInfo | back to summary |
---|---|
private volatile PolicyFile. |
SELF | back to summary |
---|---|
private static final String SELF |
url | back to summary |
---|---|
private URL url |
X500PRINCIPAL | back to summary |
---|---|
private static final String X500PRINCIPAL |
PolicyFile | back to summary |
---|---|
public PolicyFile() Initializes the Policy object and reads the default policy configuration file(s) into the Policy object. |
PolicyFile | back to summary |
---|---|
public PolicyFile(URL url) Initializes the Policy object and reads the default policy from the specified URL only. |
addGrantEntry | back to summary |
---|---|
private void addGrantEntry(PolicyParser. Add one policy entry to the list. |
addPermissions | back to summary |
---|---|
private void addPermissions(Permissions perms, final CodeSource cs, Principal[] principals, final PolicyFile. |
addPerms | back to summary |
---|---|
private void addPerms(Permissions perms, Principal[] accPs, PolicyFile. |
canonicalizeCodebase | back to summary |
---|---|
private CodeSource canonicalizeCodebase(CodeSource cs, boolean extractSignerCerts) |
canonPath | back to summary |
---|---|
private static String canonPath(String path) throws IOException |
expandPermissionName | back to summary |
---|---|
private void expandPermissionName(PolicyParser. |
expandSelf | back to summary |
---|---|
private void expandSelf(PolicyFile.
|
getCertificates | back to summary |
---|---|
private Certificate[] getCertificates(KeyStore keyStore, String aliases, PolicyFile. Fetch all certs associated with this alias. |
getCodeSource | back to summary |
---|---|
private CodeSource getCodeSource(PolicyParser. Given a GrantEntry, create a codeSource.
|
getDN | back to summary |
---|---|
private String getDN(String alias, KeyStore keystore) |
getInputStreamReader | back to summary |
---|---|
private InputStreamReader getInputStreamReader(InputStream is) |
getInstance | back to summary |
---|---|
private static final Permission getInstance(String type, String name, String actions) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException Returns a new Permission object of the given Type. The Permission is
created by getting the
Class object using the
|
getKnownPermission | back to summary |
---|---|
private static Permission getKnownPermission(Class<?> claz, String name, String actions) Creates one of the well-known permissions in the java.base module directly instead of via reflection. Keep list short to not penalize permissions from other modules. |
getKnownPrincipal | back to summary |
---|---|
private static Principal getKnownPrincipal(Class<?> claz, String name) Creates one of the well-known principals in the java.base module directly instead of via reflection. Keep list short to not penalize principals from other modules. |
getPermissions | back to summary |
---|---|
public PermissionCollection getPermissions(ProtectionDomain domain) Overrides java. Examines this Note that this
|
getPermissions | back to summary |
---|---|
public PermissionCollection getPermissions(CodeSource codesource) Overrides java. Examines this Policy and creates a PermissionCollection object with the set of permissions for the specified CodeSource.
|
getPermissions | back to summary |
---|---|
private PermissionCollection getPermissions(Permissions perms, ProtectionDomain pd) Examines the global policy and returns the provided Permissions object with additional permissions granted to the specified ProtectionDomain.
|
getPermissions | back to summary |
---|---|
private PermissionCollection getPermissions(Permissions perms, final CodeSource cs) Examines the global policy and returns the provided Permissions object with additional permissions granted to the specified CodeSource.
|
getPermissions | back to summary |
---|---|
private Permissions getPermissions(Permissions perms, final CodeSource cs, Principal[] principals) |
getPrincipalInfo | back to summary |
---|---|
private String[][] getPrincipalInfo(PolicyParser. return the principal class/name pair in the 2D array. array[x][y]: x corresponds to the array length. if (y == 0), it's the principal class. if (y == 1), it's the principal name. |
getSignerCertificates | back to summary |
---|---|
protected Certificate[] getSignerCertificates(CodeSource cs) |
implies | back to summary |
---|---|
public boolean implies(ProtectionDomain pd, Permission p) Overrides java. Evaluates the global policy for the permissions granted to the ProtectionDomain and tests whether the permission is granted.
|
init | back to summary |
---|---|
private void init(URL url) Initializes the Policy object and reads the default policy configuration file(s) into the Policy object. See the class description for details on the algorithm used to initialize the Policy object. |
init | back to summary |
---|---|
private boolean init(URL policy, PolicyFile. Reads a policy configuration into the Policy object using a Reader object. |
initDefaultPolicy | back to summary |
---|---|
private void initDefaultPolicy(PolicyFile. |
initPolicyFile | back to summary |
---|---|
private void initPolicyFile(final PolicyFile. |
initPolicyFile | back to summary |
---|---|
private boolean initPolicyFile(final String propname, final String urlname, final PolicyFile. |
initStaticPolicy | back to summary |
---|---|
private void initStaticPolicy(final PolicyFile. |
newURL | back to summary |
---|---|
private static URL newURL(String spec) throws MalformedURLException
|
printPD | back to summary |
---|---|
private String printPD(ProtectionDomain pd) |
refresh | back to summary |
---|---|
public void refresh() Overrides java. Refreshes the policy object by re-reading all the policy files.
|
replacePrincipals | back to summary |
---|---|
private boolean replacePrincipals(List<PolicyParser. return true if no replacement was performed, or if replacement succeeded. |
wildcardPrincipalNameImplies | back to summary |
---|---|
private static boolean wildcardPrincipalNameImplies(String principalClass, Principal[] principals) Returns true if the array of principals contains at least one principal of the specified class. |
A PolicyEntry is a (CodeSource,Permission) pair. The CodeSource contains the (URL, PublicKey) that together identify where the Java bytecodes come from and who (if anyone) signed them. The URL could refer to localhost. The URL could also be null, meaning that this policy entry is given to all comers, as long as they match the signer field. The signer could be null, meaning the code is not signed.
The Permission contains the (Type, Name, Action) triplet.
For now, the Policy object retrieves the public key from the X.509 certificate on disk that corresponds to the signedBy alias specified in the Policy config file. For reasons of efficiency, the Policy object keeps a hashtable of certs already read in. This could be replaced by a secure internal key store.
For example, the entry
permission java.io.File "/tmp", "read,write", signedBy "Duke";is represented internally
FilePermission f = new FilePermission("/tmp", "read,write"); PublicKey p = publickeys.get("Duke"); URL u = InetAddress.getLocalHost(); CodeBase c = new CodeBase( p, u ); pe = new PolicyEntry(f, c);
java.security.CodeSource
, java.security.Policy
, java.security.Permissions
, java.security.ProtectionDomain
Modifier and Type | Field and Description |
---|---|
private final CodeSource | |
pack-priv final List | |
private final List |
Access | Constructor and Description |
---|---|
pack-priv | PolicyEntry(CodeSource
the CodeSource, which encapsulates the URL and the
public key
attributes from the policy config file. Validity checks
are performed on the public key before PolicyEntry is
called. cs, List<PolicyParser.Given a Permission and a CodeSource, create a policy entry. |
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv void | |
pack-priv CodeSource | |
pack-priv List | |
public String |
codesource | back to summary |
---|---|
private final CodeSource codesource |
permissions | back to summary |
---|---|
pack-priv final List<Permission> permissions |
principals | back to summary |
---|---|
private final List<PolicyParser. |
PolicyEntry | back to summary |
---|---|
pack-priv PolicyEntry(CodeSource cs, List<PolicyParser. Given a Permission and a CodeSource, create a policy entry. XXX Decide if/how to add validity fields and "purpose" fields to XXX policy entries
|
PolicyEntry | back to summary |
---|---|
pack-priv PolicyEntry(CodeSource cs) |
add | back to summary |
---|---|
pack-priv void add(Permission p) add a Permission object to this entry. No need to sync add op because perms are added to entry only while entry is being initialized |
getCodeSource | back to summary |
---|---|
pack-priv CodeSource getCodeSource() Return the CodeSource for this policy entry |
getPrincipals | back to summary |
---|---|
pack-priv List |
toString | back to summary |
---|---|
public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- |
Modifier and Type | Field and Description |
---|---|
pack-priv final Map | |
private final JavaSecurityAccess. | |
pack-priv final List | |
private Random | |
private static final boolean |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv JavaSecurityAccess. |
aliasMapping | back to summary |
---|---|
pack-priv final Map<Object, Object> aliasMapping |
pdMapping | back to summary |
---|---|
private final JavaSecurityAccess. |
policyEntries | back to summary |
---|---|
pack-priv final List<PolicyFile. |
random | back to summary |
---|---|
private Random random |
verbose | back to summary |
---|---|
private static final boolean verbose |
PolicyInfo | back to summary |
---|---|
pack-priv PolicyInfo(int numCaches) |
getPdMapping | back to summary |
---|---|
pack-priv JavaSecurityAccess. |
Modifier and Type | Field and Description |
---|---|
private String | actions
The actions of the permission. |
private Certificate[] | certs
The certs of the permission. |
private String | name
The permission name.
|
private static final long | |
private String | type
The class name of the Permission class that will be created when this self permission is expanded . |
Access | Constructor and Description |
---|---|
public | SelfPermission(String
the class name of the Permission class that will be
created when this permission is expanded and if necessary resolved. type, String the name of the permission. name, String the actions of the permission. actions, Certificate[] the certificates the permission's class was signed with.
This is a list of certificate chains, where each chain is composed of
a signer certificate and optionally its supporting certificate chain.
Each chain is ordered bottom-to-top (i.e., with the signer
certificate first and the (root) certificate authority last). certs)Creates a new SelfPermission containing the permission information needed later to expand the self |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if obj is an SelfPermission, and has the same type (class) name, permission name, actions, and certificates as this object.the object we are testing for equality with this object. obj)Implements abstract java. Checks two SelfPermission objects for equality. |
public String | Returns: the empty string "".Implements abstract java. Returns the canonical string representation of the actions, which currently is the empty string "", since there are no actions for an SelfPermission. |
public Certificate[] | |
public String | |
public String | |
public String | |
public int | Returns: the hash code value for this objectImplements abstract java. Returns the hash code value for this object. |
public boolean | Returns: false.the permission to check against. p)Implements abstract java. This method always returns false for SelfPermission permissions. |
private void | readObject(ObjectInputStream
the stream)ObjectInputStream from which data is readRestores the state of this object from the stream. |
public String | Returns: information about this SelfPermission.Overrides java. Returns a string describing this SelfPermission. |
actions | back to summary |
---|---|
private String actions The actions of the permission. |
certs | back to summary |
---|---|
private Certificate[] certs The certs of the permission. |
name | back to summary |
---|---|
private String name Hides java. The permission name. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. |
type | back to summary |
---|---|
private String type The class name of the Permission class that will be created when this self permission is expanded . |
SelfPermission | back to summary |
---|---|
public SelfPermission(String type, String name, String actions, Certificate[] certs) Creates a new SelfPermission containing the permission information needed later to expand the self
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Implements abstract java. Checks two SelfPermission objects for equality. Checks that obj is an SelfPermission, and has the same type (class) name, permission name, actions, and certificates as this object. |
getActions | back to summary |
---|---|
public String getActions() Implements abstract java. Returns the canonical string representation of the actions, which currently is the empty string "", since there are no actions for an SelfPermission. That is, the actions for the permission that will be created when this SelfPermission is resolved may be non-null, but an SelfPermission itself is never considered to have any actions. |
getCerts | back to summary |
---|---|
public Certificate[] getCerts() |
getSelfActions | back to summary |
---|---|
public String getSelfActions() |
getSelfName | back to summary |
---|---|
public String getSelfName() |
getSelfType | back to summary |
---|---|
public String getSelfType() |
hashCode | back to summary |
---|---|
public int hashCode() Implements abstract java. Returns the hash code value for this object.
|
implies | back to summary |
---|---|
public boolean implies(Permission p) Implements abstract java. This method always returns false for SelfPermission permissions. That is, an SelfPermission never considered to imply another permission.
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException Restores the state of this object from the stream.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a string describing this SelfPermission. The convention is to specify the class name, the permission name, and the actions, in the following format: '(unresolved "ClassName" "name" "actions")'. |