use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestPatchIsAllowed.
@Test
public void crestPatchIsAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", 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<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
given(provider.patchInstance(isA(Context.class), eq("123"), isA(PatchRequest.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 PatchRequest request = Requests.newPatchRequest("/policies/123", PatchOperation.add("abc", "123"));
Promise<ResourceResponse, ResourceException> result = router.handlePatch(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestRequestNotAllowed.
@Test
public void crestRequestNotAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(false);
// 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 CreateRequest request = Requests.newCreateRequest("/policies", JsonValue.json(new Object()));
Promise<ResourceResponse, ResourceException> promise = router.handleCreate(context, request);
// Then...
assertThat(promise).failedWithException().isInstanceOf(ForbiddenException.class);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class RestRouterIT method shouldBeAbleToReachInternalViaInternalRouter.
@Test
public void shouldBeAbleToReachInternalViaInternalRouter() throws Exception {
// Given
Promise<ResourceResponse, ResourceException> promise = newResultPromise(newResourceResponse("1", "1", json(object())));
given(internalResource.readInstance(any(Context.class), eq("123"), any(ReadRequest.class))).willReturn(promise);
Router internalRouter = InjectorHolder.getInstance(Key.get(Router.class, Names.named("InternalCrestRouter")));
Context context = mockRequiredContexts();
ReadRequest request = Requests.newReadRequest("internal/123");
// When
internalRouter.handleRead(context, request);
// Then
verify(internalResource).readInstance(any(Context.class), eq("123"), any(ReadRequest.class));
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForUpdateSuccess.
@Test
public void shouldReturnNullForUpdateSuccess() {
UpdateRequest updateRequest = mock(UpdateRequest.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
JsonValue filterResponse = auditFilter.getUpdateSuccessDetail(updateRequest, resourceResponse);
assertThat(filterResponse).isEqualTo(null);
}
use of org.forgerock.json.resource.ResourceResponse in project OpenAM by OpenRock.
the class AuditFilterTest method shouldAuditSuccessForResults.
@Test
public void shouldAuditSuccessForResults() throws Exception {
ResourceResponse response = mock(ResourceResponse.class);
Promise<ResourceResponse, ResourceException> myPromise = Promises.newResultPromise(response);
given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
auditFilter.filterUpdate(context, updateRequest, filterChain);
verify(auditor).auditAccessSuccess(null);
}
Aggregations