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