use of org.forgerock.json.resource.ActionRequest 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.ActionRequest in project OpenAM by OpenRock.
the class PendingRequestResourceTest method actionCollectionShouldHandleDenyAction.
@SuppressWarnings("unchecked")
@Test
public void actionCollectionShouldHandleDenyAction() throws Exception {
//Given
Context context = mockContext("REALM");
ActionRequest request = Requests.newActionRequest("", "deny");
mockPendingRequestsForUser("alice", "REALM", 2);
//When
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
//Then
verify(service, times(2)).denyPendingRequest(anyString(), anyString());
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PendingRequestResourceTest method actionInstanceShouldHandleApproveAction.
@SuppressWarnings("unchecked")
@Test
public void actionInstanceShouldHandleApproveAction() throws Exception {
//Given
Context context = mockContext("REALM");
ActionRequest request = Requests.newActionRequest("", "approve");
mockPendingRequestsForUser("alice", "REALM", 1);
mockPendingRequestApprovalService();
//When
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
//Then
verify(service).approvePendingRequest(eq(context), anyString(), any(JsonValue.class), anyString());
assertThat(promise).succeeded();
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class PendingRequestResourceTest method actionCollectionShouldReturnNotSupportedExceptionForUnsupportedAction.
@SuppressWarnings("unchecked")
@Test
public void actionCollectionShouldReturnNotSupportedExceptionForUnsupportedAction() {
//Given
Context context = mock(Context.class);
ActionRequest request = Requests.newActionRequest("", "other");
//When
Promise<ActionResponse, ResourceException> promise = resource.actionCollection(context, request);
//Then
assertThat(promise).failedWithResourceException().isInstanceOf(NotSupportedException.class);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class UmaEnabledFilterTest method testFilterAction.
@Test(dataProvider = "factories")
public void testFilterAction(UmaProviderSettingsFactory factory, boolean expectFailure) throws Exception {
// Given
UmaEnabledFilter filter = new UmaEnabledFilter(factory);
ActionRequest request = Requests.newActionRequest("test", "test", "test");
// When
Promise<ActionResponse, ResourceException> promise = filter.filterAction(context, request, requestHandler);
// Then
checkResult(expectFailure, promise);
if (expectFailure) {
verifyNoMoreInteractions(requestHandler);
} else {
verify(requestHandler).handleAction(context, request);
}
}
Aggregations