public abstract class

Policy

extends Object
java.lang.Object
   ↳ java.security.Policy

Class Overview

Policy is the common super type of classes which represent a system security policy. The Policy specifies which permissions apply to which code sources.

The system policy can be changed by setting the 'policy.provider' property in the file named JAVA_HOME/lib/security/java.security to the fully qualified class name of the desired Policy.

Only one instance of a Policy is active at any time.

Summary

Public Constructors
Policy()
Public Methods
abstract PermissionCollection getPermissions(CodeSource cs)
Returns a PermissionCollection describing what permissions are allowed for the specified CodeSource based on the current security policy.
PermissionCollection getPermissions(ProtectionDomain domain)
Returns a PermissionCollection describing what permissions are allowed for the specified ProtectionDomain (more specifically, its CodeSource) based on the current security policy.
static Policy getPolicy()
Returns the current system security policy.
boolean implies(ProtectionDomain domain, Permission permission)
Indicates whether the specified Permission is implied by the PermissionCollection of the specified ProtectionDomain.
abstract void refresh()
Reloads the policy configuration for this Policy instance.
static void setPolicy(Policy policy)
Sets the system wide policy.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Policy ()

Since: API Level 1

Public Methods

public abstract PermissionCollection getPermissions (CodeSource cs)

Since: API Level 1

Returns a PermissionCollection describing what permissions are allowed for the specified CodeSource based on the current security policy.

Note that this method is not called for classes which are in the system domain (i.e. system classes). System classes are always given full permissions (i.e. AllPermission). This can not be changed by installing a new policy.

Parameters
cs the CodeSource to compute the permissions for.
Returns
  • the permissions that are granted to the specified CodeSource.

public PermissionCollection getPermissions (ProtectionDomain domain)

Since: API Level 1

Returns a PermissionCollection describing what permissions are allowed for the specified ProtectionDomain (more specifically, its CodeSource) based on the current security policy.

Note that this method is not< called for classes which are in the system domain (i.e. system classes). System classes are always given full permissions (i.e. AllPermission). This can not be changed by installing a new policy.

Parameters
domain the ProtectionDomain to compute the permissions for.
Returns
  • the permissions that are granted to the specified CodeSource.

public static Policy getPolicy ()

Since: API Level 1

Returns the current system security policy. If no policy has been instantiated then this is done using the security property "policy.provider".

If a SecurityManager is installed, code calling this method needs the SecurityPermission getPolicy to be granted, otherwise a SecurityException will be thrown.

Returns
  • the current system security policy.
Throws
SecurityException if a SecurityManager is installed and the caller does not have permission to invoke this method.

public boolean implies (ProtectionDomain domain, Permission permission)

Since: API Level 1

Indicates whether the specified Permission is implied by the PermissionCollection of the specified ProtectionDomain.

Parameters
domain the ProtectionDomain for which the permission should be granted.
permission the Permission for which authorization is to be verified.
Returns
  • true if the Permission is implied by the ProtectionDomain, false otherwise.

public abstract void refresh ()

Since: API Level 1

Reloads the policy configuration for this Policy instance.

public static void setPolicy (Policy policy)

Since: API Level 1

Sets the system wide policy.

If a SecurityManager is installed, code calling this method needs the SecurityPermission setPolicy to be granted, otherwise a SecurityException will be thrown.

Parameters
policy the Policy to set.
Throws
SecurityException if a SecurityManager is installed and the caller does not have permission to invoke this method.