- java.lang.Object
-
- javax.security.auth.Policy
-
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.
@Deprecated public abstract class Policy extends Object
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
Policy.A
Policyobject can be queried for the set of Permissions granted to code running as aPrincipalin the following manner:policy = Policy.getPolicy(); PermissionCollection perms = policy.getPermissions(subject, codeSource);ThePolicyobject consults the local policy and returns and appropriatePermissionsobject with the Permissions granted to the Principals associated with the provided subject, and granted to the code specified by the provided codeSource.A
Policycontains the following information. Note that this example only represents the syntax for the defaultPolicyimplementation. Subclass implementations of this class may implement alternative syntaxes and may retrieve thePolicyfrom any source such as files, databases, or servers.Each entry in the
Policyis represented as a 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 aSolarisPrincipalwith the name, duke, has onePermission. ThisPermissionpermits the executing code to read and write files in the directory, "/home/duke".To "run" as a particular
Principal, code invokes theSubject.doAs(subject, ...)method. After invoking that method, the code runs as all the Principals associated with the specifiedSubject. Note that thisPolicy(and the Permissions granted in thisPolicy) only become effective after the call toSubject.doAshas occurred.Multiple Principals may be listed within one grant entry. All the Principals in the grant entry must be associated with the
Subjectprovided toSubject.doAsfor thatSubjectto 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
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 thejava.security.Policy.The default
Policyimplementation can be changed by setting the value of the "auth.policy.provider" security property (in the Java security properties file) to the fully qualified name of the desiredPolicyimplementation class. The Java security properties file is located in the file named <JAVA_HOME>/lib/security/java.security. <JAVA_HOME> refers to the value of the java.home system property, and specifies the directory where the JRE is installed.
-
-
Constructor Summary
Constructors Modifier Constructor and Description protectedPolicy()Deprecated.Sole constructor.
-
Method Summary
Methods Modifier and Type Method and Description abstract PermissionCollectiongetPermissions(Subject subject, CodeSource cs)Deprecated.Retrieve the Permissions granted to the Principals associated with the specifiedCodeSource.static PolicygetPolicy()Deprecated.Returns the installed Policy object.abstract voidrefresh()Deprecated.Refresh and reload the Policy.static voidsetPolicy(Policy policy)Deprecated.Sets the system-wide Policy object.
-
-
-
Constructor Detail
-
Policy
protected Policy()
Deprecated.Sole constructor. (For invocation by subclass constructors, typically implicit.)
-
-
Method Detail
-
getPolicy
public static Policy getPolicy()
Deprecated.Returns the installed Policy object. This method first callsSecurityManager.checkPermissionwith theAuthPermission("getPolicy")permission to ensure the caller has permission to get the Policy object.- Returns:
- the installed Policy. The return value cannot be
null. - Throws:
SecurityException- if the current thread does not have permission to get the Policy object.- See Also:
setPolicy(javax.security.auth.Policy)
-
setPolicy
public static void setPolicy(Policy policy)
Deprecated.Sets the system-wide Policy object. This method first callsSecurityManager.checkPermissionwith theAuthPermission("setPolicy")permission to ensure the caller has permission to set the Policy.- Parameters:
policy- the new system Policy object.- Throws:
SecurityException- if the current thread does not have permission to set the Policy.- See Also:
getPolicy()
-
getPermissions
public abstract PermissionCollection getPermissions(Subject subject, CodeSource cs)
Deprecated.Retrieve the Permissions granted to the Principals associated with the specifiedCodeSource.- Parameters:
subject- theSubjectwhose associated Principals, in conjunction with the providedCodeSource, determines the Permissions returned by this method. This parameter may benull.cs- the code specified by itsCodeSourcethat determines, in conjunction with the providedSubject, the Permissions returned by this method. This parameter may benull.- Returns:
- the Collection of Permissions granted to all the
Subjectand code specified in the provided subject and cs parameters.
-
refresh
public abstract void refresh()
Deprecated.Refresh and reload the Policy.This method causes this object to refresh/reload its current Policy. This is implementation-dependent. For example, if the Policy object is stored in a file, calling
refreshwill cause the file to be re-read.- Throws:
SecurityException- if the caller does not have permission to refresh the Policy.
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/security/auth/Policy.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.