Handling Security
The repository framework uses permissions and access control lists (ACLs) to prevent unauthorized access to resources. Permissions define the actions that are allowed on a resource and are stored in the access control lists which are associated with resources. The repository framework automatically checks permissions before allowing the execution of an operation on a resource. Therefore a client application generally does no have to take care of any security checks. However there are two situations where it might be an advantage for the client to intervene:
- After an attempt to execute an action
If an AccessDeniedException is thrown because a user does not have the permissions required for an operation, the client application can respond with an appropriate action.
- Before an attempt to execute an action
If an application wants to find out whether an action is permissible before it is attempted, it can use the isAllowed() method of the ISecurityManager. Otherwise, it can only find out whether an action is permissible after it has been attempted.
The code extract shows how an application can respond to the AccessDeniedException by displaying the missing permission and the user involved. All operations on IResource objects, except getRID(), require permissions.
// retrieval requires no permission
IResource resource = ResourceFactory.getInstance()
.getResource(RID.getRID(″/documents/myResource″), context);
if( resource != null ) {
//resource exists
try {
resource.delete(); // request delete operation for resource delete()
}
catch( AccessDeniedException e ) {
// show some message to the user
System.out.println(
e.getPermissionName() + ″ not granted for ″ +
+ e.getUserID() + ″ on ″
+ e.getRID().name()
);
}
}