Search in sources :

Example 21 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class TestLdapDependency method assertLdapObject.

private void assertLdapObject(PrismObject<OrgType> org, ShadowKindType kind, String intent) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, DirectoryException, ExpressionEvaluationException {
    String orgName = org.getName().toString();
    display("assert org", orgName);
    String objOid = getLinkRefOid(org, RESOURCE_OPENDJ_OID, kind, intent);
    PrismObject<ShadowType> objShadow = getShadowModel(objOid);
    display("Org " + orgName + " kind " + kind + " intent " + intent + " shadow", objShadow);
    // TODO assert shadow content
    String search = "";
    if (kind.equals(ShadowKindType.ENTITLEMENT)) {
        if (LDAP_GROUP_INTENT.equals(intent))
            search = "cn=" + orgName;
        if (LDAP_GROUP_VIP_INTENT.equals(intent))
            search = "cn=" + orgName + "-vip";
        if (LDAP_GROUP_SUPERVIP_INTENT.equals(intent))
            search = "cn=" + orgName + "-supervip";
    }
    if (kind.equals(ShadowKindType.GENERIC)) {
        if (LDAP_OU_INTENT.equals(intent))
            search = "ou=" + orgName;
        if (LDAP_OU_VIP_INTENT.equals(intent))
            search = "ou=" + orgName + "-vip";
    }
    Entry objEntry = openDJController.searchSingle(search);
    assertNotNull("No LDAP entry for " + orgName, objEntry);
    ;
    display("LDAP entry kind " + kind + " inten " + intent + " ldapObj", objEntry);
    if (kind.equals(ShadowKindType.ENTITLEMENT)) {
        openDJController.assertObjectClass(objEntry, "groupOfUniqueNames");
    }
    if (kind.equals(ShadowKindType.GENERIC)) {
        openDJController.assertObjectClass(objEntry, "organizationalUnit");
    }
}
Also used : Entry(org.opends.server.types.Entry) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 22 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class Construction method evaluateKindIntentObjectClass.

private void evaluateKindIntentObjectClass(Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    String resourceOid = null;
    if (getConstructionType().getResourceRef() != null) {
        resourceOid = getConstructionType().getResourceRef().getOid();
    }
    if (getConstructionType().getResource() != null) {
        resourceOid = getConstructionType().getResource().getOid();
    }
    ResourceType resource = getResource(task, result);
    if (resourceOid != null && !resource.getOid().equals(resourceOid)) {
        throw new IllegalStateException("The specified resource and the resource in construction does not match");
    }
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, getPrismContext());
    if (refinedSchema == null) {
        // Refined schema may be null in some error-related border cases
        throw new SchemaException("No (refined) schema for " + resource);
    }
    ShadowKindType kind = getConstructionType().getKind();
    if (kind == null) {
        kind = ShadowKindType.ACCOUNT;
    }
    refinedObjectClassDefinition = refinedSchema.getRefinedDefinition(kind, getConstructionType().getIntent());
    if (refinedObjectClassDefinition == null) {
        if (getConstructionType().getIntent() != null) {
            throw new SchemaException("No " + kind + " type '" + getConstructionType().getIntent() + "' found in " + getResource(task, result) + " as specified in construction in " + getSource());
        } else {
            throw new SchemaException("No default " + kind + " type found in " + resource + " as specified in construction in " + getSource());
        }
    }
    auxiliaryObjectClassDefinitions = new ArrayList<>(getConstructionType().getAuxiliaryObjectClass().size());
    for (QName auxiliaryObjectClassName : getConstructionType().getAuxiliaryObjectClass()) {
        RefinedObjectClassDefinition auxOcDef = refinedSchema.getRefinedDefinition(auxiliaryObjectClassName);
        if (auxOcDef == null) {
            throw new SchemaException("No auxiliary object class " + auxiliaryObjectClassName + " found in " + getResource(task, result) + " as specified in construction in " + getSource());
        }
        auxiliaryObjectClassDefinitions.add(auxOcDef);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) QName(javax.xml.namespace.QName) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema)

Example 23 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method reportOrFixUniqueness.

