Search in sources :

Example 41 with ActivationStatusType

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

the class TestActivation method assertEffectiveStatus.

private <F extends FocusType> void assertEffectiveStatus(PrismObject<F> focus, ActivationStatusType expected) {
    ActivationType activation = focus.asObjectable().getActivation();
    assertNotNull("No activation in " + focus, activation);
    assertEquals("Unexpected effective activation status in " + focus, expected, activation.getEffectiveStatus());
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)

Example 42 with ActivationStatusType

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

the class ResourceObjectConverter method determineActivationChange.

private Collection<Operation> determineActivationChange(ProvisioningContext ctx, ShadowType shadow, Collection<? extends ItemDelta> objectChange, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    Collection<Operation> operations = new ArrayList<>();
    CapabilitiesType connectorCapabilities = ctx.getConnectorCapabilities(UpdateCapabilityType.class);
    ActivationCapabilityType activationCapability = CapabilityUtil.getEffectiveCapability(connectorCapabilities, ActivationCapabilityType.class);
    // administrativeStatus
    PropertyDelta<ActivationStatusType> enabledPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
    if (enabledPropertyDelta != null) {
        if (activationCapability == null) {
            SchemaException e = new SchemaException("Attempt to change activation administrativeStatus on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        ActivationStatusType status = enabledPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation administrativeStatus change to: {}", status);
        if (CapabilityUtil.hasNativeCapability(connectorCapabilities, ActivationCapabilityType.class)) {
            // Native activation, need to check if there is not also change to simulated activation which may be in conflict
            checkSimulatedActivationAdministrativeStatus(ctx, objectChange, status, activationCapability, shadow, result);
            operations.add(new PropertyModificationOperation(enabledPropertyDelta));
        } else {
            // Try to simulate activation capability
            PropertyModificationOperation activationAttribute = convertToSimulatedActivationAdministrativeStatusAttribute(ctx, enabledPropertyDelta, shadow, status, activationCapability, result);
            if (activationAttribute != null) {
                operations.add(activationAttribute);
            }
        }
    }
    // validFrom
    PropertyDelta<XMLGregorianCalendar> validFromPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_VALID_FROM);
    if (validFromPropertyDelta != null) {
        if (CapabilityUtil.getEffectiveActivationValidFrom(activationCapability) == null) {
            SchemaException e = new SchemaException("Attempt to change activation validFrom on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        XMLGregorianCalendar xmlCal = validFromPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation validFrom change to: {}", xmlCal);
        operations.add(new PropertyModificationOperation(validFromPropertyDelta));
    }
    // validTo
    PropertyDelta<XMLGregorianCalendar> validToPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_VALID_TO);
    if (validToPropertyDelta != null) {
        if (CapabilityUtil.getEffectiveActivationValidTo(activationCapability) == null) {
            SchemaException e = new SchemaException("Attempt to change activation validTo on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        XMLGregorianCalendar xmlCal = validToPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation validTo change to: {}", xmlCal);
        operations.add(new PropertyModificationOperation(validToPropertyDelta));
    }
    PropertyDelta<LockoutStatusType> lockoutPropertyDelta = PropertyDelta.findPropertyDelta(objectChange, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
    if (lockoutPropertyDelta != null) {
        if (activationCapability == null) {
            SchemaException e = new SchemaException("Attempt to change activation lockoutStatus on " + resource + " which does not have the capability");
            result.recordFatalError(e);
            throw e;
        }
        LockoutStatusType status = lockoutPropertyDelta.getPropertyNewMatchingPath().getRealValue();
        LOGGER.trace("Found activation lockoutStatus change to: {}", status);
        if (CapabilityUtil.hasNativeCapability(connectorCapabilities, ActivationCapabilityType.class)) {
            // Native lockout, need to check if there is not also change to simulated activation which may be in conflict
            checkSimulatedActivationLockoutStatus(ctx, objectChange, status, activationCapability, shadow, result);
            operations.add(new PropertyModificationOperation(lockoutPropertyDelta));
        } else {
            // Try to simulate lockout capability
            PropertyModificationOperation activationAttribute = convertToSimulatedActivationLockoutStatusAttribute(ctx, lockoutPropertyDelta, shadow, status, activationCapability, result);
            operations.add(activationAttribute);
        }
    }
    return operations;
}
Also used : ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 43 with ActivationStatusType

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

the class ResourceObjectConverter method convertToSimulatedActivationAdministrativeStatusAttribute.

private PropertyModificationOperation convertToSimulatedActivationAdministrativeStatusAttribute(ProvisioningContext ctx, PropertyDelta activationDelta, ShadowType shadow, ActivationStatusType status, ActivationCapabilityType activationCapabilityType, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceType resource = ctx.getResource();
    ActivationStatusCapabilityType capActStatus = getActivationAdministrativeStatusFromSimulatedActivation(ctx, activationCapabilityType, shadow, result);
    if (capActStatus == null) {
        throw new SchemaException("Attempt to modify activation on " + resource + " which does not have activation capability");
    }
    ResourceAttribute<?> simulatedAttribute = getSimulatedActivationAdministrativeStatusAttribute(ctx, shadow, capActStatus, result);
    if (simulatedAttribute == null) {
        return null;
    }
    Class<?> simulatedAttrValueClass = getAttributeValueClass(ctx, shadow, simulatedAttribute, capActStatus);
    PropertyDelta<?> simulatedAttrDelta;
    if (status == null && activationDelta.isDelete()) {
        LOGGER.trace("deleting activation property.");
        simulatedAttrDelta = PropertyDelta.createModificationDeleteProperty(new ItemPath(ShadowType.F_ATTRIBUTES, simulatedAttribute.getElementName()), simulatedAttribute.getDefinition(), simulatedAttribute.getRealValue());
    } else if (status == ActivationStatusType.ENABLED) {
        Object enableValue = getEnableValue(capActStatus, simulatedAttrValueClass);
        simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), enableValue);
    } else {
        Object disableValue = getDisableValue(capActStatus, simulatedAttrValueClass);
        simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), disableValue);
    }
    PropertyModificationOperation attributeChange = new PropertyModificationOperation(simulatedAttrDelta);
    return attributeChange;
}
Also used : ActivationStatusCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with ActivationStatusType

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

