use of org.forgerock.json.resource.PatchRequest in project OpenAM by OpenRock.
the class AuditRestRouteProvider method addResourceRoutes.
@Override
public void addResourceRoutes(ResourceRouter rootRouter, ResourceRouter realmRouter) {
rootRouter.route("global-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).toRequestHandler(STARTS_WITH, auditServiceProvider.getDefaultAuditService());
rootRouter.route("realm-audit").auditAs(AUDIT, AuditEndpointAuditFilter.class).authorizeWith(SpecialOrAdminOrAgentAuthzModule.class).forVersion(1).through(RealmContextFilter.class).toRequestHandler(STARTS_WITH, new RequestHandler() {
@Override
public Promise<ActionResponse, ResourceException> handleAction(Context context, ActionRequest actionRequest) {
return getAuditService(context).handleAction(context, actionRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleCreate(Context context, CreateRequest createRequest) {
return getAuditService(context).handleCreate(context, createRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context context, DeleteRequest deleteRequest) {
return getAuditService(context).handleDelete(context, deleteRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handlePatch(Context context, PatchRequest patchRequest) {
return getAuditService(context).handlePatch(context, patchRequest);
}
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest queryRequest, QueryResourceHandler queryResourceHandler) {
return getAuditService(context).handleQuery(context, queryRequest, queryResourceHandler);
}
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest readRequest) {
return getAuditService(context).handleRead(context, readRequest);
}
@Override
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest updateRequest) {
return getAuditService(context).handleUpdate(context, updateRequest);
}
private AMAuditService getAuditService(Context context) {
String realm = context.asContext(RealmContext.class).getResolvedRealm();
if (StringUtils.isEmpty(realm)) {
logger.warn("Context contained RealmContext but had an empty resolved realm");
return auditServiceProvider.getDefaultAuditService();
}
return auditServiceProvider.getAuditService(realm);
}
});
}
use of org.forgerock.json.resource.PatchRequest in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method testFilterPatch.
@Test(dataProvider = "factories")
public void testFilterPatch(UmaProviderSettingsFactory factory, boolean expectFailure) throws Exception {
// Given
UmaEnabledFilter filter = new UmaEnabledFilter(factory);
PatchRequest request = Requests.newPatchRequest("test", "test");
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterPatch(context, request, requestHandler);
// Then
checkResult(expectFailure, promise);
if (expectFailure) {
verifyNoMoreInteractions(requestHandler);
} else {
verify(requestHandler).handlePatch(context, request);
}
}
use of org.forgerock.json.resource.PatchRequest 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.PatchRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForPatchSuccess.
@Test
public void shouldReturnNullForPatchSuccess() {
PatchRequest patchRequest = mock(PatchRequest.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
JsonValue filterResponse = auditFilter.getPatchSuccessDetail(patchRequest, resourceResponse);
assertThat(filterResponse).isEqualTo(null);
}
use of org.forgerock.json.resource.PatchRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterPatch.
@Override
public Promise<ResourceResponse, ResourceException> filterPatch(Context context, PatchRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
PatchRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfPatchRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handlePatch(evaluate(context, request), evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
Aggregations