private String reportOrFixUniqueness(Task task, OperationResult result) {
    StringBuilder details = new StringBuilder();
    StringBuilder stat = new StringBuilder();
    for (Map.Entry<Pair<String, ShadowKindType>, ObjectTypeContext> entry : contextMap.entrySet()) {
        String resourceOid = entry.getKey().getLeft();
        ShadowKindType kind = entry.getKey().getRight();
        ObjectTypeContext ctx = entry.getValue();
        PrismObject<ResourceType> resource = resources.get(resourceOid);
        if (resource == null) {
            // should not happen
            LOGGER.error("No resource for {}", resourceOid);
            continue;
        }
        for (Map.Entry<QName, Map<String, List<PrismObject<ShadowType>>>> idValEntry : ctx.getIdentifierValueMap().entrySet()) {
            QName identifier = idValEntry.getKey();
            boolean first = true;
            for (Map.Entry<String, List<PrismObject<ShadowType>>> valListEntry : idValEntry.getValue().entrySet()) {
                List<PrismObject<ShadowType>> shadows = valListEntry.getValue();
                if (shadows.size() <= 1) {
                    continue;
                }
                if (first) {
                    details.append("Duplicates for ").append(ObjectTypeUtil.toShortString(resource));
                    details.append(", kind = ").append(kind);
                    details.append(", identifier = ").append(identifier).append(":\n");
                    first = false;
                }
                details.append(" - value: ").append(valListEntry.getKey()).append(", shadows: ").append(shadows.size()).append("\n");
                List<PrismObject<ShadowType>> shadowsToConsider = new ArrayList<>();
                for (PrismObject<ShadowType> shadow : shadows) {
                    details.append("   - ").append(ObjectTypeUtil.toShortString(shadow));
                    details.append("; sync situation = ").append(shadow.asObjectable().getSynchronizationSituation()).append("\n");
                    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
                    if (attributesContainer != null && !attributesContainer.isEmpty()) {
                        for (Item item : attributesContainer.getValue().getItems()) {
                            details.append("     - ").append(item.getElementName().getLocalPart()).append(" = ");
                            details.append(item.getRealValues());
                            details.append("\n");
                        }
                    }
                    if (duplicateShadowsDeleted.contains(shadow.getOid())) {
                        details.append("     (already deleted)\n");
                    } else {
                        shadowsToConsider.add(shadow);
                    }
                }
                if (fixUniqueness && shadowsToConsider.size() > 1) {
                    DuplicateShadowsTreatmentInstruction instruction = duplicateShadowsResolver.determineDuplicateShadowsTreatment(shadowsToConsider);
                    deleteShadows(instruction, details, task, result);
                }
            }
        }
    }
    stat.append("Duplicate shadows detected: ").append(duplicateShadowsDetected.size());
    if (fixUniqueness) {
        stat.append(", deleted: ").append(duplicateShadowsDeleted.size());
    // TODO report the duplicates that remain
    }
    // there can be many 'search owner' subresults
    result.summarize();
    return stat.toString() + "\n" + details.toString();
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject) Item(com.evolveum.midpoint.prism.Item) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 24 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method createLensContext.

