Interface Authorization
-
public interface AuthorizationTheAuthorizationinterface encapsulates an authorization context on which bundles can base authorization decisions, where appropriate.Bundles associate the privilege to access restricted resources or operations with roles. Before granting access to a restricted resource or operation, a bundle will check if the
Authorizationobject passed to it possess the required role, by calling itshasRolemethod.Authorization contexts are instantiated by calling the
UserAdmin.getAuthorization(User)method.Trusting Authorization objects
There are no restrictions regarding the creation of
Authorizationobjects. Hence, a service must only acceptAuthorizationobjects from bundles that has been authorized to use the service using code based (or Java 2) permissions.In some cases it is useful to use
ServicePermissionto do the code based access control. A service basing user access control onAuthorizationobjects passed to it, will then require that a calling bundle has theServicePermissionto get the service in question. This is the most convenient way. The OSGi environment will do the code based permission check when the calling bundle attempts to get the service from the service registry.Example: A servlet using a service on a user's behalf. The bundle with the servlet must be given the
ServicePermissionto get the Http Service.However, in some cases the code based permission checks need to be more fine-grained. A service might allow all bundles to get it, but require certain code based permissions for some of its methods.
Example: A servlet using a service on a user's behalf, where some service functionality is open to anyone, and some is restricted by code based permissions. When a restricted method is called (e.g., one handing over an
Authorizationobject), the service explicitly checks that the calling bundle has permission to make the call.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringgetName()Gets the name of theUserthat thisAuthorizationcontext was created for.java.lang.String[]getRoles()Gets the names of all roles implied by thisAuthorizationcontext.booleanhasRole(java.lang.String name)Checks if the role with the specified name is implied by thisAuthorizationcontext.
-
-
-
Method Detail
-
getName
java.lang.String getName()
Gets the name of theUserthat thisAuthorizationcontext was created for.- Returns:
- The name of the
Userobject that thisAuthorizationcontext was created for, ornullif no user was specified when thisAuthorizationcontext was created.
-
hasRole
boolean hasRole(java.lang.String name)
Checks if the role with the specified name is implied by thisAuthorizationcontext.Bundles must define globally unique role names that are associated with the privilege of accessing restricted resources or operations. Operators will grant users access to these resources, by creating a
Groupobject for each role and addingUserobjects to it.- Parameters:
name- The name of the role to check for.- Returns:
trueif thisAuthorizationcontext implies the specified role, otherwisefalse.
-
getRoles
java.lang.String[] getRoles()
Gets the names of all roles implied by thisAuthorizationcontext.- Returns:
- The names of all roles implied by this
Authorizationcontext, ornullif no roles are in the context. The predefined roleuser.anyonewill not be included in this list.
-
-