APIdia Launch Partner
Top Description Fields Constructors Methods
java.security

public Class ProtectionDomain

extends Object
Class Inheritance

The ProtectionDomain class encapsulates the characteristics of a domain, which encloses a set of classes whose instances are granted a set of permissions.

A static set of permissions can be bound to a ProtectionDomain when it is constructed; such permissions are granted to the domain regardless of the policy in force. However, to support dynamic security policies, a ProtectionDomain can also be constructed such that it is dynamically mapped to a set of permissions by the current policy.

API Note

Installing a system-wide Policy object is no longer supported. The current policy is always a Policy object that grants no permissions.

Authors
Li Gong, Roland Schemers, Gary Ellison
Since
1.2

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final CodeSource
private boolean
private PermissionCollection
private final Principal[]
private final boolean

Constructor Summary

AccessConstructor and Description
public
ProtectionDomain(CodeSource
the codesource associated with this domain
codesource
,
PermissionCollection
the permissions granted to this domain
permissions
)

Creates a new ProtectionDomain with the given CodeSource and permissions.

public
ProtectionDomain(CodeSource
the CodeSource associated with this domain
codesource
,
PermissionCollection
the permissions granted to this domain
permissions
,
ClassLoader
the ClassLoader associated with this domain
classloader
,
Principal[]
the array of Principal objects associated with this domain. The contents of the array are copied to protect against subsequent modification.
principals
)

Creates a new ProtectionDomain qualified by the given CodeSource, permissions, ClassLoader and array of principals.

Method Summary

Modifier and TypeMethod and Description
public final ClassLoader

Returns:

the ClassLoader of this domain which may be null.
getClassLoader
()

Returns the ClassLoader of this domain.

public final CodeSource

Returns:

the CodeSource of this domain which may be null.
getCodeSource
()

Returns the CodeSource of this domain.

public final PermissionCollection

Returns:

the static set of permissions for this domain which may be null.
getPermissions
()

Returns the static permissions granted to this domain.

public final Principal[]

Returns:

a non-null array of principals for this domain. Returns a new array each time this method is called.
getPrincipals
()

Returns an array of principals for this domain.

public boolean

Returns:

true if perm is implied by this ProtectionDomain.
implies
(Permission
the Permission object to check.
perm
)

Check and see if this ProtectionDomain implies the permissions expressed in the Permission object.

public final boolean

Returns:

true if this domain contains only static permissions.
staticPermissionsOnly
()

Returns true if this domain contains only static permissions and does not check the current Policy.

public String
toString()

Overrides java.lang.Object.toString.

Convert a ProtectionDomain to a String.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

classloaderback to summary
private final ClassLoader classloader
codesourceback to summary
private final CodeSource codesource
hasAllPermback to summary
private boolean hasAllPerm
permissionsback to summary
private PermissionCollection permissions
principalsback to summary
private final Principal[] principals
staticPermissionsback to summary
private final boolean staticPermissions

Constructor Detail

ProtectionDomainback to summary
public ProtectionDomain(CodeSource codesource, PermissionCollection permissions)

Creates a new ProtectionDomain with the given CodeSource and permissions. If permissions is not null, then setReadOnly() will be called on the passed in permissions.

The permissions granted to this domain are static, i.e. invoking the staticPermissionsOnly() method returns true. They contain only the ones passed to this constructor and the current policy will not be consulted.

API Note

Installing a system-wide Policy object is no longer supported. The current policy is always a Policy object that grants no permissions.

Parameters
codesource:CodeSource

the codesource associated with this domain

permissions:PermissionCollection

the permissions granted to this domain

ProtectionDomainback to summary
public ProtectionDomain(CodeSource codesource, PermissionCollection permissions, ClassLoader classloader, Principal[] principals)

Creates a new ProtectionDomain qualified by the given CodeSource, permissions, ClassLoader and array of principals. If permissions is not null, then setReadOnly() will be called on the passed in permissions.

The permissions granted to this domain are dynamic, i.e. invoking the staticPermissionsOnly() method returns false. They include both the static permissions passed to this constructor, and any permissions granted to this domain by the current policy.

API Note

Installing a system-wide Policy object is no longer supported. The current policy is always a Policy object that grants no permissions.

Parameters
codesource:CodeSource

the CodeSource associated with this domain

permissions:PermissionCollection

the permissions granted to this domain

classloader:ClassLoader

the ClassLoader associated with this domain

principals:Principal[]

the array of Principal objects associated with this domain. The contents of the array are copied to protect against subsequent modification.

Since
1.4
See Also
Policy#getPermissions(ProtectionDomain)

Method Detail

getClassLoaderback to summary
public final ClassLoader getClassLoader()

Returns the ClassLoader of this domain.

Returns:ClassLoader

the ClassLoader of this domain which may be null.

Since
1.4
getCodeSourceback to summary
public final CodeSource getCodeSource()

Returns the CodeSource of this domain.

Returns:CodeSource

the CodeSource of this domain which may be null.

Since
1.2
getPermissionsback to summary
public final PermissionCollection getPermissions()

Returns the static permissions granted to this domain.

Returns:PermissionCollection

the static set of permissions for this domain which may be null.

See Also
Policy#refresh, Policy#getPermissions(ProtectionDomain)
getPrincipalsback to summary
public final Principal[] getPrincipals()

Returns an array of principals for this domain.

Returns:Principal[]

a non-null array of principals for this domain. Returns a new array each time this method is called.

Since
1.4
impliesback to summary
public boolean implies(Permission perm)

Check and see if this ProtectionDomain implies the permissions expressed in the Permission object.

The set of permissions evaluated is a function of whether the ProtectionDomain was constructed with a static set of permissions or it was bound to a dynamically mapped set of permissions.

If the staticPermissionsOnly() method returns true, then the permission will only be checked against the PermissionCollection supplied at construction.

Otherwise, the permission will be checked against the combination of the PermissionCollection supplied at construction and the current policy.

API Note

Installing a system-wide Policy object is no longer supported. The current policy is always a Policy object that grants no permissions.

Parameters
perm:Permission

the Permission object to check.

Returns:boolean

true if perm is implied by this ProtectionDomain.

Annotations
@SuppressWarnings:removal
staticPermissionsOnlyback to summary
public final boolean staticPermissionsOnly()

Returns true if this domain contains only static permissions and does not check the current Policy.

API Note

Installing a system-wide Policy object is no longer supported. The current policy is always a Policy object that grants no permissions.

Returns:boolean

true if this domain contains only static permissions.

Since
9
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert a ProtectionDomain to a String.

Annotations
@Override