Search in sources :

Example 61 with ActivationType

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

the class FocusProcessor method processActivationLockout.

private <F extends FocusType> void processActivationLockout(LensFocusContext<UserType> focusContext, XMLGregorianCalendar now, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<UserType> focusPrimaryDelta = focusContext.getPrimaryDelta();
    if (focusPrimaryDelta != null) {
        PropertyDelta<LockoutStatusType> lockoutStatusDelta = focusContext.getPrimaryDelta().findPropertyDelta(SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
        if (lockoutStatusDelta != null) {
            if (lockoutStatusDelta.isAdd()) {
                for (PrismPropertyValue<LockoutStatusType> pval : lockoutStatusDelta.getValuesToAdd()) {
                    if (pval.getValue() == LockoutStatusType.LOCKED) {
                        throw new SchemaException("Lockout status cannot be changed to LOCKED value");
                    }
                }
            } else if (lockoutStatusDelta.isReplace()) {
                for (PrismPropertyValue<LockoutStatusType> pval : lockoutStatusDelta.getValuesToReplace()) {
                    if (pval.getValue() == LockoutStatusType.LOCKED) {
                        throw new SchemaException("Lockout status cannot be changed to LOCKED value");
                    }
                }
            }
        }
    }
    ActivationType activationNew = null;
    ActivationType activationCurrent = null;
    LockoutStatusType lockoutStatusNew = null;
    LockoutStatusType lockoutStatusCurrent = null;
    PrismObject<UserType> focusNew = focusContext.getObjectNew();
    if (focusNew != null) {
        activationNew = focusNew.asObjectable().getActivation();
        if (activationNew != null) {
            lockoutStatusNew = activationNew.getLockoutStatus();
        }
    }
    PrismObject<UserType> focusCurrent = focusContext.getObjectCurrent();
    if (focusCurrent != null) {
        activationCurrent = focusCurrent.asObjectable().getActivation();
        if (activationCurrent != null) {
            lockoutStatusCurrent = activationCurrent.getLockoutStatus();
        }
    }
    if (lockoutStatusNew == lockoutStatusCurrent) {
        // No change, (almost) no work
        LOGGER.trace("Skipping lockout processing because there was no change ({} -> {})", lockoutStatusCurrent, lockoutStatusNew);
        return;
    }
    LOGGER.trace("Lockout change {} -> {}", lockoutStatusCurrent, lockoutStatusNew);
    if (lockoutStatusNew == LockoutStatusType.NORMAL) {
        CredentialsType credentialsTypeNew = focusNew.asObjectable().getCredentials();
        if (credentialsTypeNew != null) {
            resetFailedLogins(focusContext, credentialsTypeNew.getPassword(), SchemaConstants.PATH_CREDENTIALS_PASSWORD_FAILED_LOGINS);
            resetFailedLogins(focusContext, credentialsTypeNew.getNonce(), SchemaConstants.PATH_CREDENTIALS_NONCE_FAILED_LOGINS);
            resetFailedLogins(focusContext, credentialsTypeNew.getSecurityQuestions(), SchemaConstants.PATH_CREDENTIALS_SECURITY_QUESTIONS_FAILED_LOGINS);
        }
        if (activationNew != null && activationNew.getLockoutExpirationTimestamp() != null) {
            PrismContainerDefinition<ActivationType> activationDefinition = getActivationDefinition();
            PrismPropertyDefinition<XMLGregorianCalendar> lockoutExpirationTimestampDef = activationDefinition.findPropertyDefinition(ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP);
            PropertyDelta<XMLGregorianCalendar> lockoutExpirationTimestampDelta = lockoutExpirationTimestampDef.createEmptyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP));
            lockoutExpirationTimestampDelta.setValueToReplace();
            focusContext.swallowToProjectionWaveSecondaryDelta(lockoutExpirationTimestampDelta);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) LockoutStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 62 with ActivationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType 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 63 with ActivationType

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

the class FocusProcessor method recordValidityDelta.

private <F extends ObjectType> void recordValidityDelta(LensFocusContext<F> focusContext, TimeIntervalStatusType validityStatusNew, XMLGregorianCalendar now) throws SchemaException {
    PrismContainerDefinition<ActivationType> activationDefinition = getActivationDefinition();
    PrismPropertyDefinition<TimeIntervalStatusType> validityStatusDef = activationDefinition.findPropertyDefinition(ActivationType.F_VALIDITY_STATUS);
    PropertyDelta<TimeIntervalStatusType> validityStatusDelta = validityStatusDef.createEmptyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_VALIDITY_STATUS));
    if (validityStatusNew == null) {
        validityStatusDelta.setValueToReplace();
    } else {
        validityStatusDelta.setValueToReplace(new PrismPropertyValue<>(validityStatusNew, OriginType.USER_POLICY, null));
    }
    focusContext.swallowToProjectionWaveSecondaryDelta(validityStatusDelta);
    PrismPropertyDefinition<XMLGregorianCalendar> validityChangeTimestampDef = activationDefinition.findPropertyDefinition(ActivationType.F_VALIDITY_CHANGE_TIMESTAMP);
    PropertyDelta<XMLGregorianCalendar> validityChangeTimestampDelta = validityChangeTimestampDef.createEmptyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_VALIDITY_CHANGE_TIMESTAMP));
    validityChangeTimestampDelta.setValueToReplace(new PrismPropertyValue<>(now, OriginType.USER_POLICY, null));
    focusContext.swallowToProjectionWaveSecondaryDelta(validityChangeTimestampDelta);
}
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) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 64 with ActivationType

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

the class AbstractModelIntegrationTest method createUser.

protected PrismObject<UserType> createUser(String name, String givenName, String familyName, Boolean enabled) throws SchemaException {
    PrismObject<UserType> user = getUserDefinition().instantiate();
    UserType userType = user.asObjectable();
    userType.setName(PrismTestUtil.createPolyStringType(name));
    userType.setGivenName(PrismTestUtil.createPolyStringType(givenName));
    userType.setFamilyName(PrismTestUtil.createPolyStringType(familyName));
    userType.setFullName(PrismTestUtil.createPolyStringType(givenName + " " + familyName));
    if (enabled != null) {
        ActivationType activation = new ActivationType();
        userType.setActivation(activation);
        if (enabled) {
            activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
        } else {
            activation.setAdministrativeStatus(ActivationStatusType.DISABLED);
        }
    }
    return user;
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 65 with ActivationType

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

the class AbstractModelIntegrationTest method getActivation.

protected ActivationType getActivation(PrismObject<? extends ObjectType> obj) {
    ObjectType objectType = obj.asObjectable();
    ActivationType activation;
    if (objectType instanceof ShadowType) {
        activation = ((ShadowType) objectType).getActivation();
    } else if (objectType instanceof UserType) {
        activation = ((UserType) objectType).getActivation();
    } else {
        throw new IllegalArgumentException("Cannot get activation from " + obj);
    }
    assertNotNull("No activation in " + obj, activation);
    return activation;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ActivationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)59 Test (org.testng.annotations.Test)34 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)22 Task (com.evolveum.midpoint.task.api.Task)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)12 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 ObjectWrapperFactory (com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory)5 LockoutStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType)5 ActivationCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType)4 ActivationStatusCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationStatusCapabilityType)4 QName (javax.xml.namespace.QName)4 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)3 TimeIntervalStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType)3 ActivationLockoutStatusCapabilityType (com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationLockoutStatusCapabilityType)3