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 SessionResourceAuthzModuleTest method shouldAllowLogoutAction.
@Test
public void shouldAllowLogoutAction() throws ExecutionException, InterruptedException {
//given
Context mockContext = mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("logout");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
//then
assertTrue(result.get().isAuthorized());
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class OathDevicesResourceTest method shouldFailOnUnknownActionInstance.
@Test
public void shouldFailOnUnknownActionInstance() throws ResourceException, SSOException {
// given
ActionRequest actionRequest = mock(ActionRequest.class);
// when
Promise<ActionResponse, ResourceException> promise = resource.actionInstance(ctx(), "", actionRequest);
// then
assertThat(promise).failedWithResourceException().withCode(ResourceException.NOT_SUPPORTED);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method shouldFailInvalidQueryParamToken.
@Test
public void shouldFailInvalidQueryParamToken() throws SSOException, ExecutionException, InterruptedException, BadRequestException {
//given
ActionRequest request = Requests.newActionRequest("resource", "deleteProperty");
request.setAdditionalParameter("tokenId", "token");
given(mockService.isSuperUser(eq("universal_id"))).willReturn(false);
given(mockTokenManager.createSSOToken(eq("token"))).willThrow(new SSOException(""));
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, request);
//then
assertThat(result).failedWithException().isInstanceOf(ForbiddenException.class);
}
use of org.forgerock.json.resource.ActionRequest in project OpenAM by OpenRock.
the class Requester method action.
/**
* Request to perform an action at a specified endpoint.
*
* @param location Endpoint destination of this request. May not be null.
* @param resourceId Specific resource ID to perform action on. May be null.
* @param actionId act ID to delete. May not be null.
* @param context Context of this request.
* @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
* @throws ResourceException If any exception occurred during processing.
*/
public JsonValue action(String location, String resourceId, String actionId, JsonValue payload, Context context) throws ResourceException {
Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
Reject.ifTrue(StringUtils.isEmpty(actionId), "The specific action to perform may not be null or empty.");
final Router rootRouter = router.get();
final ActionRequest actionRequest = Requests.newActionRequest(location, actionId);
if (payload != null) {
actionRequest.setContent(payload);
}
if (resourceId != null) {
actionRequest.setResourcePath(resourceId);
}
return rootRouter.handleAction(context, actionRequest).getOrThrowUninterruptibly().getJsonContent();
}
Aggregations