Class SubsystemPermission

java.lang.Object
java.security.Permission
java.security.BasicPermission
org.osgi.service.subsystem.SubsystemPermission
All Implemented Interfaces:
Serializable, Guard

public final class SubsystemPermission extends BasicPermission
A bundle's authority to perform specific privileged administrative operations on or to get sensitive information about a subsystem. The actions for this permission are:
 Action    Methods
 context   Subsystem.getBundleContext
 execute   Subsystem.start
           Subsystem.stop
 lifecycle Subsystem.install
           Subsystem.uninstall
 metadata  Subsystem.getSubsystemHeaders
           Subsystem.getLocation
 

The name of this permission is a filter expression. The filter gives access to the following attributes:

  • location - The location of a subsystem.
  • id - The subsystem ID of the designated subsystem.
  • name - The symbolic name of a subsystem.
Filter attribute names are processed in a case sensitive manner.
See Also:
  • Field Details

    • serialVersionUID

      static final long serialVersionUID
      See Also:
    • EXECUTE

      public static final String EXECUTE
      The action string execute.
      See Also:
    • LIFECYCLE

      public static final String LIFECYCLE
      The action string lifecycle.
      See Also:
    • METADATA

      public static final String METADATA
      The action string metadata.
      See Also:
    • CONTEXT

      public static final String CONTEXT
      The action string context.
      See Also:
    • ACTION_EXECUTE

      private static final int ACTION_EXECUTE
      See Also:
    • ACTION_LIFECYCLE

      private static final int ACTION_LIFECYCLE
      See Also:
    • ACTION_METADATA

      private static final int ACTION_METADATA
      See Also:
    • ACTION_CONTEXT

      private static final int ACTION_CONTEXT
      See Also:
    • ACTION_ALL

      private static final int ACTION_ALL
      See Also:
    • ACTION_NONE

      static final int ACTION_NONE
      See Also:
    • actions

      private volatile String actions
      The actions in canonical form.
    • action_mask

      transient int action_mask
      The actions mask.
    • filter

      transient org.osgi.framework.Filter filter
      If this SubsystemPermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.
    • subsystem

      final transient Subsystem subsystem
      The subsystem governed by this SubsystemPermission - only used if filter == null
    • properties

      private transient volatile Map<String,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.
    • recurse

      private static final ThreadLocal<Subsystem> recurse
      ThreadLocal used to determine if we have recursively called getProperties.
  • Constructor Details

    • SubsystemPermission

      public SubsystemPermission(String filter, String actions)
      Create a new SubsystemPermission. This constructor must only be used to create a permission that is going to be checked.

      Examples:

       (name=com.acme.*)(location=http://www.acme.com/subsystems/*))
       (id>=1)
       
      Parameters:
      filter - A filter expression that can use, location, id, and name keys. Filter attribute names are processed in a case sensitive manner. A special value of "*" can be used to match all subsystems.
      actions - execute, lifecycle, metadata, or context.
      Throws:
      IllegalArgumentException - If the filter has an invalid syntax.
    • SubsystemPermission

      public SubsystemPermission(Subsystem subsystem, String actions)
      Creates a new requested SubsystemPermission object to be used by the code that must perform checkPermission. SubsystemPermission objects created with this constructor cannot be added to an SubsystemPermission permission collection.
      Parameters:
      subsystem - A subsystem.
      actions - execute, lifecycle, metadata, or context.
    • SubsystemPermission

      SubsystemPermission(org.osgi.framework.Filter filter, int mask)
      Package private constructor used by SubsystemPermissionCollection.
      Parameters:
      filter - name filter or null for wildcard.
      mask - action mask
  • Method Details

    • createName

      private static String createName(Subsystem subsystem)
      Create a permission name from a Subsystem
      Parameters:
      subsystem - Subsystem to use to create permission name.
      Returns:
      permission name.
    • setTransients

      private void setTransients(org.osgi.framework.Filter filter, int mask)
      Called by constructors and when deserialized.
      Parameters:
      filter - Permission's filter or null for wildcard.
      mask - action mask
    • parseActions

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

      private static org.osgi.framework.Filter parseFilter(String filterString)
      Parse filter string into a Filter object.
      Parameters:
      filterString - The filter string to parse.
      Returns:
      a Filter for this subsystem. If the specified filterString equals "*", then null is returned to indicate a wildcard.
      Throws:
      IllegalArgumentException - If the filter syntax is invalid.
    • implies

      public boolean implies(Permission p)
      Determines if the specified permission is implied by this object. This method throws an exception if the specified permission was not constructed with a subsystem.

      This method returns true if the specified permission is a SubsystemPermission AND

      • this object's filter matches the specified permission's subsystem ID, subsystem symbolic name, and subsystem location OR
      • this object's filter is "*"
      AND this object's actions include all of the specified permission's actions.

      Special case: if the specified permission was constructed with "*" filter, then this method returns true if this object's filter is "*" and this object's actions include all of the specified permission's actions

      Overrides:
      implies in class BasicPermission
      Parameters:
      p - The requested permission.
      Returns:
      true if the specified permission is implied by this object; false otherwise.
    • implies0

      boolean implies0(SubsystemPermission requested, int effective)
      Internal implies method. Used by the implies and the permission collection implies methods.
      Parameters:
      requested - The requested SubsystemPermision which has already been validated as a proper argument. The requested SubsystemPermission 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 String getActions()
      Returns the canonical string representation of the SubsystemPermission actions.

      Always returns present SubsystemPermission actions in the following order: execute, lifecycle, metadata, context.

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

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

      public boolean equals(Object obj)
      Determines the equality of two SubsystemPermission objects.
      Overrides:
      equals in class BasicPermission
      Parameters:
      obj - The object being compared for equality with this object.
      Returns:
      true if obj is equivalent to this SubsystemPermission; false otherwise.
    • hashCode

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

      private void writeObject(ObjectOutputStream s) throws 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:
      IOException
    • readObject

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

      private Map<String,Object> getProperties()
      Called by implies0 on an SubsystemPermission which was constructed with a Subsystem. This method loads a map with the filter-matchable properties of this subsystem. The map is cached so this lookup only happens once. This method should only be called on an SubsystemPermission which was constructed with a subsystem
      Returns:
      a map of properties for this subsystem