Search in sources :

Example 31 with ObjectReferenceType

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

the class SystemConfigurationDto method getNewObject.

public SystemConfigurationType getNewObject() throws DatatypeConfigurationException {
    SystemConfigurationType newObject = oldObject.clone();
    if (StringUtils.isNotBlank(getPassPolicyDto().getOid())) {
        ObjectReferenceType globalPassPolicyRef = ObjectTypeUtil.createObjectRef(getPassPolicyDto().getOid(), ObjectTypes.PASSWORD_POLICY);
        newObject.setGlobalPasswordPolicyRef(globalPassPolicyRef);
    } else {
        newObject.setGlobalPasswordPolicyRef(null);
    }
    if (StringUtils.isNotBlank(getSecurityPolicyDto().getOid())) {
        ObjectReferenceType globalSecurityPolicyRef = ObjectTypeUtil.createObjectRef(getSecurityPolicyDto().getOid(), WebComponentUtil.createPolyFromOrigString(getSecurityPolicyDto().getName()), ObjectTypes.SECURITY_POLICY);
        newObject.setGlobalSecurityPolicyRef(globalSecurityPolicyRef);
    } else {
        newObject.setGlobalSecurityPolicyRef(null);
    }
    AssignmentPolicyEnforcementType globalAEP = AEPlevel.toAEPValueType(getAepLevel());
    if (globalAEP != null) {
        ProjectionPolicyType projectionPolicy = new ProjectionPolicyType();
        projectionPolicy.setAssignmentPolicyEnforcement(globalAEP);
        newObject.setGlobalAccountSynchronizationSettings(projectionPolicy);
    }
    Duration auditCleanupDuration = DatatypeFactory.newInstance().newDuration(getAuditCleanupValue());
    Duration cleanupTaskDuration = DatatypeFactory.newInstance().newDuration(getTaskCleanupValue());
    CleanupPolicyType auditCleanup = new CleanupPolicyType();
    CleanupPolicyType taskCleanup = new CleanupPolicyType();
    auditCleanup.setMaxAge(auditCleanupDuration);
    taskCleanup.setMaxAge(cleanupTaskDuration);
    CleanupPoliciesType cleanupPolicies = new CleanupPoliciesType();
    cleanupPolicies.setAuditRecords(auditCleanup);
    cleanupPolicies.setClosedTasks(taskCleanup);
    newObject.setCleanupPolicy(cleanupPolicies);
    SystemConfigurationTypeUtil.setEnableExperimentalCode(newObject, getEnableExperimentalCode());
    newObject.setLogging(loggingConfig.getNewObject());
    newObject.setNotificationConfiguration(notificationConfig.getNewObject(newObject));
    newObject.setProfilingConfiguration(profilingDto.getNewObject());
    ClassLoggerConfigurationType profilingClassLogger = profilingDto.getProfilingClassLogerConfig();
    if (newObject.getLogging() != null) {
        newObject.getLogging().getClassLogger().add(profilingClassLogger);
    } else {
        LoggingConfigurationType profLogging = new LoggingConfigurationType();
        profLogging.getClassLogger().add(profilingClassLogger);
        newObject.setLogging(profLogging);
    }
    return newObject;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) LoggingConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType) AssignmentPolicyEnforcementType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType) CleanupPoliciesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Duration(javax.xml.datatype.Duration) ClassLoggerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType) ProjectionPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionPolicyType)

Example 32 with ObjectReferenceType

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

the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
    for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
        ShadowType shadowType;
        try {
            shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
        } catch (ObjectNotFoundException e) {
            // Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
            // the chance to react yet. Just ignore such shadow.
            LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
            continue;
        }
        if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            ObjectReferenceType shadowRef = new ObjectReferenceType();
            shadowRef.setOid(linkRef.getOid());
            shadowAssociationType.setShadowRef(shadowRef);
        }
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 33 with ObjectReferenceType

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

the class AssociationTargetSearchExpressionEvaluator method createPrismValue.