the class AbstractBasicDummyTest method assertRepoShadowCacheActivation.

protected void assertRepoShadowCacheActivation(PrismObject<ShadowType> shadowRepo, ActivationStatusType expectedAdministrativeStatus) {
    ActivationType activationType = shadowRepo.asObjectable().getActivation();
    if (activationType == null) {
        return;
    }
    ActivationStatusType administrativeStatus = activationType.getAdministrativeStatus();
    assertNull("Unexpected activation administrativeStatus in repo shadow " + shadowRepo + ": " + administrativeStatus, administrativeStatus);
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)

Example 45 with ActivationStatusType

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

the class ActivationProcessor method processActivationMetadata.

public <F extends FocusType> void processActivationMetadata(LensContext<F> context, LensProjectionContext accCtx, XMLGregorianCalendar now, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<ShadowType> projDelta = accCtx.getDelta();
    if (projDelta == null) {
        return;
    }
    PropertyDelta<ActivationStatusType> statusDelta = projDelta.findPropertyDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
    if (statusDelta != null && !statusDelta.isDelete()) {
        // we have to determine if the status really changed
        PrismObject<ShadowType> oldShadow = accCtx.getObjectOld();
        ActivationStatusType statusOld = null;
        if (oldShadow != null && oldShadow.asObjectable().getActivation() != null) {
            statusOld = oldShadow.asObjectable().getActivation().getAdministrativeStatus();
        }
        PrismProperty<ActivationStatusType> statusPropNew = (PrismProperty<ActivationStatusType>) statusDelta.getItemNewMatchingPath(null);
        ActivationStatusType statusNew = statusPropNew.getRealValue();
        if (statusNew == statusOld) {
            LOGGER.trace("Administrative status not changed ({}), timestamp and/or reason will be recorded", statusNew);
        } else {
            // timestamps
            PropertyDelta<XMLGregorianCalendar> timestampDelta = LensUtil.createActivationTimestampDelta(statusNew, now, getActivationDefinition(), OriginType.OUTBOUND);
            accCtx.swallowToSecondaryDelta(timestampDelta);
            // disableReason
            if (statusNew == ActivationStatusType.DISABLED) {
                PropertyDelta<String> disableReasonDelta = projDelta.findPropertyDelta(SchemaConstants.PATH_ACTIVATION_DISABLE_REASON);
                if (disableReasonDelta == null) {
                    String disableReason = null;
                    ObjectDelta<ShadowType> projPrimaryDelta = accCtx.getPrimaryDelta();
                    ObjectDelta<ShadowType> projSecondaryDelta = accCtx.getSecondaryDelta();
                    if (projPrimaryDelta != null && projPrimaryDelta.findPropertyDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS) != null && (projSecondaryDelta == null || projSecondaryDelta.findPropertyDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS) == null)) {
                        disableReason = SchemaConstants.MODEL_DISABLE_REASON_EXPLICIT;
                    } else if (accCtx.isLegal()) {
                        disableReason = SchemaConstants.MODEL_DISABLE_REASON_MAPPED;
                    } else {
                        disableReason = SchemaConstants.MODEL_DISABLE_REASON_DEPROVISION;
                    }
                    PrismPropertyDefinition<String> disableReasonDef = activationDefinition.findPropertyDefinition(ActivationType.F_DISABLE_REASON);
                    disableReasonDelta = disableReasonDef.createEmptyDelta(new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_DISABLE_REASON));
                    disableReasonDelta.setValueToReplace(new PrismPropertyValue<String>(disableReason, OriginType.OUTBOUND, null));
                    accCtx.swallowToSecondaryDelta(disableReasonDelta);
                }
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)48 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)43 Test (org.testng.annotations.Test)30 AbstractUnitTest (com.evolveum.midpoint.tools.testng.AbstractUnitTest)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 ActivationStatusCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 TimeIntervalStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)2 LockoutStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType)2 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1