ProtectionDomain (Java SE 21 & JDK 21)
public class ProtectionDomain extends Object
The ProtectionDomain class encapsulates the characteristics of a
domain, which encloses a set of classes whose instances are granted a set
of permissions when being executed on behalf of a given set of Principals.
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 whenever
a permission is checked.
- Since:
- 1.2
-
Constructor Summary
Constructors
Creates a new
ProtectionDomainwith the givenCodeSourceand permissions.Creates a new
ProtectionDomainqualified by the givenCodeSource, permissions,ClassLoaderand array of principals. -
Method Summary
Returns the
ClassLoaderof this domain.Returns the
CodeSourceof this domain.Returns the static permissions granted to this domain.
Returns an array of principals for this domain.
booleanCheck and see if this
ProtectionDomainimplies the permissions expressed in thePermissionobject.final booleanReturns
trueif this domain contains only static permissions and does not check the currentPolicyat the time of permission checking.toString()Convert a
ProtectionDomainto aString.
-
Constructor Details
-
ProtectionDomain
Creates a new
ProtectionDomainwith the givenCodeSourceand permissions. If permissions is notnull, thensetReadOnly()will be called on the passed in permissions.The permissions granted to this domain are static, i.e. invoking the
staticPermissionsOnly()method returnstrue. They contain only the ones passed to this constructor and the current policy will not be consulted.- Parameters:
codesource- the codesource associated with this domainpermissions- the permissions granted to this domain
-
ProtectionDomain
Creates a new
ProtectionDomainqualified by the givenCodeSource, permissions,ClassLoaderand array of principals. If permissions is notnull, thensetReadOnly()will be called on the passed in permissions.The permissions granted to this domain are dynamic, i.e. invoking the
staticPermissionsOnly()method returnsfalse. They include both the static permissions passed to this constructor, and any permissions granted to this domain by the current policy at the time a permission is checked.This constructor is typically used by
ClassLoadersandDomainCombinerswhich delegate to thePolicyobject to actively associate the permissions granted to this domain. This constructor affords the policy provider the opportunity to augment the suppliedPermissionCollectionto reflect policy changes.- Parameters:
codesource- theCodeSourceassociated with this domainpermissions- the permissions granted to this domainclassloader- theClassLoaderassociated with this domainprincipals- the array ofPrincipalobjects associated with this domain. The contents of the array are copied to protect against subsequent modification.- Since:
- 1.4
- See Also:
-
-
Method Details
-
getCodeSource
Returns the
CodeSourceof this domain.- Returns:
- the
CodeSourceof this domain which may benull. - Since:
- 1.2
-
getClassLoader
Returns the
ClassLoaderof this domain.- Returns:
- the
ClassLoaderof this domain which may benull. - Since:
- 1.4
-
getPrincipals
public final Principal[] getPrincipals()
Returns an array of principals for this domain.
- Returns:
- a non-null array of principals for this domain. Returns a new array each time this method is called.
- Since:
- 1.4
-
getPermissions
Returns the static permissions granted to this domain.
- Returns:
- the static set of permissions for this domain which may be
null. - See Also:
-
staticPermissionsOnly
public final boolean staticPermissionsOnly()
Returns
trueif this domain contains only static permissions and does not check the currentPolicyat the time of permission checking.- Returns:
trueif this domain contains only static permissions.- Since:
- 9
-
implies
Check and see if this
ProtectionDomainimplies the permissions expressed in thePermissionobject.The set of permissions evaluated is a function of whether the
ProtectionDomainwas constructed with a static set of permissions or it was bound to a dynamically mapped set of permissions.If the
staticPermissionsOnly()method returnstrue, then the permission will only be checked against thePermissionCollectionsupplied at construction.Otherwise, the permission will be checked against the combination of the
PermissionCollectionsupplied at construction and the current policy binding.- Parameters:
perm- the {code Permission} object to check.- Returns:
trueifpermis implied by thisProtectionDomain.
-
toString
Convert a
ProtectionDomainto aString.
-