Search in sources :

Example 21 with ActionRequest

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);
        }
    });
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) QueryRequest(org.forgerock.json.resource.QueryRequest) AuditEndpointAuditFilter(org.forgerock.openam.rest.fluent.AuditEndpointAuditFilter) UpdateRequest(org.forgerock.json.resource.UpdateRequest) CreateRequest(org.forgerock.json.resource.CreateRequest) AMAuditService(org.forgerock.openam.audit.AMAuditService) PatchRequest(org.forgerock.json.resource.PatchRequest) Promise(org.forgerock.util.promise.Promise) RequestHandler(org.forgerock.json.resource.RequestHandler) ActionRequest(org.forgerock.json.resource.ActionRequest) RealmContextFilter(org.forgerock.openam.rest.RealmContextFilter) SpecialOrAdminOrAgentAuthzModule(org.forgerock.openam.rest.authz.SpecialOrAdminOrAgentAuthzModule) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) DeleteRequest(org.forgerock.json.resource.DeleteRequest) ReadRequest(org.forgerock.json.resource.ReadRequest)

Example 22 with ActionRequest

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();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 23 with ActionRequest

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();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 24 with ActionRequest

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);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 25 with ActionRequest

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);
    }
}
Also used : ActionRequest(org.forgerock.json.resource.ActionRequest) ResourceException(org.forgerock.json.resource.ResourceException) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Aggregations

ActionRequest (org.forgerock.json.resource.ActionRequest)44 Test (org.testng.annotations.Test)39 ResourceException (org.forgerock.json.resource.ResourceException)31 ActionResponse (org.forgerock.json.resource.ActionResponse)28 Context (org.forgerock.services.context.Context)23 JsonValue (org.forgerock.json.JsonValue)12 RealmContext (org.forgerock.openam.rest.RealmContext)10 BeforeTest (org.testng.annotations.BeforeTest)8 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)6 Router (org.forgerock.json.resource.Router)4 Matchers.anyString (org.mockito.Matchers.anyString)4 FilterChain (org.forgerock.json.resource.FilterChain)3 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)3 RootContext (org.forgerock.services.context.RootContext)3 DelegationPermission (com.sun.identity.delegation.DelegationPermission)2 HashSet (java.util.HashSet)2 Requests.newActionRequest (org.forgerock.json.resource.Requests.newActionRequest)2 SSOException (com.iplanet.sso.SSOException)1 UriRouterContext (org.forgerock.http.routing.UriRouterContext)1 CreateRequest (org.forgerock.json.resource.CreateRequest)1