Top Description Inners Fields Constructors Methods
java.security

public Class ProtectionDomain

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .Enumeration, .List, .Map, .Objects, .WeakHashMap, jdk.internal.access.JavaSecurityAccess, .SharedSecrets, sun.security.action.GetPropertyAction, sun.security.provider.PolicyFile, sun.security.util.Debug, .FilePermCompat, .SecurityConstants

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.

Authors
Li Gong, Roland Schemers, Gary Ellison
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
pack-priv static class
ProtectionDomain.Key

Used for storing ProtectionDomains as keys in a Map.

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private final CodeSource
private static final boolean
filePermCompatInPD

If true, impliesWithAltFilePerm will try to be compatible on FilePermission checking even if a 3rd-party Policy implementation is set.

private boolean
pack-priv final ProtectionDomain.Key
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 {code Permission} object to check.
perm
)

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

pack-priv boolean
impliesWithAltFilePerm(Permission perm)

This method has almost the same logic flow as implies but it ensures some level of FilePermission compatibility after JDK-8164705.

private PermissionCollection
private static boolean
seeAllp()

Return true (merge policy permissions) in the following cases: .

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 at the time of permission checking.

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
filePermCompatInPDback to summary
private static final boolean filePermCompatInPD

If true, impliesWithAltFilePerm will try to be compatible on FilePermission checking even if a 3rd-party Policy implementation is set.

hasAllPermback to summary
private boolean hasAllPerm
keyback to summary
pack-priv final ProtectionDomain.Key key
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.

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 at the time a permission is checked.

This constructor is typically used by ClassLoaders and DomainCombiners which delegate to the Policy object to actively associate the permissions granted to this domain. This constructor affords the policy provider the opportunity to augment the supplied PermissionCollection to reflect policy changes.

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#refresh, 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 binding.

Parameters
perm:Permission

the {code Permission} object to check.

Returns:boolean

true if perm is implied by this ProtectionDomain.

Annotations
@SuppressWarnings:removal
impliesWithAltFilePermback to summary
pack-priv boolean impliesWithAltFilePerm(Permission perm)

This method has almost the same logic flow as implies but it ensures some level of FilePermission compatibility after JDK-8164705. This method is called by AccessControlContext#checkPermission and not intended to be called by an application.

mergePermissionsback to summary
private PermissionCollection mergePermissions()
seeAllpback to summary
private static boolean seeAllp()

Return true (merge policy permissions) in the following cases: . SecurityManager is null . SecurityManager is not null, debug is not null, SecurityManager implementation is in bootclasspath, Policy implementation is in bootclasspath (the bootclasspath restrictions avoid recursion) . SecurityManager is not null, debug is null, caller has Policy.getPolicy permission

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 at the time of permission checking.

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.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
java.security back to summary

private Class ProtectionDomain.DebugHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final Debug

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private static final Debug debug

Constructor Detail

DebugHolderback to summary
private DebugHolder()
java.security back to summary

private Class ProtectionDomain.JavaSecurityAccessImpl

extends Object
implements JavaSecurityAccess
Class Inheritance
All Implemented Interfaces
jdk.internal.access.JavaSecurityAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public <T> T
public <T> T
private static AccessControlContext
getCombinedACC(AccessControlContext context, AccessControlContext stack)

Deprecated as a consequence of AccessControlContext being deprecated.
public ProtectionDomain[]
public JavaSecurityAccess.ProtectionDomainCache
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

JavaSecurityAccessImplback to summary
private JavaSecurityAccessImpl()

Method Detail

doIntersectionPrivilegeback to summary
public <T> T doIntersectionPrivilege(PrivilegedAction<T> action, final AccessControlContext stack, final AccessControlContext context)

Implements jdk.internal.access.JavaSecurityAccess.doIntersectionPrivilege.

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
@Override
doIntersectionPrivilegeback to summary
public <T> T doIntersectionPrivilege(PrivilegedAction<T> action, AccessControlContext context)

Implements jdk.internal.access.JavaSecurityAccess.doIntersectionPrivilege.

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
@Override
getCombinedACCback to summary
private static AccessControlContext getCombinedACC(AccessControlContext context, AccessControlContext stack)

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@SuppressWarnings:removal
getProtectDomainsback to summary
public ProtectionDomain[] getProtectDomains(AccessControlContext context)

Implements jdk.internal.access.JavaSecurityAccess.getProtectDomains.

Deprecated

as a consequence of AccessControlContext being deprecated. See corresponding docs for further information.

Annotations
@Override
getProtectionDomainCacheback to summary
public JavaSecurityAccess.ProtectionDomainCache getProtectionDomainCache()

Implements jdk.internal.access.JavaSecurityAccess.getProtectionDomainCache.

Doc from jdk.internal.access.JavaSecurityAccess.getProtectionDomainCache.

Returns the ProtectionDomainCache.

Annotations
@Override
java.security back to summary

pack-priv final Class ProtectionDomain.Key

extends Object
Class Inheritance

Used for storing ProtectionDomains as keys in a Map.

Constructor Summary

AccessConstructor and Description
pack-priv
Key()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Keyback to summary
pack-priv Key()