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());
});
}
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));
}
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();
}
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());
}
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());
}
Aggregations