use of org.forgerock.json.resource.UpdateRequest 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.UpdateRequest in project OpenAM by OpenRock.
the class PolicyV1FilterTest method resourceTypeAssociationOnUpdate.
/**
* Verifies that the appropriate resource type is associated with the policy being updated.
*/
@Test
public void resourceTypeAssociationOnUpdate() throws Exception {
// Given
given(contextHelper.getRealm(context)).willReturn("/abc");
given(contextHelper.getSubject(context)).willReturn(subject);
UpdateRequest updateRequest = mock(UpdateRequest.class);
JsonValue jsonValue = json(object(field("applicationName", "testApp")));
given(updateRequest.getContent()).willReturn(jsonValue);
given(applicationServiceFactory.create(subject, "/abc")).willReturn(applicationService);
Application application = mock(Application.class);
given(applicationService.getApplication("testApp")).willReturn(application);
Set<String> resourceTypeUUIDs = new HashSet<>(CollectionUtils.asSet("abc-def-hij"));
given(application.getResourceTypeUuids()).willReturn(resourceTypeUUIDs);
// When
Promise<ResourceResponse, ResourceException> promise = filter.filterUpdate(context, updateRequest, requestHandler);
// Then
assertThat(promise).succeeded();
verify(applicationServiceFactory).create(subject, "/abc");
verify(applicationService).getApplication("testApp");
assertThat(jsonValue.get("resourceTypeUuid").asString()).isEqualTo("abc-def-hij");
assertThat(promise.get().getContent().contains("resourceTypeUuid")).isFalse();
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class RealmContextFilter method filterUpdate.
@Override
public Promise<ResourceResponse, ResourceException> filterUpdate(Context context, UpdateRequest request, RequestHandler next) {
try {
Context newContext = evaluate(context, request);
UpdateRequest evaluatedRequest = wasEvaluated(context, newContext) ? copyOfUpdateRequest(request).setResourcePath(newContext.asContext(UriRouterContext.class).getRemainingUri()) : request;
return next.handleUpdate(newContext, evaluatedRequest);
} catch (ResourceException e) {
return newExceptionPromise(e);
}
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method updateInstanceShouldReturnServerInternalExceptionWhenApplicationToJson.
@Test(expectedExceptions = InternalServerErrorException.class)
public void updateInstanceShouldReturnServerInternalExceptionWhenApplicationToJson() throws EntitlementException, ResourceException {
//Given
SSOTokenContext subjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm("REALM", "REALM");
Context context = ClientContext.newInternalClientContext(realmContext);
String resourceId = "iPlanetAMWebAgentService";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = new Subject();
JsonValue content = mock(JsonValue.class);
Application application = mock(Application.class);
Application newApplication = mock(Application.class);
given(subjectContext.getCallerSubject()).willReturn(subject);
given(request.getContent()).willReturn(content);
given(applicationManagerWrapper.getApplication(subject, "/REALM", resourceId)).willReturn(application);
given(applicationWrapper.getName()).willReturn("APP_NAME");
given(applicationWrapper.getApplication()).willReturn(newApplication);
given(newApplication.getLastModifiedDate()).willReturn(1000L);
doThrow(new EntitlementException(1)).when(applicationWrapper).toJsonValue();
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
verify(applicationManagerWrapper).updateApplication(application, applicationWrapper.getApplication(), subject, "/REALM");
result.getOrThrowUninterruptibly();
}
use of org.forgerock.json.resource.UpdateRequest in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldNotUpdateInstanceWhenSubjectIsNull.
@Test(expectedExceptions = BadRequestException.class)
public void shouldNotUpdateInstanceWhenSubjectIsNull() throws EntitlementException, ResourceException {
//Given
SSOTokenContext subjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm("REALM", "REALM");
Context context = ClientContext.newInternalClientContext(realmContext);
String resourceId = "RESOURCE_ID";
UpdateRequest request = mock(UpdateRequest.class);
Subject subject = null;
given(subjectContext.getCallerSubject()).willReturn(subject);
//When
Promise<ResourceResponse, ResourceException> result = applicationsResource.updateInstance(context, resourceId, request);
//Then
result.getOrThrowUninterruptibly();
}
Aggregations