Search in sources :

Example 36 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 37 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)

Example 38 with ActivationStatusType

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

the class FocusProcessor method processActivationAdministrativeAndValidity.

private <F extends FocusType> void processActivationAdministrativeAndValidity(LensFocusContext<F> focusContext, XMLGregorianCalendar now, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    TimeIntervalStatusType validityStatusNew = null;
    TimeIntervalStatusType validityStatusCurrent = null;
    XMLGregorianCalendar validityChangeTimestamp = null;
    String lifecycleStateNew = null;
    String lifecycleStateCurrent = null;
    ActivationType activationNew = null;
    ActivationType activationCurrent = null;
    PrismObject<F> focusNew = focusContext.getObjectNew();
    if (focusNew != null) {
        F focusTypeNew = focusNew.asObjectable();
        activationNew = focusTypeNew.getActivation();
        if (activationNew != null) {
            validityStatusNew = activationComputer.getValidityStatus(activationNew, now);
            validityChangeTimestamp = activationNew.getValidityChangeTimestamp();
        }
        lifecycleStateNew = focusTypeNew.getLifecycleState();
    }
    PrismObject<F> focusCurrent = focusContext.getObjectCurrent();
    if (focusCurrent != null) {
        F focusCurrentType = focusCurrent.asObjectable();
        activationCurrent = focusCurrentType.getActivation();
        if (activationCurrent != null) {
            validityStatusCurrent = activationComputer.getValidityStatus(activationCurrent, validityChangeTimestamp);
        }
        lifecycleStateCurrent = focusCurrentType.getLifecycleState();
    }
    if (validityStatusCurrent == validityStatusNew) {
        // No change, (almost) no work
        if (validityStatusNew != null && activationNew.getValidityStatus() == null) {
            // There was no validity change. But the status is not recorded. So let's record it so it can be used in searches. 
            recordValidityDelta(focusContext, validityStatusNew, now);
        } else {
            LOGGER.trace("Skipping validity processing because there was no change ({} -> {})", validityStatusCurrent, validityStatusNew);
        }
    } else {
        LOGGER.trace("Validity change {} -> {}", validityStatusCurrent, validityStatusNew);
        recordValidityDelta(focusContext, validityStatusNew, now);
    }
    ActivationStatusType effectiveStatusNew = activationComputer.getEffectiveStatus(lifecycleStateNew, activationNew, validityStatusNew);
    ActivationStatusType effectiveStatusCurrent = activationComputer.getEffectiveStatus(lifecycleStateCurrent, activationCurrent, validityStatusCurrent);
    if (effectiveStatusCurrent == effectiveStatusNew) {
        // No change, (almost) no work
        if (effectiveStatusNew != null && (activationNew == null || activationNew.getEffectiveStatus() == null)) {
            // There was no effective status change. But the status is not recorded. So let's record it so it can be used in searches. 
            recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
        } else {
            if (focusContext.getPrimaryDelta() != null && focusContext.getPrimaryDelta().hasItemDelta(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS)) {
                LOGGER.trace("Forcing effective status delta even though there was no change ({} -> {}) because there is explicit administrativeStatus delta", effectiveStatusCurrent, effectiveStatusNew);
                // We need this to force the change down to the projections later in the activation processor
                // some of the mappings will use effectiveStatus as a source, therefore there has to be a delta for the mapping to work correctly
                recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
            } else {
                LOGGER.trace("Skipping effective status processing because there was no change ({} -> {})", effectiveStatusCurrent, effectiveStatusNew);
            }
        }
    } else {
        LOGGER.trace("Effective status change {} -> {}", effectiveStatusCurrent, effectiveStatusNew);
        recordEffectiveStatusDelta(focusContext, effectiveStatusNew, now);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) TimeIntervalStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 39 with ActivationStatusType

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

the class TestProjector method test254ModifyUserBarbossaDisable.

/**
	 * User barbossa has a direct account assignment. This assignment has an expression for enabledisable flag.
	 * Let's disable user, the account should be disabled as well.
	 */
@Test
public void test254ModifyUserBarbossaDisable() throws Exception {
    final String TEST_NAME = "test254ModifyUserBarbossaDisable";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjector.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_BARBOSSA_OID, result);
    fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
    addModificationToContextReplaceUserProperty(context, new ItemPath(UserType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), ActivationStatusType.DISABLED);
    context.recompute();
    display("Input context", context);
    assertFocusModificationSanity(context);
    // WHEN
    projector.project(context, "test", task, result);
    // THEN
    display("Output context", context);
    assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY);
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.DISABLED);
    assertFalse("No account changes", context.getProjectionContexts().isEmpty());
    Collection<LensProjectionContext> accountContexts = context.getProjectionContexts();
    assertEquals(1, accountContexts.size());
    LensProjectionContext accContext = accountContexts.iterator().next();
    assertNull(accContext.getPrimaryDelta());
    assertEquals(SynchronizationPolicyDecision.KEEP, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertNotNull("No account secondary delta", accountSecondaryDelta);
    assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
    assertEquals("Unexpected number of account secondary changes", 6, accountSecondaryDelta.getModifications().size());
    PropertyDelta<ActivationStatusType> enabledDelta = accountSecondaryDelta.findPropertyDelta(new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS));
    PrismAsserts.assertReplace(enabledDelta, ActivationStatusType.DISABLED);
    PrismAsserts.assertOrigin(enabledDelta, OriginType.OUTBOUND);
    PrismAsserts.assertPropertyReplace(accountSecondaryDelta, SchemaConstants.PATH_ACTIVATION_DISABLE_REASON, SchemaConstants.MODEL_DISABLE_REASON_MAPPED);
    ContainerDelta<TriggerType> triggerDelta = accountSecondaryDelta.findContainerDelta(ObjectType.F_TRIGGER);
    assertNotNull("No trigger delta in account secondary delta", triggerDelta);
    assertEquals("Wrong trigger delta size", 1, triggerDelta.getValuesToAdd().size());
    TriggerType triggerType = triggerDelta.getValuesToAdd().iterator().next().asContainerable();
    assertEquals("Wrong trigger URL", RecomputeTriggerHandler.HANDLER_URI, triggerType.getHandlerUri());
    XMLGregorianCalendar start = clock.currentTimeXMLGregorianCalendar();
    start.add(XmlTypeConverter.createDuration(true, 0, 0, 25, 0, 0, 0));
    XMLGregorianCalendar end = clock.currentTimeXMLGregorianCalendar();
    end.add(XmlTypeConverter.createDuration(true, 0, 0, 35, 0, 0, 0));
    TestUtil.assertBetween("Wrong trigger timestamp", start, end, triggerType.getTimestamp());
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 40 with ActivationStatusType

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

