Search in sources :

Example 1 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMITCase method list.

@Test
public void list() throws IOException {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    Response response = webClient().path("Groups").query("count", 1100000).get();
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(ErrorType.tooMany, error.getScimType());
    response = webClient().path("Groups").query("sortBy", "displayName").query("count", 11).get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    ListResponse<SCIMGroup> result = response.readEntity(new GenericType<ListResponse<SCIMGroup>>() {
    });
    assertNotNull(result);
    assertTrue(result.getTotalResults() > 0);
    assertEquals(11, result.getItemsPerPage());
    assertFalse(result.getResources().isEmpty());
    result.getResources().forEach(group -> {
        assertNotNull(group.getId());
        assertNotNull(group.getDisplayName());
    });
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) Test(org.junit.jupiter.api.Test)

Example 2 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMExceptionMapper method builder.

private ResponseBuilder builder(final ClientExceptionType hType, final String msg) {
    ResponseBuilder builder = Response.status(hType.getResponseStatus());
    ErrorType scimType = null;
    if (hType.name().startsWith("Invalid") || hType == ClientExceptionType.RESTValidation) {
        scimType = ErrorType.invalidValue;
    } else if (hType == ClientExceptionType.EntityExists) {
        scimType = ErrorType.uniqueness;
    }
    return builder.entity(new SCIMError(scimType, hType.getResponseStatus().getStatusCode(), msg));
}
Also used : ErrorType(org.apache.syncope.ext.scimv2.api.type.ErrorType) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 3 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMExceptionMapper method toResponse.

@Override
public Response toResponse(final Exception ex) {
    LOG.error("Exception thrown", ex);
    ResponseBuilder builder;
    if (ex instanceof AccessDeniedException || ex instanceof ForbiddenException || ex instanceof NotAuthorizedException) {
        // leaves the default exception processing
        builder = null;
    } else if (ex instanceof NotFoundException) {
        return Response.status(Response.Status.NOT_FOUND).entity(new SCIMError(null, Response.Status.NOT_FOUND.getStatusCode(), ExceptionUtils.getRootCauseMessage(ex))).build();
    } else if (ex instanceof SyncopeClientException) {
        SyncopeClientException sce = (SyncopeClientException) ex;
        builder = builder(sce.getType(), ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof DelegatedAdministrationException || ExceptionUtils.getRootCause(ex) instanceof DelegatedAdministrationException) {
        builder = builder(ClientExceptionType.DelegatedAdministration, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ENTITYEXISTS_EXCLASS.isAssignableFrom(ex.getClass()) || ex instanceof DuplicateException || PERSISTENCE_EXCLASS.isAssignableFrom(ex.getClass()) && ENTITYEXISTS_EXCLASS.isAssignableFrom(ex.getCause().getClass())) {
        builder = builder(ClientExceptionType.EntityExists, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof DataIntegrityViolationException || JPASYSTEM_EXCLASS.isAssignableFrom(ex.getClass())) {
        builder = builder(ClientExceptionType.DataIntegrityViolation, ExceptionUtils.getRootCauseMessage(ex));
    } else if (CONNECTOR_EXCLASS.isAssignableFrom(ex.getClass())) {
        builder = builder(ClientExceptionType.ConnectorException, ExceptionUtils.getRootCauseMessage(ex));
    } else {
        builder = processInvalidEntityExceptions(ex);
        if (builder == null) {
            builder = processBadRequestExceptions(ex);
        }
        // process JAX-RS validation errors
        if (builder == null && ex instanceof ValidationException) {
            builder = builder(ClientExceptionType.RESTValidation, ExceptionUtils.getRootCauseMessage(ex));
        }
        // ...or just report as InternalServerError
        if (builder == null) {
            builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionUtils.getRootCauseMessage(ex));
        }
    }
    return builder == null ? null : builder.build();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) ValidationException(javax.validation.ValidationException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 4 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMITCase method createGroup.

@Test
public void createGroup() {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    String displayName = UUID.randomUUID().toString();
    SCIMGroup group = new SCIMGroup(null, null, displayName);
    group.getMembers().add(new Member("1417acbe-cbf6-4277-9372-e75e04f97000", null, null));
    assertNull(group.getId());
    assertEquals(displayName, group.getDisplayName());
    Response response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    group = response.readEntity(SCIMGroup.class);
    assertNotNull(group.getId());
    assertTrue(response.getLocation().toASCIIString().endsWith(group.getId()));
    assertEquals(1, group.getMembers().size());
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", group.getMembers().get(0).getValue());
    response = webClient().path("Users").path("1417acbe-cbf6-4277-9372-e75e04f97000").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    SCIMUser user = response.readEntity(SCIMUser.class);
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", user.getId());
    response = webClient().path("Groups").post(group);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), error.getStatus());
    assertEquals(ErrorType.uniqueness, error.getScimType());
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) Member(org.apache.syncope.ext.scimv2.api.data.Member) Test(org.junit.jupiter.api.Test)

Example 5 with SCIMError

use of org.apache.syncope.ext.scimv2.api.data.SCIMError in project syncope by apache.

the class SCIMITCase method read.

@Test
public void read() throws IOException {
    assumeTrue(SCIMDetector.isSCIMAvailable(webClient()));
    Response response = webClient().path("Users").path("missing").get();
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
    SCIMError error = response.readEntity(SCIMError.class);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), error.getStatus());
    response = webClient().path("Users").path("1417acbe-cbf6-4277-9372-e75e04f97000").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    SCIMUser user = response.readEntity(SCIMUser.class);
    assertNotNull(user);
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", user.getId());
    assertEquals("rossini", user.getUserName());
    assertFalse(user.getGroups().isEmpty());
    assertFalse(user.getRoles().isEmpty());
    response = webClient().path("Users").path("1417acbe-cbf6-4277-9372-e75e04f97000").query("attributes", "groups").get();
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertEquals(SCIMConstants.APPLICATION_SCIM_JSON, StringUtils.substringBefore(response.getHeaderString(HttpHeaders.CONTENT_TYPE), ";"));
    user = response.readEntity(SCIMUser.class);
    assertNotNull(user);
    assertEquals("1417acbe-cbf6-4277-9372-e75e04f97000", user.getId());
    assertNull(user.getUserName());
    assertFalse(user.getGroups().isEmpty());
    assertTrue(user.getRoles().isEmpty());
}
Also used : ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) Response(javax.ws.rs.core.Response) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) SCIMError(org.apache.syncope.ext.scimv2.api.data.SCIMError) Test(org.junit.jupiter.api.Test)

Aggregations

SCIMError (org.apache.syncope.ext.scimv2.api.data.SCIMError)6 Response (javax.ws.rs.core.Response)4 ListResponse (org.apache.syncope.ext.scimv2.api.data.ListResponse)4 Test (org.junit.jupiter.api.Test)4 SCIMGroup (org.apache.syncope.ext.scimv2.api.data.SCIMGroup)3 SCIMUser (org.apache.syncope.ext.scimv2.api.data.SCIMUser)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Date (java.util.Date)1 ValidationException (javax.validation.ValidationException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 GenericType (javax.ws.rs.core.GenericType)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 UserTO (org.apache.syncope.common.lib.to.UserTO)1 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)1 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)1 Member (org.apache.syncope.ext.scimv2.api.data.Member)1 SCIMSearchRequest (org.apache.syncope.ext.scimv2.api.data.SCIMSearchRequest)1