protected void doHandle( final List<? extends Any<?>> anys, final SyncopePushResultHandler handler, final ExternalResource resource) throws JobExecutionException { for (int i = 0; i < anys.size() && !interrupt; i++) { try { handler.handle(anys.get(i).getKey()); reportHandled( anys.get(i).getType().getKey(), (anys.get(i) instanceof User ? ((User) anys.get(i)).getUsername() : anys.get(i) instanceof Group ? ((Group) anys.get(i)).getName() : ((AnyObject) anys.get(i)).getName())); } catch (Exception e) { LOG.warn("Failure pushing '{}' on '{}'", anys.get(i), resource, e); throw new JobExecutionException("While pushing " + anys.get(i) + " on " + resource, e); } } }
typeOwnClasses.addAll(any.getType().getClasses()); typeOwnClasses.addAll(any.getAuxClasses()); if (!typeOwnClasses.stream().anyMatch(clazz -> clazz.getPlainSchemas().contains(schema))) { LOG.warn("Schema {} not allowed for {}, ignoring", schema, any); PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null); if (attr == null) { attr = newPlainAttr(); attr.setSchema(schema); ((PlainAttr) attr).setOwner(any); any.add(attr);
private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) { Map<DerSchema, String> result = new HashMap<>(schemas.size()); schemas.forEach(schema -> { JexlContext jexlContext = new MapContext(); JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext); JexlUtils.addFieldsToContext(any, jexlContext); result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext)); }); return result; }
private void populateTransitiveResources( final Group group, final Any<?> any, final Map<String, PropagationByResource> result) { PropagationByResource propByRes = new PropagationByResource(); group.getResources().forEach(resource -> { if (!any.getResources().contains(resource)) { propByRes.add(ResourceOperation.DELETE, resource.getKey()); } if (!propByRes.isEmpty()) { result.put(any.getKey(), propByRes); } }); }
} else { references.addAll(groupableRelatable.getRelationships(relationshipType).stream(). filter(relationship -> anyType.equals(relationship.getRightEnd().getType())). map(Relationship::getRightEnd). collect(Collectors.toList())); attrValue.setStringValue(reference.getKey()); values.add(attrValue); break; attrValue.setStringValue(reference.getRealm().getFullPath()); values.add(attrValue); break; PlainAttr<?> attr; if (membership == null) { attr = reference.getPlainAttr(intAttrName.getSchemaName()).orElse(null); } else { attr = ((GroupableRelatable<?, ?, ?, ?, ?>) reference).getPlainAttr( LOG.debug("Expire entry cache {}-{}", reference, intAttrName.getSchemaName()); virAttrCache.expire( reference.getType().getKey(), reference.getKey(), intAttrName.getSchemaName());
case key: type = ReportXMLConst.XSD_STRING; value = any.getKey(); break; value = any.getStatus(); break; value = any.getCreationDate() == null ? StringUtils.EMPTY : FormatUtils.format(any.getCreationDate()); break; handler.startElement("", "", getAnyElementName(any.getType().getKind()), atts); handler.endElement("", "", getAnyElementName(any.getType().getKind()));
switch (patch.getOperation()) { case ADD_REPLACE: any.add(auxClass); break; any.getAuxClasses().remove(auxClass); case ADD_REPLACE: propByRes.add(ResourceOperation.CREATE, resource.getKey()); any.add(resource); break; default: propByRes.add(ResourceOperation.DELETE, resource.getKey()); any.getResources().remove(resource); patch.getAttrTO().getSchema()); } else { PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null); if (attr == null) { LOG.debug("No plain attribute found for schema {}", schema); ((PlainAttr) attr).setOwner(any); attr.setSchema(schema); any.add(attr);
private SyncopeClientException checkMandatoryOnResources( final Any<?> any, final Collection<? extends ExternalResource> resources) { SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); resources.forEach(resource -> { Optional<? extends Provision> provision = resource.getProvision(any.getType()); if (resource.isEnforceMandatoryCondition() && provision.isPresent()) { List<String> missingAttrNames = evaluateMandatoryCondition(provision.get(), any); if (!missingAttrNames.isEmpty()) { LOG.error("Mandatory schemas {} not provided with values", missingAttrNames); reqValMissing.getElements().addAll(missingAttrNames); } } }); return reqValMissing; }
any.getAuxClasses().clear(); anyTO.getAuxClasses().stream(). map(className -> anyTypeClassDAO.find(className)). LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass); } else { any.add(auxClass); PlainSchema schema = getPlainSchema(attrTO.getSchema()); if (schema != null) { PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null); if (attr == null) { attr = anyUtils.newPlainAttr(); attr.setOwner(null); } else { any.add(attr); LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey); } else { any.add(resource);
typeOwnClasses.addAll(any.getType().getClasses()); typeOwnClasses.addAll(any.getAuxClasses()); ((AnyObject) any).getMemberships().forEach(memb -> { memb.getRightEnd().getTypeExtensions().stream(). filter(typeExtension -> any.getType().equals(typeExtension.getAnyType())). forEachOrdered((typeExtension) -> { typeExtensionClasses.put(memb.getRightEnd(), typeExtension.getAuxClasses());
@Override public Collection<? extends REL> getRelationships(final String otherEndKey) { return getRelationships().stream().filter(relationship -> otherEndKey != null && otherEndKey.equals(relationship.getRightEnd().getKey())). collect(Collectors.toList()); } }
any.remove(attr); plainAttrDAO.delete(attr); filter(resource -> resource.getProvision(any.getType()).isPresent() && resource.getProvision(any.getType()).get().getMapping() != null). forEach(resource -> { MappingUtils.getPropagationItems( resource.getProvision(any.getType()).get().getMapping().getItems()).stream(). filter(item -> (schema.getKey().equals(item.getIntAttrName()))). forEach(item -> {
AllowedSchemas<PlainSchema> allowedPlainSchemas = ApplicationContextProvider.getApplicationContext().getBean(AnyUtilsFactory.class). getInstance(any.getType().getKind()).dao().findAllowedSchemas(any, PlainSchema.class); for (PlainAttr<?> attr : ((Any<?>) any).getPlainAttrs()) { if (attr != null && !allowedPlainSchemas.forSelfContains(attr.getSchema().getKey())) { return raiseNotAllowedViolation(context, attr.getSchema().getKey(), null);
@Override @SuppressWarnings("unchecked") public <T extends PlainAttr<?>> void delete(final T plainAttr) { if (plainAttr.getOwner() != null) { ((Any<T>) plainAttr.getOwner()).remove(plainAttr); } entityManager().remove(plainAttr); } }
private SyncopeClientException checkMandatory(final Any<?> any, final AnyUtils anyUtils) { SyncopeClientException reqValMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); // Check if there is some mandatory schema defined for which no value has been provided AllowedSchemas<PlainSchema> allowedPlainSchemas = anyUtils.dao().findAllowedSchemas(any, PlainSchema.class); allowedPlainSchemas.getForSelf().forEach(schema -> { checkMandatory(schema, any.getPlainAttr(schema.getKey()).orElse(null), any, reqValMissing); }); if (any instanceof GroupableRelatable) { allowedPlainSchemas.getForMemberships().forEach((group, schemas) -> { GroupableRelatable<?, ?, ?, ?, ?> groupable = GroupableRelatable.class.cast(any); Membership<?> membership = groupable.getMembership(group.getKey()).orElse(null); schemas.forEach(schema -> { checkMandatory(schema, groupable.getPlainAttr(schema.getKey(), membership).orElse(null), any, reqValMissing); }); }); } return reqValMissing; }
attr.setOwner(null); } else { any.add(attr);
@SuppressWarnings("unchecked") private Pair<Any<?>, Provision> init(final AnyTypeKind anyTypeKind, final String anyKey, final String resourceKey) { AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind); Any<?> any = anyUtils.dao().authFind(anyKey); if (any == null) { throw new NotFoundException(anyTypeKind + " '" + anyKey + "'"); } ExternalResource resource = resourceDAO.find(resourceKey); if (resource == null) { throw new NotFoundException("Resource '" + resourceKey + "'"); } Provision provision = resource.getProvision(any.getType()).orElseThrow(() -> new NotFoundException("Provision for " + any.getType() + " on Resource '" + resourceKey + "'")); if (provision.getMapping() == null) { throw new NotFoundException("Mapping for " + any.getType() + " on Resource '" + resourceKey + "'"); } return (Pair<Any<?>, Provision>) Pair.of(any, provision); }
protected String check(final MemberCond cond) { String memberKey; if (SyncopeConstants.UUID_PATTERN.matcher(cond.getMember()).matches()) { memberKey = cond.getMember(); } else { Any<?> member = userDAO.findByUsername(cond.getMember()); if (member == null) { member = anyObjectDAO.findByName(cond.getMember()); } memberKey = member == null ? null : member.getKey(); } if (memberKey == null) { LOG.error("Could not find user or any object for '" + cond.getMember() + "'"); throw new IllegalArgumentException(); } return memberKey; }
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_EXECUTE + "')") public void pull( final AnyTypeKind anyTypeKind, final String anyKey, final String resourceKey, final PullTaskTO pullTask) { Pair<Any<?>, Provision> init = init(anyTypeKind, anyKey, resourceKey); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Reconciliation); try { List<ProvisioningReport> results = singlePullExecutor.pull( init.getRight(), connFactory.getConnector(init.getRight().getResource()), init.getRight().getMapping().getConnObjectKeyItem().get().getExtAttrName(), mappingManager.getConnObjectKeyValue(init.getLeft(), init.getRight()).get(), init.getLeft().getRealm(), pullTask); if (!results.isEmpty() && results.get(0).getStatus() == ProvisioningReport.Status.FAILURE) { sce.getElements().add(results.get(0).getMessage()); } } catch (JobExecutionException e) { sce.getElements().add(e.getMessage()); } if (!sce.isEmpty()) { throw sce; } }