Search in sources :

Example 1 with CreateRequest

use of org.forgerock.json.resource.CreateRequest 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 2 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class AuditEventPublisherImpl method publishForRealm.

private void publishForRealm(String realm, String topic, AuditEvent auditEvent) throws ResourceException {
    AMAuditService auditService = auditServiceProvider.getAuditService(realm);
    Connection connection = newInternalConnection(auditService);
    CreateRequest request = newCreateRequest(topic, auditEvent.getValue());
    try {
        connection.create(new RootContext(), request);
    } catch (ServiceUnavailableException e) {
        debug.message("Audit Service for realm {} is unavailable. Trying the default Audit Service.", realm, e);
        publishToDefault(topic, auditEvent);
    }
}
Also used : RootContext(org.forgerock.services.context.RootContext) CreateRequest(org.forgerock.json.resource.CreateRequest) Requests.newCreateRequest(org.forgerock.json.resource.Requests.newCreateRequest) Connection(org.forgerock.json.resource.Connection) Resources.newInternalConnection(org.forgerock.json.resource.Resources.newInternalConnection) ServiceUnavailableException(org.forgerock.json.resource.ServiceUnavailableException)

Example 3 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class CoreTokenResourceTest method shouldCreateTokenInCTS.

@Test
public void shouldCreateTokenInCTS() throws CoreTokenException {
    // Given
    CreateRequest request = mock(CreateRequest.class);
    given(request.getContent()).willReturn(new JsonValue(""));
    given(mockSerialisation.deserialise(anyString(), Matchers.<Class<Object>>any())).willReturn(mockToken);
    // When
    resource.createInstance(null, request);
    // Then
    verify(mockStore).createAsync(mockToken);
}
Also used : CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 4 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class CoreTokenResourceTest method shouldGetBadRequestForMissingTokenId.

@Test
public void shouldGetBadRequestForMissingTokenId() throws CoreTokenException {
    // Given
    CreateRequest request = mock(CreateRequest.class);
    given(request.getContent()).willReturn(new JsonValue(""));
    doThrow(IllegalArgumentException.class).when(mockStore).createAsync(any(Token.class));
    // When
    Promise<ResourceResponse, ResourceException> promise = resource.createInstance(null, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) Token(org.forgerock.openam.cts.api.tokens.Token) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 5 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class PolicyResourceTest method shouldReportCreatePolicyStoreErrors.

@Test
public void shouldReportCreatePolicyStoreErrors() throws Exception {
    // Given
    String id = "uniqueId";
    JsonValue json = new JsonValue("");
    CreateRequest request = mockCreateRequest(id, json);
    Privilege policy = mockPrivilege(id, 123l);
    given(mockParser.parsePolicy(id, json)).willReturn(policy);
    willThrow(new EntitlementException(EntitlementException.INVALID_APPLICATION_CLASS)).given(mockStore).create(policy);
    // When
    Promise<ResourceResponse, ResourceException> promise = policyResource.createInstance(mockServerContext, request);
    // Then
    assertThat(promise).failedWithException().isInstanceOf(InternalServerErrorException.class);
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Aggregations

CreateRequest (org.forgerock.json.resource.CreateRequest)70 Test (org.testng.annotations.Test)62 ResourceResponse (org.forgerock.json.resource.ResourceResponse)42 JsonValue (org.forgerock.json.JsonValue)39 ResourceException (org.forgerock.json.resource.ResourceException)38 Context (org.forgerock.services.context.Context)27 DeleteRequest (org.forgerock.json.resource.DeleteRequest)19 ReadRequest (org.forgerock.json.resource.ReadRequest)18 RootContext (org.forgerock.services.context.RootContext)18 UriRouterContext (org.forgerock.http.routing.UriRouterContext)17 ActionRequest (org.forgerock.json.resource.ActionRequest)17 PatchRequest (org.forgerock.json.resource.PatchRequest)17 QueryRequest (org.forgerock.json.resource.QueryRequest)17 UpdateRequest (org.forgerock.json.resource.UpdateRequest)17 Request (org.forgerock.http.protocol.Request)16 AttributesContext (org.forgerock.services.context.AttributesContext)16 Subject (javax.security.auth.Subject)13 RealmContext (org.forgerock.openam.rest.RealmContext)11 EntitlementException (com.sun.identity.entitlement.EntitlementException)9 ResourceType (org.forgerock.openam.entitlement.ResourceType)9