Search in sources :

Example 21 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ShadowManager method createSearchShadowQuery.

private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, Collection<ResourceAttribute<?>> identifiers, boolean primaryIdentifiersOnly, PrismContext prismContext, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    S_AtomicFilterEntry q = QueryBuilder.queryFor(ShadowType.class, prismContext);
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    for (PrismProperty<?> identifier : identifiers) {
        RefinedAttributeDefinition rAttrDef;
        PrismPropertyValue<?> identifierValue = identifier.getValue();
        if (objectClassDefinition == null) {
            // If there is no specific object class definition then the identifier definition 
            // must be the same in all object classes and that means that we can use
            // definition from any of them.
            RefinedObjectClassDefinition anyDefinition = ctx.getRefinedSchema().getRefinedDefinitions().iterator().next();
            rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName());
            if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
        } else {
            if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
            rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
        }
        String normalizedIdentifierValue = (String) getNormalizedAttributeValue(identifierValue, rAttrDef);
        PrismPropertyDefinition<String> def = (PrismPropertyDefinition<String>) identifier.getDefinition();
        q = q.itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getName()).eq(normalizedIdentifierValue).and();
    }
    if (identifiers.size() < 1) {
        throw new SchemaException("Identifier not specified. Cannot create search query by identifier.");
    }
    if (objectClassDefinition != null) {
        q = q.item(ShadowType.F_OBJECT_CLASS).eq(objectClassDefinition.getTypeName()).and();
    }
    return q.item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 22 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ShadowManager method compareAttribute.

public <T> boolean compareAttribute(RefinedObjectClassDefinition refinedObjectClassDefinition, ResourceAttribute<T> attributeA, T... valuesB) throws SchemaException {
    RefinedAttributeDefinition refinedAttributeDefinition = refinedObjectClassDefinition.findAttributeDefinition(attributeA.getElementName());
    Collection<T> valuesA = getNormalizedAttributeValues(attributeA, refinedAttributeDefinition);
    return MiscUtil.unorderedCollectionEquals(valuesA, Arrays.asList(valuesB));
}
Also used : RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)

Example 23 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ShadowManager method normalizeAttributes.

public void normalizeAttributes(PrismObject<ShadowType> shadow, RefinedObjectClassDefinition objectClassDefinition) throws SchemaException {
    for (ResourceAttribute<?> attribute : ShadowUtil.getAttributes(shadow)) {
        RefinedAttributeDefinition rAttrDef = objectClassDefinition.findAttributeDefinition(attribute.getElementName());
        normalizeAttribute(attribute, rAttrDef);
    }
}
Also used : RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)

Example 24 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class ProjectionValuesProcessor method willResetIterationCounter.

private boolean willResetIterationCounter(LensProjectionContext projectionContext) throws SchemaException {
    ObjectDelta<ShadowType> accountDelta = projectionContext.getDelta();
    if (accountDelta == null) {
        return false;
    }
    RefinedObjectClassDefinition oOcDef = projectionContext.getCompositeObjectClassDefinition();
    for (RefinedAttributeDefinition identifierDef : oOcDef.getPrimaryIdentifiers()) {
        ItemPath identifierPath = new ItemPath(ShadowType.F_ATTRIBUTES, identifierDef.getName());
        if (accountDelta.findPropertyDelta(identifierPath) != null) {
            return true;
        }
    }
    for (RefinedAttributeDefinition identifierDef : oOcDef.getSecondaryIdentifiers()) {
        ItemPath identifierPath = new ItemPath(ShadowType.F_ATTRIBUTES, identifierDef.getName());
        if (accountDelta.findPropertyDelta(identifierPath) != null) {
            return true;
        }
    }
    return false;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with RefinedAttributeDefinition

use of com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition in project midpoint by Evolveum.

the class AccessChecker method checkModify.

public void checkModify(ResourceType resource, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> modifications, RefinedObjectClassDefinition objectClassDefinition, OperationResult parentResult) throws SecurityViolationException, SchemaException {
    OperationResult result = parentResult.createMinorSubresult(OPERATION_NAME);
    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();
        RefinedAttributeDefinition attrDef = objectClassDefinition.findAttributeDefinition(attrName);
        if (attrDef == null) {
            throw new SchemaException("Cannot find definition of attribute " + attrName + " in " + objectClassDefinition);
        }
        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);
        }
    }
    result.recordSuccess();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) QName(javax.xml.namespace.QName) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) PropertyAccessType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PropertyLimitations(com.evolveum.midpoint.common.refinery.PropertyLimitations)

Aggregations

RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)28 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)12 QName (javax.xml.namespace.QName)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 PropertyLimitations (com.evolveum.midpoint.common.refinery.PropertyLimitations)4 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)4 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 PropertyAccessType (com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyAccessType)3 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2