Search in sources :

Example 1 with InvalidPlainAttrValueException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException in project syncope by apache.

the class AzurePropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER.equals(task.getAnyTypeKind())) {
        User user = userDAO.find(task.getEntityKey());
        if (user == null) {
            LOG.error("Could not find user {}, skipping", task.getEntityKey());
        } else {
            boolean modified = false;
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // Azure User ID
            PlainSchema azureId = plainSchemaDAO.find(getAzureIdSchema());
            if (azureId == null) {
                LOG.error("Could not find schema {}, skipping", getAzureIdSchema());
            } else {
                // set back the __UID__ received by Azure
                UPlainAttr attr = user.getPlainAttr(getAzureIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(azureId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(afterObj.getUid().getUidValue(), anyUtils);
                        modified = true;
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), afterObj.getUid().getUidValue(), e);
                    }
                } else {
                    LOG.debug("User {} has already {} assigned: {}", user, azureId.getKey(), attr.getValuesAsStrings());
                }
            }
            if (modified) {
                userDAO.save(user);
            }
        }
    } else if (AnyTypeKind.GROUP.equals(task.getAnyTypeKind())) {
        Group group = groupDAO.find(task.getEntityKey());
        if (group == null) {
            LOG.error("Could not find group {}, skipping", task.getEntityKey());
        } else {
            boolean modified = false;
            AnyUtils anyUtils = anyUtilsFactory.getInstance(group);
            // Azure Group ID
            PlainSchema azureId = plainSchemaDAO.find(getAzureGroupIdSchema());
            if (azureId == null) {
                LOG.error("Could not find schema {}, skipping", getAzureGroupIdSchema());
            } else {
                // set back the __UID__ received by Azure
                GPlainAttr attr = group.getPlainAttr(getAzureGroupIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(GPlainAttr.class);
                    attr.setSchema(azureId);
                    attr.setOwner(group);
                    group.add(attr);
                    try {
                        attr.add(afterObj.getUid().getUidValue(), anyUtils);
                        modified = true;
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", azureId.getKey(), afterObj.getUid().getUidValue(), e);
                    }
                } else {
                    LOG.debug("Group {} has already {} assigned: {}", group, azureId.getKey(), attr.getValuesAsStrings());
                }
            }
            if (modified) {
                groupDAO.save(group);
            }
        }
    }
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) GPlainAttr(org.apache.syncope.core.persistence.api.entity.group.GPlainAttr) User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with InvalidPlainAttrValueException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException in project syncope by apache.

the class ConfigurationDataBinderImpl method fillAttr.

private void fillAttr(final List<String> values, final PlainSchema schema, final CPlainAttr attr, final SyncopeClientException invalidValues) {
    // if schema is multivalue, all values are considered for addition;
    // otherwise only the fist one - if provided - is considered
    List<String> valuesProvided = schema.isMultivalue() ? values : (values.isEmpty() ? Collections.<String>emptyList() : Collections.singletonList(values.iterator().next()));
    if (valuesProvided.isEmpty()) {
        JexlContext jexlContext = new MapContext();
        JexlUtils.addPlainAttrsToContext(confDAO.get().getPlainAttrs(), jexlContext);
        if (!schema.isReadonly() && Boolean.parseBoolean(JexlUtils.evaluate(schema.getMandatoryCondition(), jexlContext))) {
            LOG.error("Mandatory schema " + schema.getKey() + " not provided with values");
            SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
            reqValMissing.getElements().add(schema.getKey());
            throw reqValMissing;
        }
    }
    for (String value : valuesProvided) {
        if (value == null || value.isEmpty()) {
            LOG.debug("Null value for {}, ignoring", schema.getKey());
        } else {
            try {
                PlainAttrValue attrValue;
                if (schema.isUniqueConstraint()) {
                    attrValue = entityFactory.newEntity(CPlainAttrUniqueValue.class);
                    ((PlainAttrUniqueValue) attrValue).setSchema(schema);
                } else {
                    attrValue = entityFactory.newEntity(CPlainAttrValue.class);
                }
                attr.add(value, attrValue);
            } catch (InvalidPlainAttrValueException e) {
                LOG.warn("Invalid value for attribute " + schema.getKey() + ": " + value, e);
                invalidValues.getElements().add(schema.getKey() + ": " + value + " - " + e.getMessage());
            }
        }
    }
}
Also used : CPlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue) PlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue) CPlainAttrValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue) CPlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue) JexlContext(org.apache.commons.jexl3.JexlContext) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) CPlainAttrValue(org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue) MapContext(org.apache.commons.jexl3.MapContext) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)

Example 3 with InvalidPlainAttrValueException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException in project syncope by apache.

the class GoogleAppsPullActions method afterAll.

@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
    googleAppsIds.forEach((key, value) -> {
        User user = userDAO.find(key);
        if (user == null) {
            LOG.error("Could not find user {}, skipping", key);
        } else {
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // 1. stores the __UID__ received by Google
            PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
            if (googleAppsId == null) {
                LOG.error("Could not find schema googleAppsId, skipping");
            } else {
                UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(googleAppsId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(value, anyUtils);
                        userDAO.save(user);
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
                    }
                } else {
                    LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
                }
            }
        }
    });
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with InvalidPlainAttrValueException

use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException in project syncope by apache.

the class GoogleAppsPropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER != task.getAnyTypeKind()) {
        return;
    }
    User user = userDAO.find(task.getEntityKey());
    if (user == null) {
        LOG.error("Could not find user {}, skipping", task.getEntityKey());
    } else {
        boolean modified = false;
        AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
        PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
        if (googleAppsId == null) {
            LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
        } else {
            // set back the __UID__ received by Google
            UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
            if (attr == null) {
                attr = entityFactory.newEntity(UPlainAttr.class);
                attr.setSchema(googleAppsId);
                attr.setOwner(user);
                user.add(attr);
                try {
                    attr.add(afterObj.getUid().getUidValue(), anyUtils);
                    modified = true;
                } catch (InvalidPlainAttrValueException e) {
                    LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
                }
            } else {
                LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
            }
        }
        if (modified) {
            userDAO.save(user);
        }
    }
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InvalidPlainAttrValueException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)4 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)3 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)3 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)3 User (org.apache.syncope.core.persistence.api.entity.user.User)3 Transactional (org.springframework.transaction.annotation.Transactional)3 JexlContext (org.apache.commons.jexl3.JexlContext)1 MapContext (org.apache.commons.jexl3.MapContext)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 PlainAttrUniqueValue (org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue)1 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)1 CPlainAttrUniqueValue (org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrUniqueValue)1 CPlainAttrValue (org.apache.syncope.core.persistence.api.entity.conf.CPlainAttrValue)1 GPlainAttr (org.apache.syncope.core.persistence.api.entity.group.GPlainAttr)1 Group (org.apache.syncope.core.persistence.api.entity.group.Group)1