isValid = true; } else { if (attr.getSchema().isUniqueConstraint()) { isValid = attr.getValues().isEmpty() && attr.getUniqueValue() != null; } else { isValid = !attr.getValues().isEmpty() && attr.getUniqueValue() == null; if (!attr.getSchema().isMultivalue()) { isValid &= attr.getValues().size() == 1; + "schema=" + attr.getSchema().getKey() + ", values={}", attr.getValuesAsStrings()); "Invalid values " + attr.getValuesAsStrings())). addPropertyNode(attr.getSchema().getKey()).addConstraintViolation();
@Override public void deleteAll(final PlainAttr<?> attr, final AnyUtils anyUtils) { if (attr.getUniqueValue() == null) { attr.getValues().stream().map(Entity::getKey).collect(Collectors.toSet()).forEach(attrValueKey -> { PlainAttrValue attrValue = anyUtils.plainAttrValueClass().cast( entityManager().find(getEntityReference(anyUtils.plainAttrValueClass()), attrValueKey)); if (attrValue != null) { entityManager().remove(attrValue); attr.getValues().remove(attrValue); } }); } else { entityManager().remove(attr.getUniqueValue()); attr.setUniqueValue(null); } } }
public static void addPlainAttrsToContext( final Collection<? extends PlainAttr<?>> attrs, final JexlContext jexlContext) { attrs.stream().filter(attr -> attr.getSchema() != null).forEach(attr -> { List<String> attrValues = attr.getValuesAsStrings(); String expressionValue = attrValues.isEmpty() ? StringUtils.EMPTY : attrValues.get(0); LOG.debug("Add attribute {} with value {}", attr.getSchema().getKey(), expressionValue); jexlContext.set(attr.getSchema().getKey(), expressionValue); }); }
if (attr == null) { attr = newPlainAttr(); attr.setSchema(schema); ((PlainAttr) attr).setOwner(any); any.add(attr); attr.add(value, this); dao().save(any); } catch (InvalidPlainAttrValueException e) { LOG.debug("{} has already {} set: {}", any, schema.getKey(), attr.getValuesAsStrings());
case ADD_REPLACE: if (attr.getSchema().isUniqueConstraint()) { if (attr.getUniqueValue() != null && !patch.getAttrTO().getValues().isEmpty() && !patch.getAttrTO().getValues().get(0).equals(attr.getUniqueValue().getValueAsString())) { && (!schema.isUniqueConstraint() || attr.getUniqueValue() == null || !valuesToBeAdded.get(0).equals(attr.getUniqueValue().getValueAsString()))) { if (attr.getValuesAsStrings().isEmpty()) { plainAttrDAO.delete(attr); propByRes.add(ResourceOperation.UPDATE, resource.getKey()); if (item.isConnObjectKey() && !attr.getValuesAsStrings().isEmpty()) { propByRes.addOldConnObjectKey(resource.getKey(), attr.getValuesAsStrings().get(0));
if (attr == null) { attr = anyUtils.newPlainAttr(); ((PlainAttr) attr).setOwner(any); attr.setSchema(schema); if (attr.getValuesAsStrings().isEmpty()) { attr.setOwner(null); } else { any.add(attr);
intAttrName.getSchemaName(), reference); } else { if (attr.getUniqueValue() != null) { values.add(anyUtils.clonePlainAttrValue(attr.getUniqueValue())); } else if (attr.getValues() != null) { attr.getValues().forEach(value -> values.add(anyUtils.clonePlainAttrValue(value)));
private void fillAttr( final List<String> values, final AnyUtils anyUtils, final PlainSchema schema, final PlainAttr<?> 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.get(0))); valuesProvided.forEach(value -> { if (StringUtils.isBlank(value)) { LOG.debug("Null value for {}, ignoring", schema.getKey()); } else { try { attr.add(value, anyUtils); } catch (InvalidPlainAttrValueException e) { String valueToPrint = value.length() > 40 ? value.substring(0, 20) + "..." : value; LOG.warn("Invalid value for attribute " + schema.getKey() + ": " + valueToPrint, e); invalidValues.getElements().add(schema.getKey() + ": " + valueToPrint + " - " + e.getMessage()); } } }); }
protected void fillTO( final AnyTO anyTO, final String realmFullPath, final Collection<? extends AnyTypeClass> auxClasses, final Collection<? extends PlainAttr<?>> plainAttrs, final Map<DerSchema, String> derAttrs, final Map<VirSchema, List<String>> virAttrs, final Collection<? extends ExternalResource> resources, final boolean details) { anyTO.setRealm(realmFullPath); anyTO.getAuxClasses().addAll(auxClasses.stream().map(Entity::getKey).collect(Collectors.toList())); plainAttrs.forEach(plainAttr -> { anyTO.getPlainAttrs().add(new AttrTO.Builder(). schema(plainAttr.getSchema().getKey()). values(plainAttr.getValuesAsStrings()).build()); }); derAttrs.forEach((schema, value) -> { anyTO.getDerAttrs().add(new AttrTO.Builder().schema(schema.getKey()).value(value).build()); }); virAttrs.forEach((schema, values) -> { anyTO.getVirAttrs().add(new AttrTO.Builder().schema(schema.getKey()).values(values).build()); }); anyTO.getResources().addAll(resources.stream().map(Entity::getKey).collect(Collectors.toSet())); }
@Override public String getValueAsString() { PlainSchema schema = getAttr() == null || getAttr().getSchema() == null ? null : getAttr().getSchema(); AttrSchemaType type = schema == null || schema.getType() == null ? AttrSchemaType.String : getAttr().getSchema().getType(); return getValueAsString(type, schema); }
protected MembershipTO getMembershipTO( final Collection<? extends PlainAttr<?>> plainAttrs, final Map<DerSchema, String> derAttrs, final Map<VirSchema, List<String>> virAttrs, final Membership<? extends Any<?>> membership) { MembershipTO membershipTO = new MembershipTO.Builder(). group(membership.getRightEnd().getKey(), membership.getRightEnd().getName()). build(); plainAttrs.forEach(plainAttr -> { membershipTO.getPlainAttrs().add(new AttrTO.Builder(). schema(plainAttr.getSchema().getKey()). values(plainAttr.getValuesAsStrings()). build()); }); derAttrs.forEach((schema, value) -> { membershipTO.getDerAttrs().add(new AttrTO.Builder(). schema(schema.getKey()). value(value). build()); }); virAttrs.forEach((schema, values) -> { membershipTO.getVirAttrs().add(new AttrTO.Builder(). schema(schema.getKey()). values(values). build()); }); return membershipTO; }
@Override protected void doValidate(final PlainAttrValue attrValue) { // check Binary schemas MIME Type mismatches if (attrValue.getBinaryValue() != null) { byte[] binaryValue = attrValue.getBinaryValue(); String mimeType = TIKA.detect(binaryValue); boolean valid = true; if (!mimeType.equals(attrValue.getAttr().getSchema().getMimeType())) { if (MediaType.TEXT_PLAIN.equals(mimeType) && MediaType.APPLICATION_JSON.equals(attrValue.getAttr().getSchema().getMimeType())) { String decoded = new String(binaryValue).trim(); valid = (decoded.startsWith("{") && decoded.endsWith("}")) || (decoded.startsWith("[") && decoded.endsWith("]")) && isValidJSON(decoded); } else { valid = false; } } if (!valid) { throw new InvalidPlainAttrValueException( "Found MIME type: '" + mimeType + "', expecting: '" + attrValue.getAttr().getSchema().getMimeType() + "'"); } } }
if (attr != null && !allowedPlainSchemas.forSelfContains(attr.getSchema().getKey())) { return raiseNotAllowedViolation(context, attr.getSchema().getKey(), null); for (PlainAttr<?> attr : ((GroupableRelatable<?, ?, ?, ?, ?>) any).getPlainAttrs(membership)) { if (attr != null && !allowedPlainSchemas.forMembershipsContains( membership.getRightEnd(), attr.getSchema().getKey())) { context, attr.getSchema().getKey(), membership.getRightEnd());
A any = (A) value.getAttr().getOwner(); if (!result.contains(any)) { result.add(any);
PlainSchema attrSchema = value.getAttr().getSchema();