Class ServicePermission

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

    public final class ServicePermission
    extends java.security.BasicPermission
    A bundle's authority to register or get a service.
    • The register action allows a bundle to register a service on the specified names.
    • The get action allows a bundle to detect a service and get it.
    Permission to get a service is required in order to detect events regarding the service. Untrusted bundles should not be able to detect the presence of certain services unless they have the appropriate ServicePermission to get the specific service.
    Version:
    $Revision: 7189 $
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int ACTION_ALL  
      private static int ACTION_GET  
      (package private) int action_mask
      The actions mask.
      (package private) static int ACTION_NONE  
      private static int ACTION_REGISTER  
      private java.lang.String actions
      The actions in canonical form.
      (package private) Filter filter
      If this ServicePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.
      static java.lang.String GET
      The action string get.
      (package private) java.lang.String[] objectClass
      The object classes for this ServicePermission.
      private java.lang.String prefix
      If constructed with a name and the name ends with ".*", this contains the name without the final "*".
      private java.util.Dictionary properties
      This dictionary holds the properties of the permission, used to match a filter in implies.
      static java.lang.String REGISTER
      The action string register.
      (package private) static long serialVersionUID  
      (package private) ServiceReference service
      The service used by this ServicePermission.
      private boolean wildcard
      True if constructed with a name and the name is "*" or ends with ".*".
    • Constructor Summary

      Constructors 
      Constructor Description
      ServicePermission​(java.lang.String name, int mask)
      Package private constructor used by ServicePermissionCollection.
      ServicePermission​(java.lang.String name, java.lang.String actions)
      Create a new ServicePermission.
      ServicePermission​(ServiceReference reference, java.lang.String actions)
      Creates a new requested ServicePermission object to be used by code that must perform checkPermission for the get action.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String createName​(ServiceReference reference)
      Create a permission name from a ServiceReference
      boolean equals​(java.lang.Object obj)
      Determines the equality of two ServicePermission objects.
      java.lang.String getActions()
      Returns the canonical string representation of the actions.
      private java.util.Dictionary getProperties()
      Called by <@link ServicePermission#implies(Permission)>.
      int hashCode()
      Returns the hash code value for this object.
      boolean implies​(java.security.Permission p)
      Determines if a ServicePermission object "implies" the specified permission.
      (package private) boolean implies0​(ServicePermission requested, int effective)
      Internal implies method.
      java.security.PermissionCollection newPermissionCollection()
      Returns a new PermissionCollection object for storing ServicePermission 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​(Filter f, 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 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

      • REGISTER

        public static final java.lang.String REGISTER
        The action string register.
        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.
      • service

        final transient ServiceReference service
        The service used by this ServicePermission. Must be null if not constructed with a service.
      • objectClass

        final transient java.lang.String[] objectClass
        The object classes for this ServicePermission. Must be null if not constructed with a service.
      • filter

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

        private transient volatile java.util.Dictionary properties
        This dictionary 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.
      • wildcard

        private transient boolean wildcard
        True if constructed with a name and the name is "*" or ends with ".*".
      • prefix

        private transient java.lang.String prefix
        If constructed with a name and the name ends with ".*", this contains the name without the final "*".
    • Constructor Detail

      • ServicePermission

        public ServicePermission​(java.lang.String name,
                                 java.lang.String actions)
        Create a new ServicePermission.

        The name of the service is specified as a fully qualified class name. Wildcards may be used.

         name ::= <class name> | <class name ending in ".*"> | *
         
        Examples:
         org.osgi.service.http.HttpService
         org.osgi.service.http.*
         *
         
        For the get action, the name can also be a filter expression. The filter gives access to the service properties as well as the following attributes:
        • signer - A Distinguished Name chain used to sign the bundle publishing the service. 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 bundle publishing the service.
        • id - The bundle ID of the bundle publishing the service.
        • name - The symbolic name of the bundle publishing the service.
        Since the above attribute names may conflict with service property names used by a service, you can prefix an attribute name with '@' in the filter expression to match against the service property and not one of the above attributes. Filter attribute names are processed in a case sensitive manner unless the attribute references a service property. Service properties names are case insensitive.

        There are two possible actions: get and register. The get permission allows the owner of this permission to obtain a service with this name. The register permission allows the bundle to register a service under that name.

        Parameters:
        name - The service class name
        actions - get,register (canonical order)
        Throws:
        java.lang.IllegalArgumentException - If the specified name is a filter expression and either the specified action is not get or the filter has an invalid syntax.
      • ServicePermission

        public ServicePermission​(ServiceReference reference,
                                 java.lang.String actions)
        Creates a new requested ServicePermission object to be used by code that must perform checkPermission for the get action. ServicePermission objects created with this constructor cannot be added to a ServicePermission permission collection.
        Parameters:
        reference - The requested service.
        actions - The action get.
        Throws:
        java.lang.IllegalArgumentException - If the specified action is not get or reference is null.
        Since:
        1.5
      • ServicePermission

        ServicePermission​(java.lang.String name,
                          int mask)
        Package private constructor used by ServicePermissionCollection.
        Parameters:
        name - class name
        mask - action mask
    • Method Detail

      • createName

        private static java.lang.String createName​(ServiceReference reference)
        Create a permission name from a ServiceReference
        Parameters:
        reference - ServiceReference to use to create permission name.
        Returns:
        permission name.
      • setTransients

        private void setTransients​(Filter f,
                                   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 a ServicePermission object "implies" the specified permission.
        Overrides:
        implies in class java.security.BasicPermission
        Parameters:
        p - The target permission to check.
        Returns:
        true if the specified permission is implied by this object; false otherwise.
      • implies0

        boolean implies0​(ServicePermission requested,
                         int effective)
        Internal implies method. Used by the implies and the permission collection implies methods.
        Parameters:
        requested - The requested ServicePermission which has already be validated as a proper argument. The requested ServicePermission 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 actions. Always returns present actions in the following order: get, register.
        Overrides:
        getActions in class java.security.BasicPermission
        Returns:
        The canonical string representation of the actions.
      • newPermissionCollection

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

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

        public int hashCode()
        Returns the hash code value for this object.
        Overrides:
        hashCode in class java.security.BasicPermission
        Returns:
        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 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.Dictionary getProperties()
        Called by <@link ServicePermission#implies(Permission)>.
        Returns:
        a dictionary of properties for this permission.