use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterAction.
@Override
public Promise<ActionResponse, ResourceException> filterAction(Context context, ActionRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
ActionRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfActionRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleAction(evaluate(context, request), evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestActionEvaluateIsAllowed.
@Test
public void crestActionEvaluateIsAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("READ"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "evaluate", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "evaluate", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
JsonValue jsonValue = json(object(field("someKey", "someValue")));
Promise<ActionResponse, ResourceException> promise = Promises.newResultPromise(Responses.newActionResponse(jsonValue));
given(provider.actionCollection(isA(Context.class), isA(ActionRequest.class))).willReturn(promise);
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final RealmContext context = new RealmContext(subjectContext);
context.setSubRealm("abc", "abc");
final ActionRequest request = Requests.newActionRequest("/policies", "evaluate");
Promise<ActionResponse, ResourceException> result = router.handleAction(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestActionBlowupIsAllowed.
@Test
public void crestActionBlowupIsAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "destroy", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "destroy", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
JsonValue jsonValue = json(object(field("someKey", "someValue")));
Promise<ActionResponse, ResourceException> promise = Promises.newResultPromise(Responses.newActionResponse(jsonValue));
given(provider.actionCollection(isA(Context.class), isA(ActionRequest.class))).willReturn(promise);
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final RealmContext context = new RealmContext(subjectContext);
context.setSubRealm("abc", "abc");
final ActionRequest request = Requests.newActionRequest("/policies", "blowup");
Promise<ActionResponse, ResourceException> result = router.handleAction(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForActionSuccess.
@Test
public void shouldReturnNullForActionSuccess() {
ActionRequest actionRequest = mock(ActionRequest.class);
ActionResponse actionResponse = mock(ActionResponse.class);
JsonValue filterResponse = auditFilter.getActionSuccessDetail(actionRequest, actionResponse);
assertThat(filterResponse).isEqualTo(null);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PoliciesAuditFilterTest method shouldReturnJsonDetailForActionSuccess.
@Test
public void shouldReturnJsonDetailForActionSuccess() {
JsonValue jsonValue = new JsonValue("Test string");
ActionResponse actionResponse = Responses.newActionResponse(jsonValue);
ActionRequest actionRequest = mock(ActionRequest.class);
JsonValue filterResponse = auditFilter.getActionSuccessDetail(actionRequest, actionResponse);
assertThat(filterResponse).isEqualTo(jsonValue);
}
Aggregations