Search in sources :

Example 56 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class AbstractAnyLogic method beforeCreate.

protected Pair<TO, List<LogicActions>> beforeCreate(final TO input) {
    Realm realm = realmDAO.findByFullPath(input.getRealm());
    if (realm == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
        sce.getElements().add(input.getRealm());
        throw sce;
    }
    AnyType anyType = input instanceof UserTO ? anyTypeDAO.findUser() : input instanceof GroupTO ? anyTypeDAO.findGroup() : anyTypeDAO.find(input.getType());
    if (anyType == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
        sce.getElements().add(input.getType());
        throw sce;
    }
    TO any = input;
    templateUtils.apply(any, realm.getTemplate(anyType));
    List<LogicActions> actions = getActions(realm);
    for (LogicActions action : actions) {
        any = action.beforeCreate(any);
    }
    LOG.debug("Input: {}\nOutput: {}\n", input, any);
    return ImmutablePair.of(any, actions);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTO(org.apache.syncope.common.lib.to.AnyTO) GroupTO(org.apache.syncope.common.lib.to.GroupTO) UserTO(org.apache.syncope.common.lib.to.UserTO) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) LogicActions(org.apache.syncope.core.provisioning.api.LogicActions) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 57 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class AccessTokenLogic method login.

@PreAuthorize("isAuthenticated()")
public Pair<String, Date> login() {
    if (anonymousUser.equals(AuthContextUtils.getUsername())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add(anonymousUser + " cannot be granted an access token");
        throw sce;
    }
    return binder.create(AuthContextUtils.getUsername(), Collections.<String, Object>emptyMap(), getAuthorities(), false);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 58 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException 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 59 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class RestServiceExceptionMapper method getSyncopeClientCompositeExceptionResponse.

private ResponseBuilder getSyncopeClientCompositeExceptionResponse(final SyncopeClientCompositeException ex) {
    if (ex.getExceptions().size() == 1) {
        return getSyncopeClientExceptionResponse(ex.getExceptions().iterator().next());
    }
    ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
    List<ErrorTO> errors = new ArrayList<>();
    for (SyncopeClientException sce : ex.getExceptions()) {
        builder.header(RESTHeaders.ERROR_CODE, sce.getType().name());
        ErrorTO error = new ErrorTO();
        error.setStatus(sce.getType().getResponseStatus().getStatusCode());
        error.setType(sce.getType());
        for (String element : sce.getElements()) {
            builder.header(RESTHeaders.ERROR_INFO, sce.getType().getInfoHeaderValue(element));
            error.getElements().add(element);
        }
        errors.add(error);
    }
    return builder.entity(errors);
}
Also used : ErrorTO(org.apache.syncope.common.lib.to.ErrorTO) ArrayList(java.util.ArrayList) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Example 60 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class AnyObjectServiceImpl method search.

@Override
public PagedResult<AnyObjectTO> search(final AnyQuery anyQuery) {
    if (StringUtils.isBlank(anyQuery.getFiql()) || -1 == anyQuery.getFiql().indexOf(SpecialAttr.TYPE.toString())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression);
        sce.getElements().add(SpecialAttr.TYPE.toString() + " is required in the FIQL string");
        throw sce;
    }
    return super.search(anyQuery);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11