Search in sources :

Example 31 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method createConnIdOptions.

private OperationOptions createConnIdOptions(ConnectorOperationOptions options, Collection<Operation> changes) throws SchemaException {
    OperationOptionsBuilder connIdOptionsBuilder = new OperationOptionsBuilder();
    if (options != null) {
        ResourceObjectIdentification runAsIdentification = options.getRunAsIdentification();
        if (runAsIdentification != null) {
            connIdOptionsBuilder.setRunAsUser(getNameValue(runAsIdentification));
            // This is quite a black magic. But we do not have a better way now.
            for (Operation change : changes) {
                if (change instanceof PropertyModificationOperation) {
                    PropertyDelta propertyDelta = ((PropertyModificationOperation) change).getPropertyDelta();
                    if (!propertyDelta.getPath().equivalent(SchemaConstants.PATH_PASSWORD_VALUE)) {
                        continue;
                    }
                    Collection<PrismPropertyValue<ProtectedStringType>> oldValues = propertyDelta.getEstimatedOldValues();
                    if (oldValues == null || oldValues.isEmpty()) {
                        continue;
                    }
                    ProtectedStringType oldPassword = oldValues.iterator().next().getValue();
                    if (oldPassword != null) {
                        GuardedString oldPasswordGs = ConnIdUtil.toGuardedString(oldPassword, "runAs password", protector);
                        connIdOptionsBuilder.setRunWithPassword(oldPasswordGs);
                    }
                }
            }
        }
    }
    return connIdOptionsBuilder.build();
}
Also used : PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ConnectorTestOperation(com.evolveum.midpoint.schema.constants.ConnectorTestOperation) ConnIdOperation(com.evolveum.midpoint.schema.reporting.ConnIdOperation) ProvisioningOperation(com.evolveum.midpoint.schema.statistics.ProvisioningOperation) GuardedString(org.identityconnectors.common.security.GuardedString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 32 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class AddOverwriteTest method test091GetVersion.

@Test
public void test091GetVersion() throws Exception {
    OperationResult result = new OperationResult("get version");
    String version = repositoryService.getVersion(OrgType.class, ORG_OID, result);
    AssertJUnit.assertEquals("0", version);
    PrismObjectDefinition<OrgType> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(OrgType.class);
    Collection<PropertyDelta<String>> deltas = new ArrayList<>();
    deltas.add(prismContext.deltaFactory().property().createAddDelta(def, OrgType.F_SUBTYPE, "asdf"));
    repositoryService.modifyObject(OrgType.class, ORG_OID, deltas, result);
    version = repositoryService.getVersion(OrgType.class, ORG_OID, result);
    AssertJUnit.assertEquals("1", version);
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
}
Also used : ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) Test(org.testng.annotations.Test)

Example 33 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class EntitlementConverter method collectEntitlementToAttrDelta.

/**
 *  Collects entitlement changes from the shadow to entitlement section into attribute operations.
 *  Collects a single value.
 *  NOTE: only collects  SUBJECT_TO_ENTITLEMENT entitlement direction.
 */
private <T> void collectEntitlementToAttrDelta(OperationMap operationMap, PrismContainerValue<ShadowAssociationType> associationValue, ModificationType modificationType, ProvisioningContext subjectCtx) throws SchemaException {
    ResourceObjectDefinition subjectDef = subjectCtx.getObjectDefinitionRequired();
    ShadowAssociationType associationBean = associationValue.asContainerable();
    QName associationName = associationBean.getName();
    schemaCheck(associationName != null, "No name in entitlement association %s", associationValue);
    ResourceAssociationDefinition associationDef = subjectDef.findAssociationDefinitionRequired(associationName, () -> " in " + subjectCtx);
    ResourceObjectAssociationDirectionType direction = associationDef.getDirection();
    if (direction != ResourceObjectAssociationDirectionType.SUBJECT_TO_OBJECT) {
        // therefore will be processed later.
        return;
    }
    QName assocAttrName = associationDef.getDefinitionBean().getAssociationAttribute();
    QName valueAttrName = associationDef.getDefinitionBean().getValueAttribute();
    schemaCheck(assocAttrName != null, "No association attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
    schemaCheck(valueAttrName != null, "No value attribute defined in entitlement association '%s' in %s", associationName, subjectCtx);
    ResourceAttributeDefinition<?> assocAttrDef = subjectDef.findAttributeDefinition(assocAttrName);
    if (assocAttrDef == null) {
        throw new SchemaException("Association attribute '" + assocAttrName + "'defined in entitlement association '" + associationName + "' was not found in schema for " + subjectCtx);
    }
    // noinspection unchecked
    PropertyModificationOperation<T> attributeOperation = (PropertyModificationOperation<T>) operationMap.get(assocAttrName);
    if (attributeOperation == null) {
        // noinspection unchecked
        PropertyDelta<T> emptyDelta = (PropertyDelta<T>) assocAttrDef.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, assocAttrName));
        attributeOperation = new PropertyModificationOperation<>(emptyDelta);
        attributeOperation.setMatchingRuleQName(associationDef.getMatchingRule());
        operationMap.put(assocAttrName, attributeOperation);
    }
    // MID-7144: Identifier container may not be resource attribute container, if its origin is serialized pending delta
    PrismContainer<?> identifiersContainer = associationValue.findContainer(ShadowAssociationType.F_IDENTIFIERS);
    PrismProperty<T> valueAttr = identifiersContainer.findProperty(ItemName.fromQName(valueAttrName));
    if (valueAttr == null) {
        throw new SchemaException("No value attribute " + valueAttrName + " present in entitlement association '" + associationName + "' in shadow for " + subjectCtx);
    }
    if (modificationType == ModificationType.ADD) {
        attributeOperation.getPropertyDelta().addValuesToAdd(valueAttr.getClonedValues());
    } else if (modificationType == ModificationType.DELETE) {
        attributeOperation.getPropertyDelta().addValuesToDelete(valueAttr.getClonedValues());
    } else if (modificationType == ModificationType.REPLACE) {
        // TODO: check if already exists
        attributeOperation.getPropertyDelta().setValuesToReplace(valueAttr.getClonedValues());
    }
}
Also used : QName(javax.xml.namespace.QName) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 34 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class SqaleRepositoryService method logTraceModifications.

