TopBlend: Here is the first difference. There are 30 differences. is old. is new.

java.security
Class Policy


java.lang.Object
  extended by java.security.Policy

public abstract class Policy
extends Object

A Policy object is responsible for determining whether code executing in the Java runtime environment has permission to perform a security-sensitive operation. This is an abstract class for representing the system security policy for a Java application environment (specifying which permissions are available for code from various sources). That is, the security policy is represented by a Policy subclass providing an implementation of the abstract methods in this Policy class.

There is only one Policy object installed in the runtime at any given time. A Policy object can be installed by calling the setPolicy method. The installed Policy object can be obtained by calling the getPolicy method. There is only one Policy object in effect at any given time.

If no Policy object has been installed in the runtime, a call to getPolicy installs an instance of the default Policy implementation (a default subclass implementation of this abstract class). The default Policy implementation can be changed by setting the value of the "policy.provider" security property (in the Java security properties file) to the fully qualified name of the desired Policy subclass implementation. 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. The source location for the policy information utilized by the Policy object is up to the Policy implementation. The policy configuration may be stored, for example, as a flat ASCII file, as a serialized binary file of the Policy class, or as a database.

Application code can directly subclass Policy to provide a custom implementation. In addition, an instance of a Policy object can be constructed by invoking one of the getInstance factory methods with a standard type. The default policy type is "JavaPolicy". See Appendix A in the Java Cryptography Architecture API Specification & Reference for a list of standard Policy types. The currently-installed Policy object can be obtained by calling the getPolicy method, and it can be changed by a call to the setPolicy method (by code with permission to reset the Policy).

Once a Policy instance has been installed (either by default, or by calling setPolicy), the Java runtime invokes its implies when it needs to determine whether executing code (encapsulated in a ProtectionDomain) can perform SecurityManager-protected operations. How a Policy object retrieves its policy data is up to the Policy implementation itself. The policy data may be stored, for example, in a flat ASCII file, in a serialized binary file of the Policy class, or in a database. The refresh method causes the policy object to refresh/reload its current configuration.

The refresh method causes the policy object to refresh/reload its data. This operation is implementation-dependent. For example, if the policy object stores its data policy in configuration files, calling refresh will cause it to re-read the configuration policy files. If a refresh operation is not supported, this method does nothing. Note that The refreshed policy may not have an effect on classes in a particular ProtectionDomain. This is dependent on the Policy provider's implementation of the implies implies method and its the PermissionCollection caching strategy.

The default Policy implementation can be changed by setting the value of the "policy.provider" security property (in the Java security properties file) to the fully qualified name of the desired Policy implementation class. The Java security properties file is located in the file named <JAVA_HOME>/lib/security/java.security, where <JAVA_HOME> refers to the directory where the JDK was installed.

See Also:
Provider CodeSource , ProtectionDomain PermissionCollection , Permission SecureClassLoader

Nested Class Summary
static interface Policy.Parameters
          This represents a marker interface for Policy parameters.
 
Field Summary
static  PermissionCollection UNSUPPORTED_EMPTY_COLLECTION
          A read-only empty PermissionCollection instance.
 
