use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class SessionResourceAuthzModuleTest method shouldAllowValidateAction.
@Test
public void shouldAllowValidateAction() throws ExecutionException, InterruptedException {
//given
Context mockContext = mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("validate");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
//then
assertTrue(result.get().isAuthorized());
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method shouldFailDifferentOwnerQueryParamToken.
@Test
public void shouldFailDifferentOwnerQueryParamToken() throws SSOException, ExecutionException, InterruptedException, BadRequestException {
//given
ActionRequest request = Requests.newActionRequest("resource", "deleteProperty");
request.setAdditionalParameter("tokenId", "token");
given(mockService.isSuperUser(eq("universal_id"))).willReturn(false);
given(mockService.isSuperUser(eq("john"))).willReturn(false);
Context otherContext = setupUser("john");
setupUser("universal_id");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(otherContext, request);
//then
assertThat(result).failedWithException().isInstanceOf(ForbiddenException.class);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method shouldAllowValidQueryParamToken.
@Test
public void shouldAllowValidQueryParamToken() throws SSOException, ExecutionException, InterruptedException, BadRequestException {
//given
ActionRequest request = Requests.newActionRequest("resource", "deleteProperty");
request.setAdditionalParameter("tokenId", "token");
given(mockService.isSuperUser(eq("universal_id"))).willReturn(false);
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, request);
//then
assertThat(result).succeeded();
assertTrue(result.get().isAuthorized());
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method forwardOnAction.
/**
* Verify that action requests are forwarded on.
*/
@Test
public void forwardOnAction() throws Exception {
// Given
ActionRequest actionRequest = mock(ActionRequest.class);
// When
Promise<ActionResponse, ResourceException> promise = filter.filterAction(context, actionRequest, requestHandler);
// Then
assertThat(promise).succeeded();
assertThat(promise.get().getJsonContent().contains("ttl")).isFalse();
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PolicyResourceWithCopyMoveSupport method copyOrMoveGivenPolicy.
private ActionResponse copyOrMoveGivenPolicy(Context context, JsonValue policy, String destinationRealm, String destinationApplication, String namePostfix, JsonValue resourceTypeMapping, PolicyAction copyOrMoveAction) throws ResourceException {
String name = policy.get("name").asString();
String copiedName = name + namePostfix;
String sourceResourceType = policy.get("resourceTypeUuid").asString();
String destinationResourceType = resourceTypeMapping.get(sourceResourceType).defaultTo(sourceResourceType).asString();
JsonValue newPayload = json(object(field("to", object(field("name", copiedName), field("realm", destinationRealm), field("application", destinationApplication), field("resourceType", destinationResourceType)))));
String copyOrMoveActionName = copyOrMoveAction.name().toLowerCase();
ActionRequest newActionRequest = Requests.newActionRequest("policies", name, copyOrMoveActionName);
newActionRequest.setContent(newPayload);
return router.handleAction(context, newActionRequest).getOrThrowUninterruptibly();
}
Aggregations