Search in sources :

Example 1 with RequestType

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

the class AuditFilter method getDetail.

/**
     * Provides additional details (e.g. failure description or summary of the payload) relating to the a successful
     * {@link Response} to a {@link Request}. This information is logged in the access audit log.
     *
     * @param request The {@link Request} instance from which details may be taken. Cannot be null.
     * @param response The {@link Response} instance from which details may be taken. Cannot be null.
     * @return {@link JsonValue} free-form details, or null to indicate no details.
     */
private JsonValue getDetail(Request request, Response response) {
    Reject.ifNull(request, "request cannot be null.");
    Reject.ifNull(request, "response cannot be null.");
    RequestType requestType = request.getRequestType();
    switch(requestType) {
        case CREATE:
            return getCreateSuccessDetail((CreateRequest) request, (ResourceResponse) response);
        case READ:
            return getReadSuccessDetail((ReadRequest) request, (ResourceResponse) response);
        case UPDATE:
            return getUpdateSuccessDetail((UpdateRequest) request, (ResourceResponse) response);
        case DELETE:
            return getDeleteSuccessDetail((DeleteRequest) request, (ResourceResponse) response);
        case PATCH:
            return getPatchSuccessDetail((PatchRequest) request, (ResourceResponse) response);
        case ACTION:
            return getActionSuccessDetail((ActionRequest) request, (ActionResponse) response);
        case QUERY:
            return getQuerySuccessDetail((QueryRequest) request, (QueryResponse) response);
        default:
            throw new IllegalStateException("Unknown RequestType");
    }
}
Also used : RequestType(org.forgerock.json.resource.RequestType)

Example 2 with RequestType

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

the class EntitlementsExceptionMappingHandlerTest method shouldApplyRequestTypeOverrides.

@Test
public void shouldApplyRequestTypeOverrides() {
    // Given
    Map<RequestType, Map<Integer, Integer>> overrides = new HashMap<RequestType, Map<Integer, Integer>>();
    RequestType requestType = RequestType.CREATE;
    overrides.put(requestType, Collections.singletonMap(ResourceException.NOT_FOUND, ResourceException.BAD_REQUEST));
    EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(ERROR_CODE, ResourceException.NOT_FOUND), overrides, Collections.<Integer, Integer>emptyMap());
    EntitlementException error = exception(ERROR_CODE, ERROR_MESSAGE);
    Request request = mock(Request.class);
    given(request.getRequestType()).willReturn(requestType);
    // When
    ResourceException result = errorHandler.handleError(request, error);
    // Then
    assertThat(result).isInstanceOf(BadRequestException.class).hasMessage(ERROR_MESSAGE);
}
Also used : EntitlementsExceptionMappingHandler(org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Request(org.forgerock.json.resource.Request) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) HashMap(java.util.HashMap) Map(java.util.Map) RequestType(org.forgerock.json.resource.RequestType) Test(org.testng.annotations.Test)

Aggregations

RequestType (org.forgerock.json.resource.RequestType)2 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BadRequestException (org.forgerock.json.resource.BadRequestException)1 Request (org.forgerock.json.resource.Request)1 ResourceException (org.forgerock.json.resource.ResourceException)1 EntitlementsExceptionMappingHandler (org.forgerock.openam.entitlement.rest.EntitlementsExceptionMappingHandler)1 Test (org.testng.annotations.Test)1