Constructor Summary
Policy ()
           
 
Method Summary
static  Policy abstract   PermissionCollection getInstance getPermissions ( String CodeSource  type, Policy.Parameters
          Returns           Evaluates the global policy and returns a Policy PermissionCollection object specifying the set of permissions allowed for code from the specified type. code source.
static  Policy getInstance ( String  type, Policy.Parameters  params, Provider
          Returns a Policy object of the specified type.
  PermissionCollection getPermissions ( ProtectionDomain
          Evaluates the global policy and returns a PermissionCollection object specifying the set of permissions allowed given the characteristics of the protection domain.
static  Policy getInstance ( String  type, Policy.Parameters  params, String
          Returns a Policy object of the specified type.
  Policy.Parameters getParameters ()
          Return Policy parameters.
  PermissionCollection getPermissions ( CodeSource
          Return a PermissionCollection object containing the set of permissions granted to the specified CodeSource.
  PermissionCollection getPermissions ( ProtectionDomain
          Return a PermissionCollection object containing the set of permissions granted to the specified ProtectionDomain.
static  Policy getPolicy ()
          Returns the installed Policy object.
  Provider getProvider ()
          Return the Provider of this Policy.
  String getType ()
          Return the type of this Policy.
 boolean implies ( ProtectionDomain  domain, Permission  permission)
          Evaluates the global policy for the permissions granted to the ProtectionDomain and tests whether the permission is granted.
abstract  void refresh ()
          Refreshes/reloads the policy configuration.
static void setPolicy ( Policy  p)
          Sets the system-wide Policy object.
 
Methods inherited from class java.lang. Object
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait
 

Field Detail

UNSUPPORTED_EMPTY_COLLECTION


 
public static final PermissionCollectionUNSUPPORTED_EMPTY_COLLECTION 
A read-only empty PermissionCollection instance.

Constructor Detail

Policy


public Policy()
Method Detail

getPolicy


public static Policy getPolicy()
Returns the installed Policy object. This value should not be cached, as it may be changed by a call to setPolicy. This method first calls SecurityManager.checkPermission with a SecurityPermission("getPolicy") permission to ensure it's ok to get the Policy object..

Returns:
the installed Policy.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow getting the Policy object.
See Also:
SecurityManager.checkPermission(Permission) , setPolicy(java.security.Policy)

setPolicy


public static void setPolicy(Policy p)
Sets the system-wide Policy object. This method first calls SecurityManager.checkPermission with a SecurityPermission("setPolicy") permission to ensure it's ok to set the Policy.

Parameters:
p - the new system Policy object.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow setting the Policy.
See Also:
SecurityManager.checkPermission(Permission) , getPolicy()

getInstance


 
public static PolicygetInstance ( String type,
 Policy.Parameters params)
 throws NoSuchAlgorithmException
Returns a Policy object of the specified type.

This method traverses the list of registered security providers, starting with the most preferred Provider. A new Policy object encapsulating the PolicySpi implementation from the first Provider that supports the specified type is returned.

Note that the list of registered providers may be retrieved via the Security.getProviders() method.

Parameters:
type - the specified Policy type. See Appendix A in the Java Cryptography Architecture API Specification & Reference for a list of standard Policy types.
params - parameters for the Policy, which may be null.
Returns:
the new Policy object.
Throws:
SecurityException - if the caller does not have permission to get a Policy instance for the specified type.
NullPointerException - if the specified type is null.
IllegalArgumentException - if the specified parameters are not understood by the PolicySpi implementation from the selected Provider.
NoSuchAlgorithmException - if no Provider supports a PolicySpi implementation for the specified type.
Since:
1.6
See Also:
Provider

getInstance


 
public static PolicygetInstance ( String type,
 Policy.Parameters params,
 String provider)
 throws NoSuchProviderException,
 NoSuchAlgorithmException
Returns a Policy object of the specified type.

A new Policy object encapsulating the PolicySpi implementation from the specified provider is returned. The specified provider must be registered in the provider list.

Note that the list of registered providers may be retrieved via the Security.getProviders() method.

Parameters:
type - the specified Policy type. See Appendix A in the Java Cryptography Architecture API Specification & Reference for a list of standard Policy types.
params - parameters for the Policy, which may be null.
provider - the provider.
Returns:
the new Policy object.
Throws:
SecurityException - if the caller does not have permission to get a Policy instance for the specified type.
NullPointerException - if the specified type is null.
IllegalArgumentException - if the specified provider is null or empty, or if the specified parameters are not understood by the PolicySpi implementation from the specified provider.
NoSuchProviderException - if the specified provider is not registered in the security provider list.
NoSuchAlgorithmException - if the specified provider does not support a PolicySpi implementation for the specified type.
Since:
1.6
See Also:
Provider

getInstance


 
public static PolicygetInstance ( String type,
 Policy.Parameters params,
 Provider provider)
 throws NoSuchAlgorithmException
Returns a Policy object of the specified type.

A new Policy object encapsulating the PolicySpi implementation from the specified Provider object is returned. Note that the specified Provider object does not have to be registered in the provider list.

Parameters:
type - the specified Policy type. See Appendix A in the Java Cryptography Architecture API Specification & Reference for a list of standard Policy types.
params - parameters for the Policy, which may be null.
provider - the Provider.
Returns:
the new Policy object.
Throws:
SecurityException - if the caller does not have permission to get a Policy instance for the specified type.
NullPointerException - if the specified type is null.
IllegalArgumentException - if the specified Provider is null, or if the specified parameters are not understood by the PolicySpi implementation from the specified Provider.
NoSuchAlgorithmException - if the specified Provider does not support a PolicySpi implementation for the specified type.
Since:
1.6
See Also:
Provider

getProvider


 
public ProvidergetProvider () 
Return the Provider of this Policy.

This Policy instance will only have a Provider if it was obtained via a call to Policy.getInstance. Otherwise this method returns null.

Returns:
the Provider of this Policy, or null.
Since:
1.6

getType


 
public StringgetType () 
Return the type of this Policy.

This Policy instance will only have a type if it was obtained via a call to Policy.getInstance. Otherwise this method returns null.

Returns:
the type of this Policy, or null.
Since:
1.6

getParameters


 
public Policy.ParametersgetParameters () 
Return Policy parameters.

This Policy instance will only have parameters if it was obtained via a call to Policy.getInstance. Otherwise this method returns null.

Returns:
Policy parameters, or null.
Since:
1.6

getPermissions


public abstract PermissionCollectiongetPermissions(CodeSource codesource)
Return Evaluates the global policy and returns a PermissionCollection object containing specifying the set of permissions granted to allowed for code from the specified CodeSource. code source.

Applications are discouraged from calling this method since this operation may not be supported by all policy implementations. Applications should solely rely on the implies method to perform policy checks. If an application absolutely must call a getPermissions method, it should call getPermissions(ProtectionDomain).

The default implementation of this method returns Policy.UNSUPPORTED_EMPTY_COLLECTION. This method can be overridden if the policy implementation can return a set of permissions granted to a CodeSource.

Parameters:
codesource - the CodeSource to which the returned PermissionCollection has been granted. 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.
Returns:
a the set of permissions granted allowed for code from codesource according to the specified CodeSource. If this operation is supported, the policy.The returned set of permissions must be a new mutable instance and it must support heterogeneous Permission types. If this operation is not supported, Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.

getPermissions


public PermissionCollection getPermissions(ProtectionDomain domain)
Return a PermissionCollection object containing the set of permissions granted to the specified ProtectionDomain. Evaluates the global policy and returns a PermissionCollection object specifying the set of permissions allowed given the characteristics of the protection domain.

Applications are discouraged from calling this method since this operation may not be supported by all policy implementations. Applications should rely on the implies method to perform policy checks.

The default implementation of this method first retrieves the permissions returned via getPermissions(CodeSource) (the CodeSource is taken from the specified ProtectionDomain), as well as the permissions located inside the specified ProtectionDomain. All of these permissions are then combined and returned in a new PermissionCollection object. If getPermissions(CodeSource) returns Policy.UNSUPPORTED_EMPTY_COLLECTION, then this method returns the permissions contained inside the specified ProtectionDomain in a new PermissionCollection object.

This method can be overridden if the policy implementation supports returning a set of permissions granted to a ProtectionDomain.

Parameters:
domain - the ProtectionDomain to which associated with the returned PermissionCollection has been granted. caller.
Returns:
a the set of permissions granted allowed for the domain according to the specified ProtectionDomain. If this operation is supported, the policy.The returned set of permissions must be a new mutable instance and it must support heterogeneous Permission types. If this operation is not supported, Policy.UNSUPPORTED_EMPTY_COLLECTION is returned.
Since:
1.4
See Also:
ProtectionDomain , SecureClassLoader

implies


public boolean implies(ProtectionDomain domain,
                       Permission permission)
Evaluates the global policy for the permissions granted to the ProtectionDomain and tests whether the permission is granted.

Parameters:
domain - the ProtectionDomain to test
permission - the Permission object to be tested for implication.
Returns:
true if "permission" is a proper subset of a permission granted to this ProtectionDomain.
Since:
1.4
See Also:
ProtectionDomain

refresh


public abstract void refresh()
Refreshes/reloads the policy configuration. The behavior of this method depends on the implementation. For example, calling refresh on a file-based policy will cause the file to be re-read.

The default implementation of this method does nothing. This method should be overridden if a refresh operation is supported by the policy implementation.