public Builder values(final Collection<String> values) { instance.getValues().addAll(values); return this; }
public Builder value(final String value) { instance.getValues().add(value); return this; }
@JsonIgnore public boolean isEmpty() { return attrTO == null || attrTO.getValues().isEmpty(); }
public Builder values(final String... values) { instance.getValues().addAll(Arrays.asList(values)); return this; }
private AttrTO evaluateAttr(final AttrTO template, final MapContext jexlContext) { AttrTO result = new AttrTO(); result.setSchema(template.getSchema()); if (template.getValues() != null && !template.getValues().isEmpty()) { template.getValues().forEach(value -> { String evaluated = JexlUtils.evaluate(value, jexlContext); if (StringUtils.isNotBlank(evaluated)) { result.getValues().add(evaluated); } }); } return result; }
private static boolean isValid(final AttrTO attrTO, final CustomAttribute customAttribute) { return customAttribute.isReadonly() ? attrTO.getValues().stream().allMatch(value -> customAttribute.getDefaultValues().contains(value)) : true; }
public static void addAttrTOsToContext(final Collection<AttrTO> attrs, final JexlContext jexlContext) { attrs.stream().filter(attr -> attr.getSchema() != null).forEach(attr -> { String expressionValue = attr.getValues().isEmpty() ? StringUtils.EMPTY : attr.getValues().get(0); LOG.debug("Add attribute {} with value {}", attr.getSchema(), expressionValue); jexlContext.set(attr.getSchema(), expressionValue); }); }
protected void millisToDate(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws IllegalArgumentException { final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern()); attrs.stream(). filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))). forEachOrdered(attr -> { for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext();) { String value = itor.next(); try { itor.set(fmt.format(Long.valueOf(value))); } catch (NumberFormatException ex) { LOG.error("Invalid format value for {}", value); } } }); }
protected void dateToMillis(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws ParseException { final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern()); attrs.stream(). filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))). forEachOrdered(attr -> { for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext();) { String value = itor.next(); try { itor.set(String.valueOf(fmt.parse(value).getTime())); } catch (ParseException ex) { LOG.error("Unable to parse date {}", value); } } }); }
private static boolean validateAttributes(final Map<String, AttrTO> attrMap, final CustomAttributesInfo customAttrInfo, final boolean checkDefaultValues) { return customAttrInfo == null || customAttrInfo.getAttributes().isEmpty() || attrMap.entrySet().stream().allMatch(entry -> { String schemaKey = entry.getKey(); AttrTO attrTO = entry.getValue(); CustomAttribute customAttr = customAttrInfo.getAttributes().get(schemaKey); boolean compliant = customAttr != null && (!checkDefaultValues || isValid(attrTO, customAttr)); if (!compliant) { LOG.trace("Attribute [{}] or its values [{}] are not allowed by form customization rules", attrTO.getSchema(), attrTO.getValues()); } return compliant; }); }
@PreAuthorize("hasRole('" + SCIMEntitlement.SCIM_CONF_GET + "')") public SCIMConf get() { AttrTO confTO = null; try { confTO = configurationLogic.get(SCIMConf.KEY); } catch (Exception e) { LOG.error("{} not found, reverting to default", SCIMConf.KEY); } SCIMConf conf = null; if (confTO != null) { try { conf = POJOHelper.deserialize( new String(Base64.getDecoder().decode(confTO.getValues().get(0))), SCIMConf.class); } catch (Exception e) { LOG.error("Could not deserialize, reverting to default", e); } } if (conf == null) { conf = new SCIMConf(); set(conf); } return conf; }
/** * Builds {@link ConnObjectTO} out of a collection of {@link Attribute} instances. * * @param attrs attributes * @return transfer object */ public static ConnObjectTO getConnObjectTO(final Set<Attribute> attrs) { final ConnObjectTO connObjectTO = new ConnObjectTO(); if (attrs != null) { connObjectTO.getAttrs().addAll(attrs.stream().map(attr -> { AttrTO attrTO = new AttrTO(); attrTO.setSchema(attr.getName()); if (attr.getValue() != null) { attr.getValue().stream().filter(value -> value != null).forEachOrdered(value -> { if (value instanceof GuardedString || value instanceof GuardedByteArray) { attrTO.getValues().add(getPassword(value)); } else if (value instanceof byte[]) { attrTO.getValues().add(Base64.getEncoder().encodeToString((byte[]) value)); } else if (value != null) { attrTO.getValues().add(value.toString()); } }); } return attrTO; }).collect(Collectors.toList())); } return connObjectTO; }
private static Collection<AttrTO> patch(final Map<String, AttrTO> attrs, final Set<AttrPatch> attrPatches) { Map<String, AttrTO> rwattrs = new HashMap<>(attrs); attrPatches.forEach(patch -> { if (patch.getAttrTO() == null) { LOG.warn("Invalid {} specified: {}", AttrPatch.class.getName(), patch); } else { AttrTO removed = rwattrs.remove(patch.getAttrTO().getSchema()); if (patch.getOperation() == PatchOperation.ADD_REPLACE && !patch.getAttrTO().getValues().isEmpty()) { rwattrs.put(patch.getAttrTO().getSchema(), patch.getAttrTO()); } } }); return rwattrs.values(); }
filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))). forEachOrdered(attrTO -> { sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0)); }); filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))). forEachOrdered((attrTO) -> { sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0)); });
@Override protected AnyPatch doUpdate( final AnyTO before, final AnyPatch anyPatch, final SyncDelta delta, final ProvisioningReport result) { GroupPatch groupPatch = GroupPatch.class.cast(anyPatch); Pair<GroupPatch, List<PropagationStatus>> updated = groupProvisioningManager.update( groupPatch, Collections.singleton(profile.getTask().getResource().getKey()), true); String groupOwner = null; for (AttrPatch attrPatch : groupPatch.getPlainAttrs()) { if (attrPatch.getOperation() == PatchOperation.ADD_REPLACE && attrPatch.getAttrTO() != null && attrPatch.getAttrTO().getSchema().isEmpty() && !attrPatch.getAttrTO().getValues().isEmpty()) { groupOwner = attrPatch.getAttrTO().getValues().get(0); } } if (groupOwner != null) { groupOwnerMap.put(updated.getLeft().getKey(), groupOwner); } return anyPatch; }
private <E extends Enum<?>> void fill( final Map<String, AttrTO> attrs, final List<SCIMComplexConf<E>> confs, final List<SCIMComplexValue> values) { confs.forEach(conf -> { SCIMComplexValue value = new SCIMComplexValue(); if (conf.getValue() != null && attrs.containsKey(conf.getValue())) { value.setValue(attrs.get(conf.getValue()).getValues().get(0)); } if (conf.getDisplay() != null && attrs.containsKey(conf.getDisplay())) { value.setDisplay(attrs.get(conf.getDisplay()).getValues().get(0)); } if (conf.getType() != null) { value.setType(conf.getType().name()); } if (conf.isPrimary()) { value.setPrimary(true); } if (!value.isEmpty()) { values.add(value); } }); }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Override public Pair<String, List<PropagationStatus>> create( final GroupTO groupTO, final Map<String, String> groupOwnerMap, final Set<String> excludedResources, final boolean nullPriorityAsync) { WorkflowResult<String> created = gwfAdapter.create(groupTO); // see ConnObjectUtils#getAnyTOFromConnObject for GroupOwnerSchema groupTO.getPlainAttr(StringUtils.EMPTY).ifPresent(groupOwner -> groupOwnerMap.put(created.getResult(), groupOwner.getValues().iterator().next())); List<PropagationTaskInfo> tasks = propagationManager.getCreateTasks( AnyTypeKind.GROUP, created.getResult(), null, created.getPropByRes(), groupTO.getVirAttrs(), excludedResources); PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync); return Pair.of(created.getResult(), propagationReporter.getStatuses()); }
@Override public CPlainAttr getAttr(final AttrTO attrTO) { PlainSchema schema = getPlainSchema(attrTO.getSchema()); if (schema == null) { throw new NotFoundException("Conf schema " + attrTO.getSchema()); } else { SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues); CPlainAttr attr = entityFactory.newEntity(CPlainAttr.class); attr.setSchema(schema); fillAttr(attrTO.getValues(), schema, attr, invalidValues); if (!invalidValues.isEmpty()) { throw invalidValues; } return attr; } } }