protected PrismContainerValue<ShadowAssociationType> createPrismValue(String oid, QName targetTypeQName, List<ItemDelta<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> additionalAttributeDeltas, ExpressionEvaluationContext params) {
    ShadowAssociationType associationType = new ShadowAssociationType();
    PrismContainerValue<ShadowAssociationType> associationCVal = associationType.asPrismContainerValue();
    associationType.setName(params.getMappingQName());
    ObjectReferenceType targetRef = new ObjectReferenceType();
    targetRef.setOid(oid);
    targetRef.setType(targetTypeQName);
    associationType.setShadowRef(targetRef);
    try {
        if (additionalAttributeDeltas != null) {
            ItemDelta.applyTo(additionalAttributeDeltas, associationCVal);
        }
        getPrismContext().adopt(associationCVal, ShadowType.COMPLEX_TYPE, new ItemPath(ShadowType.F_ASSOCIATION));
        if (InternalsConfig.consistencyChecks) {
            associationCVal.assertDefinitions("associationCVal in assignment expression in " + params.getContextDescription());
        }
    } catch (SchemaException e) {
        // Should not happen
        throw new SystemException(e);
    }
    return associationCVal;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 34 with ObjectReferenceType

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

the class GenerateExpressionEvaluator method evaluate.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java
	 * .util.Collection, java.util.Map, boolean, java.lang.String,
	 * com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    StringPolicyType stringPolicyType = null;
    ObjectReferenceType generateEvaluatorValuePolicyRef = generateEvaluatorType.getValuePolicyRef();
    if (generateEvaluatorValuePolicyRef != null) {
        if (generateEvaluatorType.getValuePolicyRef() != null) {
            ValuePolicyType valuePolicyType = objectResolver.resolve(generateEvaluatorValuePolicyRef, ValuePolicyType.class, null, "resolving value policy reference in generateExpressionEvaluator", context.getTask(), context.getResult());
            stringPolicyType = valuePolicyType.getStringPolicy();
        }
    }
    // would be generated
    if (stringPolicyType == null) {
        StringPolicyResolver stringPolicyResolver = context.getStringPolicyResolver();
        if (stringPolicyResolver != null) {
            stringPolicyType = stringPolicyResolver.resolve();
        }
    }
    elementStringPolicy = stringPolicyType;
    // } else {
    // stringPolicyType = elementStringPolicy;
    // }
    //
    String stringValue = null;
    GenerateExpressionEvaluatorModeType mode = generateEvaluatorType.getMode();
    Item<V, D> output = outputDefinition.instantiate();
    if (mode == null || mode == GenerateExpressionEvaluatorModeType.POLICY) {
        PrismObject<? extends ObjectType> object = getObject(context);
        // TODO: generate value based on stringPolicyType (if not null)
        if (stringPolicyType != null) {
            if (isNotEmptyMinLength(stringPolicyType)) {
                stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, true, object, context.getContextDescription(), context.getTask(), context.getResult());
            } else {
                stringValue = valuePolicyGenerator.generate(output.getPath(), stringPolicyType, DEFAULT_LENGTH, false, object, context.getContextDescription(), context.getTask(), context.getResult());
            }
            context.getResult().computeStatus();
            if (context.getResult().isError()) {
                throw new ExpressionEvaluationException("Failed to generate value according to policy: " + stringPolicyType.getDescription() + ". " + context.getResult().getMessage());
            }
        }
        if (stringValue == null) {
            int length = DEFAULT_LENGTH;
            RandomString randomString = new RandomString(length);
            stringValue = randomString.nextString();
        }
    } else if (mode == GenerateExpressionEvaluatorModeType.UUID) {
        UUID randomUUID = UUID.randomUUID();
        stringValue = randomUUID.toString();
    } else {
        throw new ExpressionEvaluationException("Unknown mode for generate expression: " + mode);
    }
    Object value = ExpressionUtil.convertToOutputValue(stringValue, outputDefinition, protector);
    if (output instanceof PrismProperty) {
        PrismPropertyValue<Object> pValue = new PrismPropertyValue<Object>(value);
        ((PrismProperty<Object>) output).add(pValue);
    } else {
        throw new UnsupportedOperationException("Can only generate values of property, not " + output.getClass());
    }
    return ItemDelta.toDeltaSetTriple(output, null);
}
Also used : StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) UUID(java.util.UUID) RandomString(com.evolveum.midpoint.util.RandomString) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) RandomString(com.evolveum.midpoint.util.RandomString) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismObject(com.evolveum.midpoint.prism.PrismObject) UUID(java.util.UUID) GenerateExpressionEvaluatorModeType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorModeType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 35 with ObjectReferenceType

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

the class LazyXPathVariableResolver method resolveVariable.

@Override
public Object resolveVariable(QName name) {
    if (variables == null) {
        return null;
    }
    if (name != null && (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty())) {
        LOGGER.warn("Using variable without a namespace (" + name + "), possible namespace problem (e.g. missing namespace prefix declaration) in " + contextDescription);
    }
    // Note: null is a legal variable name here. It corresponds to the root node
    Object variableValue = variables.get(name);
    if (variableValue == null) {
        // TODO: warning ???
        return null;
    }
    QName type = null;
    // Attempt to resolve object reference
    if (objectResolver != null && variableValue instanceof ObjectReferenceType) {
        ObjectReferenceType ref = (ObjectReferenceType) variableValue;
        if (ref.getOid() == null) {
            SchemaException newEx = new SchemaException("Null OID in reference in variable " + name + " in " + contextDescription, name);
            throw new TunnelException(newEx);
        } else {
            type = ref.getType();
            try {
                // TODO task
                variableValue = objectResolver.resolve(ref, ObjectType.class, null, contextDescription, null, result);
            } catch (ObjectNotFoundException e) {
                ObjectNotFoundException newEx = new ObjectNotFoundException("Object not found during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, ref.getOid());
                // We have no other practical way how to handle the error
                throw new TunnelException(newEx);
            } catch (SchemaException e) {
                ExpressionSyntaxException newEx = new ExpressionSyntaxException("Schema error during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, name);
                throw new TunnelException(newEx);
            }
        }
    }
    try {
        return convertToXml(variableValue, name, prismContext, contextDescription);
    } catch (SchemaException e) {
        throw new TunnelException(e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)

Aggregations

ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)225 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)100 Test (org.testng.annotations.Test)79 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)78 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)77 Task (com.evolveum.midpoint.task.api.Task)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)42 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)41 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)37 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)36 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)33 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)32 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)31 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 QName (javax.xml.namespace.QName)29 ArrayList (java.util.ArrayList)28 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)25 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)22 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17