Class PackagePermission

  • All Implemented Interfaces:
    java.io.Serializable, java.security.Guard

    public final class PackagePermission
    extends java.security.BasicPermission
    A bundle's authority to import or export a package.

    A package is a dot-separated string that defines a fully qualified Java package.

    For example:

     org.osgi.service.http
     

    PackagePermission has three actions: exportonly, import and export. The export action, which is deprecated, implies the import action.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int ACTION_ALL  
      private static int ACTION_EXPORT  
      private static int ACTION_IMPORT  
      (package private) int action_mask
      The actions mask.
      (package private) static int ACTION_NONE  
      private java.lang.String actions
      The actions in canonical form.
      (package private) Bundle bundle
      The bundle used by this PackagePermission.
      static java.lang.String EXPORT
      Deprecated.
      Since 1.5.
      static java.lang.String EXPORTONLY
      The action string exportonly.
      (package private) Filter filter
      If this PackagePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.
      static java.lang.String IMPORT
      The action string import.
      private java.util.Map<java.lang.String,​java.lang.Object> properties
      This map holds the properties of the permission, used to match a filter in implies.
      (package private) static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      PackagePermission​(java.lang.String name, int mask)
      Package private constructor used by PackagePermissionCollection.
      PackagePermission​(java.lang.String name, java.lang.String actions)
      Creates a new PackagePermission object.
      PackagePermission​(java.lang.String name, Bundle exportingBundle, java.lang.String actions)
      Creates a new requested PackagePermission object to be used by code that must perform checkPermission for the import action.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Determines the equality of two PackagePermission objects.
      java.lang.String getActions()
      Returns the canonical string representation of the PackagePermission actions.
      private java.util.Map<java.lang.String,​java.lang.Object> getProperties()
      int hashCode()
      Returns the hash code value for this object.
      boolean implies​(java.security.Permission p)
      Determines if the specified permission is implied by this object.
      (package private) boolean implies0​(PackagePermission requested, int effective)
      Internal implies method.
      java.security.PermissionCollection newPermissionCollection()
      Returns a new PermissionCollection object suitable for storing PackagePermission objects.
      private static int parseActions​(java.lang.String actions)
      Parse action string into action mask.
      private static Filter parseFilter​(java.lang.String filterString)
      Parse filter string into a Filter object.
      private void readObject​(java.io.ObjectInputStream s)
      readObject is called to restore the state of this permission from a stream.
      private void setTransients​(java.lang.String name, int mask)
      Called by constructors and when deserialized.
      private void writeObject​(java.io.ObjectOutputStream s)
      WriteObject is called to save the state of this permission object to a stream.
      • Methods inherited from class java.security.Permission

        checkGuard, getName, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EXPORT

        public static final java.lang.String EXPORT
        Deprecated.
        Since 1.5. Use exportonly instead.
        The action string export. The export action implies the import action.
        See Also:
        Constant Field Values
      • EXPORTONLY

        public static final java.lang.String EXPORTONLY
        The action string exportonly. The exportonly action does not imply the import action.
        Since:
        1.5
        See Also:
        Constant Field Values
      • IMPORT

        public static final java.lang.String IMPORT
        The action string import.
        See Also:
        Constant Field Values
      • action_mask

        transient int action_mask
        The actions mask.
      • actions

        private volatile java.lang.String actions
        The actions in canonical form.
      • bundle

        final transient Bundle bundle
        The bundle used by this PackagePermission.
      • filter

        transient Filter filter
        If this PackagePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.
      • properties

        private transient volatile java.util.Map<java.lang.String,​java.lang.Object> properties
        This map holds the properties of the permission, used to match a filter in implies. This is not initialized until necessary, and then cached in this object.
    • Constructor Detail

      • PackagePermission

        public PackagePermission​(java.lang.String name,
                                 java.lang.String actions)
        Creates a new PackagePermission object.

        The name is specified as a normal Java package name: a dot-separated string. Wildcards may be used.

         name ::= <package name> | <package name ending in ".*"> | *
         
        Examples:
         org.osgi.service.http
         javax.servlet.*
         *
         
        For the import action, the name can also be a filter expression. The filter gives access to the following attributes:
        • signer - A Distinguished Name chain used to sign the exporting bundle. Wildcards in a DN are not matched according to the filter string rules, but according to the rules defined for a DN chain.
        • location - The location of the exporting bundle.
        • id - The bundle ID of the exporting bundle.
        • name - The symbolic name of the exporting bundle.
        • package.name - The name of the requested package.
        Filter attribute names are processed in a case sensitive manner.

        Package Permissions are granted over all possible versions of a package. A bundle that needs to export a package must have the appropriate PackagePermission for that package; similarly, a bundle that needs to import a package must have the appropriate PackagePermssion for that package.

        Permission is granted for both classes and resources.

        Parameters:
        name - Package name or filter expression. A filter expression can only be specified if the specified action is import.
        actions - exportonly,import (canonical order).
        Throws:
        java.lang.IllegalArgumentException - If the specified name is a filter expression and either the specified action is not import or the filter has an invalid syntax.
      • PackagePermission

        public PackagePermission​(java.lang.String name,
                                 Bundle exportingBundle,
                                 java.lang.String actions)
        Creates a new requested PackagePermission object to be used by code that must perform checkPermission for the import action. PackagePermission objects created with this constructor cannot be added to a PackagePermission permission collection.
        Parameters:
        name - The name of the requested package to import.
        exportingBundle - The bundle exporting the requested package.
        actions - The action import.
        Throws:
        java.lang.IllegalArgumentException - If the specified action is not import or the name is a filter expression.
        Since:
        1.5
      • PackagePermission

        PackagePermission​(java.lang.String name,
                          int mask)
        Package private constructor used by PackagePermissionCollection.
        Parameters:
        name - package name
        mask - action mask
    • Method Detail

      • setTransients

        private void setTransients​(java.lang.String name,
                                   int mask)
        Called by constructors and when deserialized.
        Parameters:
        mask - action mask
      • parseActions

        private static int parseActions​(java.lang.String actions)
        Parse action string into action mask.
        Parameters:
        actions - Action string.
        Returns:
        action mask.
      • parseFilter

        private static Filter parseFilter​(java.lang.String filterString)
        Parse filter string into a Filter object.
        Parameters:
        filterString - The filter string to parse.
        Returns:
        a Filter for this bundle. If the specified filterString is not a filter expression, then null is returned.
        Throws:
        java.lang.IllegalArgumentException - If the filter syntax is invalid.
      • implies

        public boolean implies​(java.security.Permission p)
        Determines if the specified permission is implied by this object.

        This method checks that the package name of the target is implied by the package name of this object. The list of PackagePermission actions must either match or allow for the list of the target object to imply the target PackagePermission action.

        The permission to export a package implies the permission to import the named package.

         x.y.*,"export" -> x.y.z,"export" is true
         *,"import" -> x.y, "import"      is true
         *,"export" -> x.y, "import"      is true
         x.y,"export" -> x.y.z, "export"  is false
         
        Overrides:
        implies in class java.security.BasicPermission
        Parameters:
        p - The requested permission.
        Returns:
        true if the specified permission is implied by this object; false otherwise.
      • implies0

        boolean implies0​(PackagePermission requested,
                         int effective)
        Internal implies method. Used by the implies and the permission collection implies methods.
        Parameters:
        requested - The requested PackagePermission which has already be validated as a proper argument. The requested PackagePermission must not have a filter expression.
        effective - The effective actions with which to start.
        Returns:
        true if the specified permission is implied by this object; false otherwise.
      • getActions

        public java.lang.String getActions()
        Returns the canonical string representation of the PackagePermission actions.

        Always returns present PackagePermission actions in the following order: EXPORTONLY,IMPORT.

        Overrides:
        getActions in class java.security.BasicPermission
        Returns:
        Canonical string representation of the PackagePermission actions.
      • newPermissionCollection

        public java.security.PermissionCollection newPermissionCollection()
        Returns a new PermissionCollection object suitable for storing PackagePermission objects.
        Overrides:
        newPermissionCollection in class java.security.BasicPermission
        Returns:
        A new PermissionCollection object.
      • equals

        public boolean equals​(java.lang.Object obj)
        Determines the equality of two PackagePermission objects. This method checks that specified package has the same package name and PackagePermission actions as this PackagePermission object.
        Overrides:
        equals in class java.security.BasicPermission
        Parameters:
        obj - The object to test for equality with this PackagePermission object.
        Returns:
        true if obj is a PackagePermission, and has the same package name and actions as this PackagePermission object; false otherwise.
      • hashCode

        public int hashCode()
        Returns the hash code value for this object.
        Overrides:
        hashCode in class java.security.BasicPermission
        Returns:
        A hash code value for this object.
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream s)
                          throws java.io.IOException
        WriteObject is called to save the state of this permission object to a stream. The actions are serialized, and the superclass takes care of the name.
        Throws:
        java.io.IOException
      • readObject

        private void readObject​(java.io.ObjectInputStream s)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        readObject is called to restore the state of this permission from a stream.
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • getProperties

        private java.util.Map<java.lang.String,​java.lang.Object> getProperties()
        Called by implies(Permission). This method is only called on a requested permission which cannot have a filter set.
        Returns:
        a map of properties for this permission.