@NotNull
private <F extends FocusType> LensContext<F> createLensContext(Class<F> focusClass, ResourceObjectShadowChangeDescription change, SynchronizationReactionType reactionDefinition, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ModelExecuteOptions options, PrismObject<SystemConfigurationType> configuration, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    LensContext<F> context = contextFactory.createSyncContext(focusClass, change);
    context.setLazyAuditRequest(true);
    context.setSystemConfiguration(configuration);
    context.setOptions(options);
    ResourceType resource = change.getResource().asObjectable();
    if (ModelExecuteOptions.isLimitPropagation(options)) {
        context.setTriggeredResource(resource);
    }
    context.rememberResource(resource);
    PrismObject<ShadowType> shadow = getShadowFromChange(change);
    if (InternalsConfig.consistencyChecks)
        shadow.checkConsistence();
    // Projection context
    ShadowKindType kind = getKind(shadow, synchronizationPolicy);
    String intent = getIntent(shadow, synchronizationPolicy);
    boolean thombstone = isThombstone(change);
    ResourceShadowDiscriminator descr = new ResourceShadowDiscriminator(resource.getOid(), kind, intent, thombstone);
    LensProjectionContext projectionContext = context.createProjectionContext(descr);
    projectionContext.setResource(resource);
    projectionContext.setOid(getOidFromChange(change));
    projectionContext.setSynchronizationSituationDetected(situation.getSituation());
    // insert object delta if available in change
    ObjectDelta<? extends ShadowType> delta = change.getObjectDelta();
    if (delta != null) {
        projectionContext.setSyncDelta((ObjectDelta<ShadowType>) delta);
    } else {
        projectionContext.setSyncAbsoluteTrigger(true);
    }
    // we insert account if available in change
    PrismObject<ShadowType> currentAccount = shadow;
    if (currentAccount != null) {
        projectionContext.setLoadedObject(currentAccount);
        if (!thombstone) {
            projectionContext.setFullShadow(true);
        }
        projectionContext.setFresh(true);
    }
    if (delta != null && delta.isDelete()) {
        projectionContext.setExists(false);
    } else {
        projectionContext.setExists(true);
    }
    projectionContext.setDoReconciliation(ModelExecuteOptions.isReconcile(options));
    // Focus context
    if (situation.getCurrentOwner() != null) {
        F focusType = situation.getCurrentOwner();
        LensFocusContext<F> focusContext = context.createFocusContext();
        PrismObject<F> focusOld = (PrismObject<F>) focusType.asPrismObject();
        focusContext.setLoadedObject(focusOld);
    }
    // Global stuff
    ObjectReferenceType objectTemplateRef = null;
    if (reactionDefinition.getObjectTemplateRef() != null) {
        objectTemplateRef = reactionDefinition.getObjectTemplateRef();
    } else if (synchronizationPolicy.getObjectTemplateRef() != null) {
        objectTemplateRef = synchronizationPolicy.getObjectTemplateRef();
    }
    if (objectTemplateRef != null) {
        ObjectTemplateType objectTemplate = repositoryService.getObject(ObjectTemplateType.class, objectTemplateRef.getOid(), null, parentResult).asObjectable();
        context.setFocusTemplate(objectTemplate);
    }
    return context;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with ShadowKindType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method saveSyncMetadata.

/**
	 * Saves situation, timestamps, kind and intent (if needed)
	 */
private PrismObject<ShadowType> saveSyncMetadata(PrismObject<ShadowType> shadow, SynchronizationSituation situation, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, Task task, OperationResult parentResult) {
    if (shadow == null) {
        return null;
    }
    ShadowType shadowType = shadow.asObjectable();
    // new situation description
    List<PropertyDelta<?>> deltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(shadow, situation.getSituation(), change.getSourceChannel(), true);
    if (shadowType.getKind() == null) {
        ShadowKindType kind = synchronizationPolicy.getKind();
        if (kind == null) {
            kind = ShadowKindType.ACCOUNT;
        }
        PropertyDelta<ShadowKindType> kindDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_KIND, kind);
        deltas.add(kindDelta);
    }
    if (shadowType.getIntent() == null) {
        String intent = synchronizationPolicy.getIntent();
        if (intent == null) {
            intent = SchemaConstants.INTENT_DEFAULT;
        }
        PropertyDelta<String> intentDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_INTENT, intent);
        deltas.add(intentDelta);
    }
    try {
        repositoryService.modifyObject(shadowType.getClass(), shadow.getOid(), deltas, parentResult);
        ItemDelta.applyTo(deltas, shadow);
        task.recordObjectActionExecuted(shadow, ChangeType.MODIFY, null);
        return shadow;
    } catch (ObjectNotFoundException ex) {
        task.recordObjectActionExecuted(shadow, ChangeType.MODIFY, ex);
        // This may happen e.g. during some recon-livesync interactions.
        // If the shadow is gone then it is gone. No point in recording the
        // situation any more.
        LOGGER.debug("Could not update situation in account, because shadow {} does not exist any more (this may be harmless)", shadow.getOid());
        parentResult.getLastSubresult().setStatus(OperationResultStatus.HANDLED_ERROR);
    } catch (ObjectAlreadyExistsException | SchemaException ex) {
        task.recordObjectActionExecuted(shadow, ChangeType.MODIFY, ex);
        LoggingUtils.logException(LOGGER, "### SYNCHRONIZATION # notifyChange(..): Save of synchronization situation failed: could not modify shadow " + shadow.getOid() + ": " + ex.getMessage(), ex);
        parentResult.recordFatalError("Save of synchronization situation failed: could not modify shadow " + shadow.getOid() + ": " + ex.getMessage(), ex);
        throw new SystemException("Save of synchronization situation failed: could not modify shadow " + shadow.getOid() + ": " + ex.getMessage(), ex);
    } catch (Throwable t) {
        task.recordObjectActionExecuted(shadow, ChangeType.MODIFY, t);
        throw t;
    }
    return null;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)33 QName (javax.xml.namespace.QName)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 ArrayList (java.util.ArrayList)7 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 List (java.util.List)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 NotNull (org.jetbrains.annotations.NotNull)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)3 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)3 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3