use of org.apache.syncope.common.lib.SyncopeClientCompositeException in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.syncope.common.lib.SyncopeClientCompositeException in project syncope by apache.
the class ExceptionMapperITCase method headersMultiValue.
@Test
public void headersMultiValue() {
UserTO userTO = new UserTO();
userTO.setRealm(SyncopeConstants.ROOT_REALM);
String userId = getUUIDString() + "issue654@syncope.apache.org";
userTO.setUsername(userId);
userTO.setPassword("password123");
userTO.getPlainAttrs().add(attrTO("userId", "issue654"));
userTO.getPlainAttrs().add(attrTO("fullname", userId));
userTO.getPlainAttrs().add(attrTO("surname", userId));
try {
createUser(userTO);
fail("This should not happen");
} catch (SyncopeClientCompositeException e) {
assertEquals(2, e.getExceptions().size());
}
}
use of org.apache.syncope.common.lib.SyncopeClientCompositeException in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
// 0. aux classes
any.getAuxClasses().clear();
anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
} else {
any.add(auxClass);
}
});
// 1. attributes
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema != null) {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
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);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
// 2. resources
anyTO.getResources().forEach(resourceKey -> {
ExternalResource resource = resourceDAO.find(resourceKey);
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
} else {
any.add(resource);
}
});
requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
}
use of org.apache.syncope.common.lib.SyncopeClientCompositeException in project syncope by apache.
the class SAML2IdPDataBinderImpl method populateItems.
private void populateItems(final SAML2IdPTO idpTO, final SAML2IdP idp, final AnyTypeClassTO allowedSchemas) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
for (ItemTO itemTO : idpTO.getItems()) {
if (itemTO == null) {
LOG.error("Null {}", ItemTO.class.getSimpleName());
invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
} else if (itemTO.getIntAttrName() == null) {
requiredValuesMissing.getElements().add("intAttrName");
scce.addException(requiredValuesMissing);
} else {
IntAttrName intAttrName = null;
try {
intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), AnyTypeKind.USER);
} catch (ParseException e) {
LOG.error("Invalid intAttrName '{}' specified, ignoring", itemTO.getIntAttrName(), e);
}
if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
LOG.error("'{}' not existing", itemTO.getIntAttrName());
invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
} else {
boolean allowed = true;
if (intAttrName.getSchemaType() != null && intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null) {
switch(intAttrName.getSchemaType()) {
case PLAIN:
allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
break;
case DERIVED:
allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
break;
case VIRTUAL:
allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
break;
default:
}
}
if (allowed) {
// no mandatory condition implies mandatory condition false
if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null ? "false" : itemTO.getMandatoryCondition())) {
SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(ClientExceptionType.InvalidValues);
invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
scce.addException(invalidMandatoryCondition);
}
SAML2IdPItem item = entityFactory.newEntity(SAML2IdPItem.class);
BeanUtils.copyProperties(itemTO, item, ITEM_IGNORE_PROPERTIES);
item.setIdP(idp);
item.setPurpose(MappingPurpose.NONE);
if (item.isConnObjectKey()) {
if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
invalidMapping.getElements().add("Virtual attributes cannot be set as ConnObjectKey");
}
if ("password".equals(intAttrName.getField())) {
invalidMapping.getElements().add("Password attributes cannot be set as ConnObjectKey");
}
idp.setConnObjectKeyItem(item);
} else {
idp.add(item);
}
} else {
LOG.error("'{}' not allowed", itemTO.getIntAttrName());
invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
}
}
}
}
if (!invalidMapping.getElements().isEmpty()) {
scce.addException(invalidMapping);
}
if (scce.hasExceptions()) {
throw scce;
}
}
use of org.apache.syncope.common.lib.SyncopeClientCompositeException in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- DERIVED -----------------
private DerSchema fill(final DerSchema schema, final DerSchemaTO schemaTO) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
if (StringUtils.isBlank(schemaTO.getExpression())) {
SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
requiredValuesMissing.getElements().add("expression");
scce.addException(requiredValuesMissing);
} else if (!JexlUtils.isExpressionValid(schemaTO.getExpression())) {
SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidValues);
e.getElements().add(schemaTO.getExpression());
scce.addException(e);
}
if (scce.hasExceptions()) {
throw scce;
}
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
DerSchema merged = derSchemaDAO.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().getDerSchemas().remove(merged);
merged.setAnyTypeClass(null);
}
return merged;
}
Aggregations