Package org.osgi.framework
Class CapabilityPermission
- java.lang.Object
-
- java.security.Permission
-
- java.security.BasicPermission
-
- org.osgi.framework.CapabilityPermission
-
- All Implemented Interfaces:
java.io.Serializable,java.security.Guard
public final class CapabilityPermission extends java.security.BasicPermissionA bundle's authority to provide or require a capability.- The
provideaction allows a bundle to provide a capability matching the specified filter. - The
requireaction allows a bundle to require a capability matching the specified filter.
- Since:
- 1.6
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCapabilityPermission.Properties
-
Field Summary
Fields Modifier and Type Field Description private static intACTION_ALL(package private) intaction_maskThe actions mask.(package private) static intACTION_NONEprivate static intACTION_PROVIDEprivate static intACTION_REQUIREprivate java.lang.StringactionsThe actions in canonical form.(package private) java.util.Map<java.lang.String,java.lang.Object>attributesThe attributes of the requested capability.(package private) BundlebundleThe bundle of the requested capability.(package private) FilterfilterIf this CapabilityPermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.private java.util.Map<java.lang.String,java.lang.Object>propertiesThis map holds the properties of the permission, used to match a filter in implies.static java.lang.StringPROVIDEThe action stringprovide.static java.lang.StringREQUIREThe action stringrequire.(package private) static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description CapabilityPermission(java.lang.String name, int mask)Package private constructor used by CapabilityPermissionCollection.CapabilityPermission(java.lang.String name, java.lang.String actions)Create a new CapabilityPermission.CapabilityPermission(java.lang.String namespace, java.util.Map<java.lang.String,?> attributes, Bundle providingBundle, java.lang.String actions)Creates a new requestedCapabilityPermissionobject to be used by code that must performcheckPermissionfor therequireaction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Determines the equality of two CapabilityPermission objects.java.lang.StringgetActions()Returns the canonical string representation of the actions.private java.util.Map<java.lang.String,java.lang.Object>getProperties()Called byimplies(Permission).inthashCode()Returns the hash code value for this object.booleanimplies(java.security.Permission p)Determines if aCapabilityPermissionobject "implies" the specified permission.(package private) booleanimplies0(CapabilityPermission requested, int effective)Internal implies method.java.security.PermissionCollectionnewPermissionCollection()Returns a newPermissionCollectionobject for storingCapabilityPermissionobjects.private static intparseActions(java.lang.String actions)Parse action string into action mask.private static FilterparseFilter(java.lang.String filterString)Parse filter string into a Filter object.private voidreadObject(java.io.ObjectInputStream s)readObject is called to restore the state of this permission from a stream.private voidsetTransients(java.lang.String name, int mask)Called by constructors and when deserialized.private voidwriteObject(java.io.ObjectOutputStream s)WriteObject is called to save the state of this permission to a stream.
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
REQUIRE
public static final java.lang.String REQUIRE
The action stringrequire.- See Also:
- Constant Field Values
-
PROVIDE
public static final java.lang.String PROVIDE
The action stringprovide.- See Also:
- Constant Field Values
-
ACTION_REQUIRE
private static final int ACTION_REQUIRE
- See Also:
- Constant Field Values
-
ACTION_PROVIDE
private static final int ACTION_PROVIDE
- See Also:
- Constant Field Values
-
ACTION_ALL
private static final int ACTION_ALL
- See Also:
- Constant Field Values
-
ACTION_NONE
static final int ACTION_NONE
- 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.
-
attributes
final transient java.util.Map<java.lang.String,java.lang.Object> attributes
The attributes of the requested capability. Must be null if not constructed with attributes.
-
bundle
final transient Bundle bundle
The bundle of the requested capability. Must be null if not constructed with bundle.
-
filter
transient Filter filter
If this CapabilityPermission 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
-
CapabilityPermission
public CapabilityPermission(java.lang.String name, java.lang.String actions)Create a new CapabilityPermission.The name is specified as a dot-separated string. Wildcards may be used.
name ::= <namespace> | <namespace ending in ".*"> | *
Examples:com.acme.capability.* org.foo.capability *
For therequireaction, the name can also be a filter expression. The filter gives access to the capability attributes as well as the following attributes:- signer - A Distinguished Name chain used to sign the bundle providing the capability. 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 providing the capability.
- id - The bundle ID of the bundle providing the capability.
- name - The symbolic name of the bundle providing the capability.
- capability.namespace - The namespace of the required capability.
There are two possible actions:
requireandprovide. Therequirepermission allows the owner of this permission to require a capability matching the attributes. Theprovidepermission allows the bundle to provide a capability in the specified capability namespace.- Parameters:
name- The capability namespace or a filter over the attributes.actions-require,provide(canonical order)- Throws:
java.lang.IllegalArgumentException- If the specified name is a filter expression and either the specified action is notrequireor the filter has an invalid syntax.
-
CapabilityPermission
public CapabilityPermission(java.lang.String namespace, java.util.Map<java.lang.String,?> attributes, Bundle providingBundle, java.lang.String actions)Creates a new requestedCapabilityPermissionobject to be used by code that must performcheckPermissionfor therequireaction.CapabilityPermissionobjects created with this constructor cannot be added to aCapabilityPermissionpermission collection.- Parameters:
namespace- The requested capability namespace.attributes- The requested capability attributes.providingBundle- The bundle providing the requested capability.actions- The actionrequire.- Throws:
java.lang.IllegalArgumentException- If the specified action is notrequireor attributes or providingBundle arenull.
-
CapabilityPermission
CapabilityPermission(java.lang.String name, int mask)Package private constructor used by CapabilityPermissionCollection.- Parameters:
name- class namemask- 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
nullis returned. - Throws:
java.lang.IllegalArgumentException- If the filter syntax is invalid.
-
implies
public boolean implies(java.security.Permission p)
Determines if aCapabilityPermissionobject "implies" the specified permission.- Overrides:
impliesin classjava.security.BasicPermission- Parameters:
p- The target permission to check.- Returns:
trueif the specified permission is implied by this object;falseotherwise.
-
implies0
boolean implies0(CapabilityPermission requested, int effective)
Internal implies method. Used by the implies and the permission collection implies methods.- Parameters:
requested- The requested CapabilityPermission which has already be validated as a proper argument. The requested CapabilityPermission must not have a filter expression.effective- The effective actions with which to start.- Returns:
trueif the specified permission is implied by this object;falseotherwise.
-
getActions
public java.lang.String getActions()
Returns the canonical string representation of the actions. Always returns present actions in the following order:require,provide.- Overrides:
getActionsin classjava.security.BasicPermission- Returns:
- The canonical string representation of the actions.
-
newPermissionCollection
public java.security.PermissionCollection newPermissionCollection()
Returns a newPermissionCollectionobject for storingCapabilityPermissionobjects.- Overrides:
newPermissionCollectionin classjava.security.BasicPermission- Returns:
- A new
PermissionCollectionobject suitable for storingCapabilityPermissionobjects.
-
equals
public boolean equals(java.lang.Object obj)
Determines the equality of two CapabilityPermission objects. Checks that specified object has the same name and action as thisCapabilityPermission.- Overrides:
equalsin classjava.security.BasicPermission- Parameters:
obj- The object to test for equality.- Returns:
- true if obj is a
CapabilityPermission, and has the same name and actions as thisCapabilityPermissionobject;falseotherwise.
-
hashCode
public int hashCode()
Returns the hash code value for this object.- Overrides:
hashCodein classjava.security.BasicPermission- Returns:
- Hash code value for this object.
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOExceptionWriteObject 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.ClassNotFoundExceptionreadObject is called to restore the state of this permission from a stream.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
getProperties
private java.util.Map<java.lang.String,java.lang.Object> getProperties()
Called byimplies(Permission). This method is only called on a requested permission which cannot have a filter set.- Returns:
- a map of properties for this permission.
-
-