Search in sources :

Example 66 with SyncopeClientException

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

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final Membership membership, final MembershipTO membershipTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    membershipTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
        PlainSchema schema = getPlainSchema(attrTO.getSchema());
        if (schema != null) {
            GroupablePlainAttr attr = (GroupablePlainAttr) GroupableRelatable.class.cast(any).getPlainAttr(schema.getKey(), membership).orElse(null);
            if (attr == null) {
                attr = anyUtils.newPlainAttr();
                attr.setOwner(any);
                attr.setMembership(membership);
                attr.setSchema(schema);
            }
            fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
            if (attr.getValuesAsStrings().isEmpty()) {
                attr.setOwner(null);
            } else {
                any.add(attr);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) SchemaDataBinder(org.apache.syncope.core.provisioning.api.data.SchemaDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ParseException(java.text.ParseException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Logger(org.slf4j.Logger) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) Membership(org.apache.syncope.core.persistence.api.entity.Membership) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr)

Example 67 with SyncopeClientException

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

the class AbstractAnyDataBinder method checkMandatoryOnResources.

private SyncopeClientException checkMandatoryOnResources(final Any<?> any, final Collection<? extends ExternalResource> resources) {
    SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
    resources.forEach(resource -> {
        Optional<? extends Provision> provision = resource.getProvision(any.getType());
        if (resource.isEnforceMandatoryCondition() && provision.isPresent()) {
            List<String> missingAttrNames = evaluateMandatoryCondition(provision.get(), any);
            if (!missingAttrNames.isEmpty()) {
                LOG.error("Mandatory schemas {} not provided with values", missingAttrNames);
                reqValMissing.getElements().addAll(missingAttrNames);
            }
        }
    });
    return reqValMissing;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException)

Example 68 with SyncopeClientException

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

the class SchemaDataBinderImpl method fill.

// --------------- VIRTUAL -----------------
private VirSchema fill(final VirSchema schema, final VirSchemaTO schemaTO) {
    BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
    if (schemaTO.getAnyTypeClass() != null && (schema.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(schema.getAnyTypeClass().getKey()))) {
        AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
        if (anyTypeClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
        } else {
            anyTypeClass.add(schema);
            schema.setAnyTypeClass(anyTypeClass);
        }
    } else if (schemaTO.getAnyTypeClass() == null && schema.getAnyTypeClass() != null) {
        schema.getAnyTypeClass().getVirSchemas().remove(schema);
        schema.setAnyTypeClass(null);
    }
    ExternalResource resource = resourceDAO.find(schemaTO.getResource());
    if (resource == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("Resource " + schemaTO.getResource() + " not found");
        throw sce;
    }
    AnyType anyType = anyTypeDAO.find(schemaTO.getAnyType());
    if (anyType == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("AnyType " + schemaTO.getAnyType() + " not found");
        throw sce;
    }
    Provision provision = resource.getProvision(anyType).orElse(null);
    if (provision == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("Provision for AnyType" + schemaTO.getAnyType() + " not found in " + schemaTO.getResource());
        throw sce;
    }
    schema.setProvision(provision);
    return virSchemaDAO.save(schema);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 69 with SyncopeClientException

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

the class SchemaDataBinderImpl method update.

@Override
public PlainSchema update(final PlainSchemaTO schemaTO, final PlainSchema schema) {
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    boolean hasAttrs = false;
    for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
        AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind);
        hasAttrs |= plainSchemaDAO.findAttrs(schema, anyUtils.plainAttrClass()).isEmpty();
    }
    if (hasAttrs) {
        if (schema.getType() != schemaTO.getType()) {
            SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
            e.getElements().add("Cannot change type since " + schema.getKey() + " has attributes");
            scce.addException(e);
        }
        if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) {
            SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema);
            e.getElements().add("Cannot alter unique contraint since " + schema.getKey() + " has attributes");
            scce.addException(e);
        }
    }
    if (scce.hasExceptions()) {
        throw scce;
    }
    return fill(schema, schemaTO);
}
Also used : SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 70 with SyncopeClientException

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

the class SchemaDataBinderImpl method fill.

// --------------- PLAIN -----------------
private PlainSchema fill(final PlainSchema schema, final PlainSchemaTO schemaTO) {
    if (!JexlUtils.isExpressionValid(schemaTO.getMandatoryCondition())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidValues);
        sce.getElements().add(schemaTO.getMandatoryCondition());
        throw sce;
    }
    BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
    if (schemaTO.getValidator() == null) {
        schema.setValidator(null);
    } else {
        Implementation validator = implementationDAO.find(schemaTO.getValidator());
        if (validator == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", schemaTO.getValidator());
        } else {
            schema.setValidator(validator);
        }
    }
    PlainSchema merged = plainSchemaDAO.save(schema);
    if (schemaTO.getAnyTypeClass() != null && (merged.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(merged.getAnyTypeClass().getKey()))) {
        AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
        if (anyTypeClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
        } else {
            anyTypeClass.add(merged);
            merged.setAnyTypeClass(anyTypeClass);
        }
    } else if (schemaTO.getAnyTypeClass() == null && merged.getAnyTypeClass() != null) {
        merged.getAnyTypeClass().getPlainSchemas().remove(merged);
        merged.setAnyTypeClass(null);
    }
    return merged;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

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