Skip to content

Commit

Permalink
[HQ-1861] Handle permission exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen committed Sep 15, 2009
1 parent 833c617 commit 4cff0bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
20 changes: 12 additions & 8 deletions hqu/hqapi1/app/ControlController.groovy
@@ -1,5 +1,5 @@
import org.hyperic.hq.hqapi1.ErrorCode;
import org.hyperic.hq.control.server.session.ControlScheduleManagerEJBImpl as CMan
import org.hyperic.hq.authz.shared.PermissionException
import org.hyperic.util.pager.PageControl

class ControlController extends ApiController {
Expand Down Expand Up @@ -35,8 +35,11 @@ class ControlController extends ApiController {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
// TODO: Seems that permissions are not applied here. XXX: need test
actions = resource.getControlActions(user)
try {
actions = resource.getControlActions(user)
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}
}

renderXml() {
Expand Down Expand Up @@ -64,10 +67,11 @@ class ControlController extends ApiController {
failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
"Resource id " + resourceId + " not found")
} else {
// TODO: This needs to be pulled into ResourceHelper
def cMan = CMan.one
history = cMan.findJobHistory(user, resource.entityId,
PageControl.PAGE_ALL)
try {
history = resource.getControlHistory(user)
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
}
}

renderXml() {
Expand Down Expand Up @@ -104,7 +108,7 @@ class ControlController extends ApiController {
failureXml = getFailureXML(ErrorCode.NOT_SUPPORTED,
"Resource id " + resourceId +
" does not support action " + action)
} catch (org.hyperic.hq.authz.shared.PermissionException e) {
} catch (PermissionException e) {
failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
} catch (Exception e) {
failureXml = getFailureXML(ErrorCode.UNEXPECTED_ERROR,
Expand Down
5 changes: 2 additions & 3 deletions src/org/hyperic/hq/hqapi1/test/ControlAction_test.java
Expand Up @@ -80,7 +80,7 @@ public void testControlActionValidResource() throws Exception {
cleanupControllableResource(api, controllableResource);
}

public void testControlActionNoPermissio() throws Exception {
public void testControlActionNoPermission() throws Exception {
HQApi api = getApi();
Resource controllableResource = createControllableResource(api);

Expand All @@ -91,8 +91,7 @@ public void testControlActionNoPermissio() throws Exception {
ControlApi cApi = apiUnpriv.getControlApi();

ControlActionResponse response = cApi.getActions(controllableResource);
// TODO: This should fail!
hqAssertSuccess(response);
hqAssertFailurePermissionDenied(response);

deleteTestUsers(users);
cleanupControllableResource(api, controllableResource);
Expand Down

0 comments on commit 4cff0bd

Please sign in to comment.