private void logTraceModifications(@NotNull Collection<? extends ItemDelta<?, ?>> modifications) {
    if (logger.isTraceEnabled()) {
        for (ItemDelta<?, ?> modification : modifications) {
            if (modification instanceof PropertyDelta<?>) {
                PropertyDelta<?> propDelta = (PropertyDelta<?>) modification;
                if (propDelta.getPath().equivalent(ObjectType.F_NAME)) {
                    Collection<PrismPropertyValue<PolyString>> values = propDelta.getValues(PolyString.class);
                    for (PrismPropertyValue<PolyString> pval : values) {
                        PolyString value = pval.getValue();
                        logger.trace("NAME delta: {} - {}", value.getOrig(), value.getNorm());
                    }
                }
            }
        }
    }
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 35 with PropertyDelta

use of com.evolveum.midpoint.prism.delta.PropertyDelta in project midpoint by Evolveum.

the class AccessChecker method checkModify.

void checkModify(ProvisioningContext ctx, Collection<? extends ItemDelta<?, ?>> modifications, OperationResult parentResult) throws SecurityViolationException, SchemaException {
    ResourceObjectDefinition resourceObjectDefinition = ctx.getObjectDefinitionRequired();
    OperationResult result = parentResult.createMinorSubresult(OP_ACCESS_CHECK);
    try {
        for (ItemDelta<?, ?> modification : modifications) {
            if (!(modification instanceof PropertyDelta<?>)) {
                continue;
            }
            PropertyDelta<?> attrDelta = (PropertyDelta<?>) modification;
            if (!SchemaConstants.PATH_ATTRIBUTES.equivalent(attrDelta.getParentPath())) {
                // Not an attribute
                continue;
            }
            QName attrName = attrDelta.getElementName();
            LOGGER.trace("Checking attribute {} definition present in {}", attrName, resourceObjectDefinition);
            ResourceAttributeDefinition<?> attrDef = resourceObjectDefinition.findAttributeDefinitionRequired(attrName);
            PropertyLimitations limitations = attrDef.getLimitations(LayerType.MODEL);
            if (limitations == null) {
                continue;
            }
            // We cannot throw error here. At least not now. Provisioning will internally use ignored attributes
            // e.g. for simulated capabilities. This is not a problem for normal operations, but it is a problem
            // for delayed operations (e.g. consistency) that are passing through this code again.
            // TODO: we need to figure a way how to avoid this loop
            // if (limitations.isIgnore()) {
            // String message = "Attempt to create shadow with ignored attribute "+attribute.getName();
            // LOGGER.error(message);
            // throw new SchemaException(message);
            // }
            PropertyAccessType access = limitations.getAccess();
            if (access == null) {
                continue;
            }
            if (access.isModify() == null || !access.isModify()) {
                String message = "Attempt to modify non-updateable attribute " + attrName;
                LOGGER.error(message);
                result.recordFatalError(message);
                throw new SecurityViolationException(message);
            }
        }
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.close();
    }
}
Also used : SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) QName(javax.xml.namespace.QName) PropertyAccessType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Aggregations

PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)90 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)39 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)33 QName (javax.xml.namespace.QName)28 ArrayList (java.util.ArrayList)23 Test (org.testng.annotations.Test)20 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)19 Task (com.evolveum.midpoint.task.api.Task)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 Collection (java.util.Collection)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6