Package org.osgi.framework
Class ServicePermission
java.lang.Object
java.security.Permission
java.security.BasicPermission
org.osgi.framework.ServicePermission
- All Implemented Interfaces:
Serializable,Guard
A bundle's authority to register or get a service.
- The
registeraction allows a bundle to register a service on the specified names. - The
getaction allows a bundle to detect a service and get it.
ServicePermission
to get the specific service.- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final int(package private) intThe actions mask.(package private) static final intprivate static final intprivate StringThe actions in canonical form.(package private) FilterIf this ServicePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies.static final StringThe action stringget.(package private) final String[]The object classes for this ServicePermission.private StringIf constructed with a name and the name ends with ".*", this contains the name without the final "*".This map holds the properties of the permission, used to match a filter in implies.static final StringThe action stringregister.(package private) static final long(package private) final ServiceReference<?>The service used by this ServicePermission.private booleanTrue if constructed with a name and the name is "*" or ends with ".*". -
Constructor Summary
ConstructorsConstructorDescriptionServicePermission(String name, int mask) Package private constructor used by ServicePermissionCollection.ServicePermission(String name, String actions) Create a new ServicePermission.ServicePermission(ServiceReference<?> reference, String actions) Creates a new requestedServicePermissionobject to be used by code that must performcheckPermissionfor thegetaction. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringcreateName(ServiceReference<?> reference) Create a permission name from a ServiceReferencebooleanDetermines the equality of two ServicePermission objects.Returns the canonical string representation of the actions.Called byimplies(Permission).inthashCode()Returns the hash code value for this object.booleanDetermines if aServicePermissionobject "implies" the specified permission.(package private) booleanimplies0(ServicePermission requested, int effective) Internal implies method.Returns a newPermissionCollectionobject for storingServicePermissionobjects.private static intparseActions(String actions) Parse action string into action mask.private static FilterparseFilter(String filterString) Parse filter string into a Filter object.private voidreadObject is called to restore the state of this permission from a stream.private voidsetTransients(Filter f, int mask) Called by constructors and when deserialized.private voidWriteObject is called to save the state of this permission to a stream.Methods inherited from class java.security.Permission
checkGuard, getName, toString
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
GET
The action stringget.- See Also:
-
REGISTER
The action stringregister.- See Also:
-
ACTION_GET
private static final int ACTION_GET- See Also:
-
ACTION_REGISTER
private static final int ACTION_REGISTER- See Also:
-
ACTION_ALL
private static final int ACTION_ALL- See Also:
-
ACTION_NONE
static final int ACTION_NONE- See Also:
-
action_mask
transient int action_maskThe actions mask. -
actions
The actions in canonical form. -
service
The service used by this ServicePermission. Must be null if not constructed with a service. -
objectClass
The object classes for this ServicePermission. Must be null if not constructed with a service. -
filter
If this ServicePermission was constructed with a filter, this holds a Filter matching object used to evaluate the filter in implies. -
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. -
wildcard
private transient boolean wildcardTrue if constructed with a name and the name is "*" or ends with ".*". -
prefix
If constructed with a name and the name ends with ".*", this contains the name without the final "*".
-
-
Constructor Details
-
ServicePermission
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 thegetaction, 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.
There are two possible actions:
getandregister. Thegetpermission allows the owner of this permission to obtain a service with this name. Theregisterpermission allows the bundle to register a service under that name.- Parameters:
name- The service class nameactions-get,register(canonical order)- Throws:
IllegalArgumentException- If the specified name is a filter expression and either the specified action is notgetor the filter has an invalid syntax.
-
ServicePermission
Creates a new requestedServicePermissionobject to be used by code that must performcheckPermissionfor thegetaction.ServicePermissionobjects created with this constructor cannot be added to aServicePermissionpermission collection.- Parameters:
reference- The requested service.actions- The actionget.- Throws:
IllegalArgumentException- If the specified action is notgetor reference isnull.- Since:
- 1.5
-
ServicePermission
ServicePermission(String name, int mask) Package private constructor used by ServicePermissionCollection.- Parameters:
name- class namemask- action mask
-
-
Method Details
-
createName
Create a permission name from a ServiceReference- Parameters:
reference- ServiceReference to use to create permission name.- Returns:
- permission name.
-
setTransients
Called by constructors and when deserialized.- Parameters:
mask- action mask
-
parseActions
Parse action string into action mask.- Parameters:
actions- Action string.- Returns:
- action mask.
-
parseFilter
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:
IllegalArgumentException- If the filter syntax is invalid.
-
implies
Determines if aServicePermissionobject "implies" the specified permission.- Overrides:
impliesin classBasicPermission- Parameters:
p- The target permission to check.- Returns:
trueif the specified permission is implied by this object;falseotherwise.
-
implies0
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:
trueif the specified permission is implied by this object;falseotherwise.
-
getActions
Returns the canonical string representation of the actions. Always returns present actions in the following order:get,register.- Overrides:
getActionsin classBasicPermission- Returns:
- The canonical string representation of the actions.
-
newPermissionCollection
Returns a newPermissionCollectionobject for storingServicePermissionobjects.- Overrides:
newPermissionCollectionin classBasicPermission- Returns:
- A new
PermissionCollectionobject suitable for storingServicePermissionobjects.
-
equals
Determines the equality of two ServicePermission objects. Checks that specified object has the same class name and action as thisServicePermission.- Overrides:
equalsin classBasicPermission- Parameters:
obj- The object to test for equality.- Returns:
- true if obj is a
ServicePermission, and has the same class name and actions as thisServicePermissionobject;falseotherwise.
-
hashCode
public int hashCode()Returns the hash code value for this object.- Overrides:
hashCodein classBasicPermission- Returns:
- Hash code value for this object.
-
writeObject
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:
IOException
-
readObject
readObject is called to restore the state of this permission from a stream.- Throws:
IOExceptionClassNotFoundException
-
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.
-