Class ProtectionDomain

java.lang.Object
java.security.ProtectionDomain

public classProtectionDomainextendsObject
TheProtectionDomain 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 aProtectionDomain when it is constructed; such permissions are granted to the domain regardless of the policy in force. However, to support dynamic security policies, aProtectionDomain can also be constructed such that it is dynamically mapped to a set of permissions by the current policy.

API Note:
Installing a system-widePolicy object is no longer supported. Thecurrent policy is always aPolicy object that grants no permissions.
Since:
1.2
  • Constructor Details

    • ProtectionDomain

      public ProtectionDomain(CodeSource codesource,PermissionCollection permissions)
      Creates a newProtectionDomain with the givenCodeSource and 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 thestaticPermissionsOnly() method returnstrue. They contain only the ones passed to this constructor and the current policy will not be consulted.

      API Note:
      Installing a system-widePolicy object is no longer supported. Thecurrent policy is always aPolicy object that grants no permissions.
      Parameters:
      codesource - the codesource associated with this domain
      permissions - the permissions granted to this domain
    • ProtectionDomain

      public ProtectionDomain(CodeSource codesource,PermissionCollection permissions,ClassLoader classloader,Principal[] principals)
      Creates a newProtectionDomain qualified by the givenCodeSource, permissions,ClassLoader and 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 thestaticPermissionsOnly() method returnsfalse. 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-widePolicy object is no longer supported. Thecurrent policy is always aPolicy object that grants no permissions.
      Parameters:
      codesource - theCodeSource associated with this domain
      permissions - the permissions granted to this domain
      classloader - theClassLoader associated with this domain
      principals - the array ofPrincipal objects associated with this domain. The contents of the array are copied to protect against subsequent modification.
      Since:
      1.4
      See Also:
  • Method Details

    • getCodeSource

      public final CodeSource getCodeSource()
      Returns theCodeSource of this domain.
      Returns:
      theCodeSource of this domain which may benull.
      Since:
      1.2
    • getClassLoader

      public final ClassLoader getClassLoader()
      Returns theClassLoader of this domain.
      Returns:
      theClassLoader of 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

      public final PermissionCollection getPermissions()
      Returns the static permissions granted to this domain.
      Returns:
      the static set of permissions for this domain which may benull.
      See Also:
    • staticPermissionsOnly

      public final boolean staticPermissionsOnly()
      Returnstrue if this domain contains only static permissions and does not check the currentPolicy.
      API Note:
      Installing a system-widePolicy object is no longer supported. Thecurrent policy is always aPolicy object that grants no permissions.
      Returns:
      true if this domain contains only static permissions.
      Since:
      9
    • implies

      public boolean implies(Permission perm)
      Check and see if thisProtectionDomain implies the permissions expressed in thePermission object.

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

      If thestaticPermissionsOnly() method returnstrue, then the permission will only be checked against thePermissionCollection supplied at construction.

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

      API Note:
      Installing a system-widePolicy object is no longer supported. Thecurrent policy is always aPolicy object that grants no permissions.
      Parameters:
      perm - the {code Permission} object to check.
      Returns:
      true ifperm is implied by thisProtectionDomain.
    • toString

      public String toString()
      Convert aProtectionDomain to aString.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object