public class

ProtectionDomain

extends Object
java.lang.Object
   ↳ java.security.ProtectionDomain

Class Overview

ProtectionDomain represents all permissions that are granted to a specific code source. The ClassLoader associates each class with the corresponding ProtectionDomain, depending on the location and the certificates (encapsulates in CodeSource) it loads the code from.

A class belongs to exactly one protection domain and the protection domain can not be changed during the lifetime of the class.

Summary

Public Constructors
ProtectionDomain(CodeSource cs, PermissionCollection permissions)
Constructs a new instance of ProtectionDomain with the specified code source and the specified static permissions.
ProtectionDomain(CodeSource cs, PermissionCollection permissions, ClassLoader cl, Principal[] principals)
Constructs a new instance of ProtectionDomain with the specified code source, the permissions, the class loader and the principals.
Public Methods
final ClassLoader getClassLoader()
Returns the ClassLoader associated with this ProtectionDomain.
final CodeSource getCodeSource()
Returns the CodeSource of this ProtectionDomain.
final PermissionCollection getPermissions()
Returns the static permissions that are granted to this ProtectionDomain.
final Principal[] getPrincipals()
Returns the principals associated with this ProtectionDomain.
boolean implies(Permission permission)
Indicates whether the specified permission is implied by this ProtectionDomain.
String toString()
Returns a string containing a concise, human-readable description of the this ProtectionDomain.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ProtectionDomain (CodeSource cs, PermissionCollection permissions)

Constructs a new instance of ProtectionDomain with the specified code source and the specified static permissions.

If permissions is not null, the permissions collection is made immutable by calling setReadOnly() and it is considered as granted statically to this ProtectionDomain.

The policy will not be consulted by access checks against this ProtectionDomain.

If permissions is null, the method implies(Permission) always returns false .

Parameters
cs the code source associated with this domain, maybe null.
permissions the PermissionCollection containing all permissions to be statically granted to this ProtectionDomain, maybe null.

public ProtectionDomain (CodeSource cs, PermissionCollection permissions, ClassLoader cl, Principal[] principals)

Constructs a new instance of ProtectionDomain with the specified code source, the permissions, the class loader and the principals.

If permissions is null, and access checks are performed against this protection domain, the permissions defined by the policy are consulted. If permissions is not null, the permissions collection is made immutable by calling setReadOnly(). If access checks are performed, the policy and the provided permission collection are checked.

External modifications of the provided principals array has no impact on this ProtectionDomain.

Parameters
cs the code source associated with this domain, maybe null.
permissions the permissions associated with this domain, maybe null.
cl the class loader associated with this domain, maybe null.
principals the principals associated with this domain, maybe null .

Public Methods

public final ClassLoader getClassLoader ()

Returns the ClassLoader associated with this ProtectionDomain.

Returns
  • the ClassLoader associated with this ProtectionDomain, maybe null.

public final CodeSource getCodeSource ()

Returns the CodeSource of this ProtectionDomain.

Returns
  • the CodeSource of this ProtectionDomain, maybe null.

public final PermissionCollection getPermissions ()

Returns the static permissions that are granted to this ProtectionDomain.

Returns
  • the static permissions that are granted to this ProtectionDomain, maybe null.

public final Principal[] getPrincipals ()

Returns the principals associated with this ProtectionDomain. Modifications of the returned Principal array has no impact on this ProtectionDomain.

Returns
  • the principals associated with this ProtectionDomain.

public boolean implies (Permission permission)

Indicates whether the specified permission is implied by this ProtectionDomain.

If this ProtectionDomain was constructed with ProtectionDomain(CodeSource, PermissionCollection), the specified permission is only checked against the permission collection provided in the constructor. If null was provided, false is returned.

If this ProtectionDomain was constructed with ProtectionDomain(CodeSource, PermissionCollection, ClassLoader, Principal[]) , the specified permission is checked against the policy and the permission collection provided in the constructor.

Parameters
permission the permission to check against the domain.
Returns
  • true if the specified permission is implied by this ProtectionDomain, false otherwise.

public String toString ()

Returns a string containing a concise, human-readable description of the this ProtectionDomain.

Returns
  • a printable representation for this ProtectionDomain.