the class TestPreviewChanges method test220PreviewJackAssignRolePirate.

/**
	 * MID-3079
	 */
@Test
public void test220PreviewJackAssignRolePirate() throws Exception {
    final String TEST_NAME = "test220PreviewJackAssignRolePirate";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    ObjectDelta<UserType> delta = createAssignmentFocusDelta(UserType.class, USER_JACK_OID, ROLE_PIRATE_OID, RoleType.COMPLEX_TYPE, null, null, null, true);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ModelContext<UserType> modelContext = modelInteractionService.previewChanges(MiscSchemaUtil.createCollection(delta), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Preview context", modelContext);
    assertNotNull("Null model context", modelContext);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
    assertNotNull("Model focus context missing", focusContext);
    Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
    assertNotNull("Null model projection context list", projectionContexts);
    assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
    ModelProjectionContext accContext = projectionContexts.iterator().next();
    assertNotNull("Null model projection context", accContext);
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertNull("Unexpected account primary delta", accountPrimaryDelta);
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
    assertAccountItemModify(accountSecondaryDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, // old
    null, // add
    null, // delete
    null, // replace
    new ActivationStatusType[] { ActivationStatusType.ENABLED });
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, // old
    null, // add
    new String[] { ROLE_PIRATE_WEAPON }, // delete
    null, // replace
    null);
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, // old
    null, // add
    new String[] { ROLE_PIRATE_TITLE }, // delete
    null, // replace
    null);
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DUMMY_ACCOUNT_ATTRIBUTE_SEA_NAME, // old
    null, // add
    null, // delete
    null, // replace
    new String[] { "jack sailed The Seven Seas, immediately , role , with this The Seven Seas while focused on  (in Pirate)" });
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, // old
    null, // add
    new String[] { "Jack Sparrow is the best pirate Caribbean has ever seen" }, // delete
    null, // replace
    null);
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, // old
    null, // add
    new String[] { RESOURCE_DUMMY_QUOTE }, // delete
    null, // replace
    null);
    assertAccountDefaultDummyAttributeModify(accountSecondaryDelta, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, // old
    null, // add
    new String[] { RESOURCE_DUMMY_DRINK }, // delete
    null, // replace
    null);
    PrismAsserts.assertModifications(accountSecondaryDelta, 15);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)32 ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)24 Test (org.testng.annotations.Test)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)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 TimeIntervalStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 ActivationStatusCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType)2 ArrayList (java.util.ArrayList)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1