Search in sources :

Example 1 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class RestServiceExceptionMapper method toResponse.

@Override
public Response toResponse(final Exception ex) {
    LOG.error("Exception thrown", ex);
    ResponseBuilder builder;
    if (ex instanceof AccessDeniedException) {
        // leaves the default exception processing to Spring Security
        builder = null;
    } else if (ex instanceof SyncopeClientException) {
        SyncopeClientException sce = (SyncopeClientException) ex;
        builder = sce.isComposite() ? getSyncopeClientCompositeExceptionResponse(sce.asComposite()) : getSyncopeClientExceptionResponse(sce);
    } else if (ex instanceof DelegatedAdministrationException || ExceptionUtils.getRootCause(ex) instanceof DelegatedAdministrationException) {
        builder = builder(ClientExceptionType.DelegatedAdministration, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof EntityExistsException || ex instanceof DuplicateException || ex instanceof PersistenceException && ex.getCause() instanceof EntityExistsException) {
        builder = builder(ClientExceptionType.EntityExists, getJPAMessage(ex instanceof PersistenceException ? ex.getCause() : ex));
    } else if (ex instanceof DataIntegrityViolationException || ex instanceof JpaSystemException) {
        builder = builder(ClientExceptionType.DataIntegrityViolation, getJPAMessage(ex));
    } else if (ex instanceof ConnectorException) {
        builder = builder(ClientExceptionType.ConnectorException, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof NotFoundException) {
        builder = builder(ClientExceptionType.NotFound, 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(validationEM.toResponse((ValidationException) ex)).header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.name()).header(RESTHeaders.ERROR_INFO, ClientExceptionType.RESTValidation.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
            ErrorTO error = new ErrorTO();
            error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
            error.setType(ClientExceptionType.RESTValidation);
            error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
            builder.entity(error);
        }
        // ...or just report as InternalServerError
        if (builder == null) {
            builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).header(RESTHeaders.ERROR_INFO, ClientExceptionType.Unknown.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
            ErrorTO error = new ErrorTO();
            error.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
            error.setType(ClientExceptionType.Unknown);
            error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
            builder.entity(error);
        }
    }
    return builder == null ? null : builder.build();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ValidationException(javax.validation.ValidationException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) EntityExistsException(javax.persistence.EntityExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) JpaSystemException(org.springframework.orm.jpa.JpaSystemException) ErrorTO(org.apache.syncope.common.lib.to.ErrorTO) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) PersistenceException(javax.persistence.PersistenceException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 2 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class ReportTemplateLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_CREATE + "')")
public ReportTemplateTO create(final String key) {
    if (reportTemplateDAO.find(key) != null) {
        throw new DuplicateException(key);
    }
    ReportTemplate reportTemplate = entityFactory.newEntity(ReportTemplate.class);
    reportTemplate.setKey(key);
    reportTemplateDAO.save(reportTemplate);
    return getReportTemplateTO(key);
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ReportTemplate(org.apache.syncope.core.persistence.api.entity.ReportTemplate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class AnyTypeClassLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPECLASS_CREATE + "')")
public AnyTypeClassTO create(final AnyTypeClassTO anyTypeClassTO) {
    if (StringUtils.isBlank(anyTypeClassTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add(AnyTypeClass.class.getSimpleName() + " name");
        throw sce;
    }
    if (anyTypeClassDAO.find(anyTypeClassTO.getKey()) != null) {
        throw new DuplicateException(anyTypeClassTO.getKey());
    }
    return binder.getAnyTypeClassTO(anyTypeClassDAO.save(binder.create(anyTypeClassTO)));
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.

the class AnyTypeLogic method create.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_CREATE + "')")
public AnyTypeTO create(final AnyTypeTO anyTypeTO) {
    if (StringUtils.isBlank(anyTypeTO.getKey())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
        sce.getElements().add(AnyType.class.getSimpleName() + " key");
        throw sce;
    }
    if (anyTypeDAO.find(anyTypeTO.getKey()) != null) {
        throw new DuplicateException(anyTypeTO.getKey());
    }
    return binder.getAnyTypeTO(anyTypeDAO.save(binder.create(anyTypeTO)));
}
Also used : DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with DuplicateException

use of org.apache.syncope.core.persistence.api.dao.DuplicateException 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)

Aggregations

DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 ValidationException (javax.validation.ValidationException)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)2 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)2 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 EntityExistsException (javax.persistence.EntityExistsException)1 PersistenceException (javax.persistence.PersistenceException)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)1 ErrorTO (org.apache.syncope.common.lib.to.ErrorTO)1 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)1 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)1 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)1 RealmTO (org.apache.syncope.common.lib.to.RealmTO)1