use of org.forgerock.json.resource.DeleteRequest 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.DeleteRequest in project OpenAM by OpenRock.
the class TrustedDevicesResourceTest method shouldDeleteTrustedDevice.
@Test
public void shouldDeleteTrustedDevice() throws ResourceException {
//Given
DeleteRequest request = Requests.newDeleteRequest("UUID_1");
Connection connection = newInternalConnection(newCollection(resource));
List<JsonValue> devices = new ArrayList<JsonValue>();
devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
//When
connection.delete(ctx(), request);
//Then
ArgumentCaptor<List> devicesCaptor = ArgumentCaptor.forClass(List.class);
verify(dao).saveDeviceProfiles(anyString(), anyString(), devicesCaptor.capture());
assertThat(devicesCaptor.getValue()).hasSize(1);
}
use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldNotDeleteTrustedDeviceWhenNotFound.
@Test
public void shouldNotDeleteTrustedDeviceWhenNotFound() throws ResourceException, SSOException {
// Given
DeleteRequest request = Requests.newDeleteRequest("UUID_3");
List<JsonValue> devices = new ArrayList<JsonValue>();
devices.add(json(object(field("uuid", "UUID_1"), field("name", "NAME_1"))));
devices.add(json(object(field("uuid", "UUID_2"), field("name", "NAME_2"))));
given(dao.getDeviceProfiles(anyString(), anyString())).willReturn(devices);
// When
Promise<ResourceResponse, ResourceException> promise = resource.deleteInstance(ctx(), request.getResourcePath(), request);
// Then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_FOUND);
}
use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldRejectNullPolicyIdInDelete.
@Test
public void shouldRejectNullPolicyIdInDelete() throws Exception {
// Given
String id = null;
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.json.resource.DeleteRequest in project OpenAM by OpenRock.
the class PolicyResourceTest method shouldReportMissingPoliciesInDelete.
@Test
public void shouldReportMissingPoliciesInDelete() throws Exception {
// Given
String id = "unknown";
DeleteRequest request = mock(DeleteRequest.class);
willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY)).given(mockStore).delete(id);
// When
Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request);
// Then
assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
Aggregations