Search in sources :

Example 21 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowCreator method createRepositoryShadow.

/**
 * Create a copy of a resource object (or another shadow) that is suitable for repository storage.
 */
@NotNull
PrismObject<ShadowType> createRepositoryShadow(ProvisioningContext ctx, PrismObject<ShadowType> resourceObjectOrShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException, EncryptionException {
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceObjectOrShadow);
    PrismObject<ShadowType> repoShadow = resourceObjectOrShadow.clone();
    ShadowType repoShadowType = repoShadow.asObjectable();
    ResourceAttributeContainer repoAttributesContainer = ShadowUtil.getAttributesContainer(repoShadow);
    repoShadowType.setPrimaryIdentifierValue(helper.determinePrimaryIdentifierValue(ctx, resourceObjectOrShadow));
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    if (cachingStrategy == CachingStategyType.NONE) {
        // Clean all repoShadow attributes and add only those that should be there
        repoAttributesContainer.clear();
        Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers();
        for (PrismProperty<?> p : primaryIdentifiers) {
            repoAttributesContainer.add(p.clone());
        }
        Collection<ResourceAttribute<?>> secondaryIdentifiers = attributesContainer.getSecondaryIdentifiers();
        for (PrismProperty<?> p : secondaryIdentifiers) {
            repoAttributesContainer.add(p.clone());
        }
        // Also add all the attributes that act as association identifiers.
        // We will need them when the shadow is deleted (to remove the shadow from entitlements).
        ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
        for (ResourceAssociationDefinition associationDef : objectDefinition.getAssociationDefinitions()) {
            if (associationDef.getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
                QName valueAttributeName = associationDef.getDefinitionBean().getValueAttribute();
                if (repoAttributesContainer.findAttribute(valueAttributeName) == null) {
                    ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName);
                    if (valueAttribute != null) {
                        repoAttributesContainer.add(valueAttribute.clone());
                    }
                }
            }
        }
        repoShadowType.setCachingMetadata(null);
        ProvisioningUtil.cleanupShadowActivation(repoShadowType);
    } else if (cachingStrategy == CachingStategyType.PASSIVE) {
        // Do not need to clear anything. Just store all attributes and add metadata.
        CachingMetadataType cachingMetadata = new CachingMetadataType();
        cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
        repoShadowType.setCachingMetadata(cachingMetadata);
    } else {
        throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
    }
    helper.setKindIfNecessary(repoShadowType, ctx);
    // setIntentIfNecessary(repoShadowType, objectClassDefinition);
    // Store only password meta-data in repo - unless there is explicit caching
    CredentialsType creds = repoShadowType.getCredentials();
    if (creds != null) {
        PasswordType passwordType = creds.getPassword();
        if (passwordType != null) {
            preparePasswordForStorage(passwordType, ctx);
            ObjectReferenceType owner = ctx.getTask() != null ? ctx.getTask().getOwnerRef() : null;
            ProvisioningUtil.addPasswordMetadata(passwordType, clock.currentTimeXMLGregorianCalendar(), owner);
        }
    // TODO: other credential types - later
    }
    // now
    if (repoShadowType.getResourceRef() == null) {
        repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource(), prismContext));
    }
    if (repoShadowType.getName() == null) {
        repoShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(resourceObjectOrShadow)));
    }
    if (repoShadowType.getObjectClass() == null) {
        repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
    }
    if (repoShadowType.isProtectedObject() != null) {
        repoShadowType.setProtectedObject(null);
    }
    helper.normalizeAttributes(repoShadow, ctx.getObjectDefinitionRequired());
    return repoShadow;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowedObjectConstruction method getAssociationDefinition.

@NotNull
private ResourceAssociationDefinition getAssociationDefinition(QName associationName) throws SchemaException {
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    ResourceAssociationDefinition rEntitlementAssociationDef = objectDefinition.findAssociationDefinition(associationName);
    if (rEntitlementAssociationDef == null) {
        LOGGER.trace("Entitlement association with name {} couldn't be found in {} {}\nresource shadow:\n{}\nrepo shadow:\n{}", associationName, objectDefinition, ctx.getDesc(), resourceObject.debugDumpLazily(1), repoShadow.debugDumpLazily(1));
        LOGGER.trace("Full [refined] definition: {}", objectDefinition.debugDumpLazily());
        throw new SchemaException("Entitlement association with name " + associationName + " couldn't be found in " + ctx);
    }
    return rEntitlementAssociationDef;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class QueryHelper method applyMatchingRules.

/**
 * Visit the query and normalize values (or set matching rules) as needed
 */
@Contract("null, _ -> null; !null, _ -> !null")
ObjectQuery applyMatchingRules(ObjectQuery originalQuery, ResourceObjectDefinition objectDef) {
    if (originalQuery == null) {
        return null;
    }
    ObjectQuery processedQuery = originalQuery.clone();
    ObjectFilter filter = processedQuery.getFilter();
    Visitor visitor = f -> {
        try {
            if (f instanceof EqualFilter) {
                applyMatchingRuleToEqFilter((EqualFilter<?>) f, objectDef);
            }
        } catch (SchemaException e) {
            throw new SystemException(e);
        }
    };
    filter.accept(visitor);
    return processedQuery;
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Trace(com.evolveum.midpoint.util.logging.Trace) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ArrayList(java.util.ArrayList) List(java.util.List) Contract(org.jetbrains.annotations.Contract) Component(org.springframework.stereotype.Component) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) Visitor(com.evolveum.midpoint.prism.query.Visitor) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Visitor(com.evolveum.midpoint.prism.query.Visitor) SystemException(com.evolveum.midpoint.util.exception.SystemException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Contract(org.jetbrains.annotations.Contract)

Example 24 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class AssignmentEditorDto method prepareAssignmentAttributes.

private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignment, PageBase pageBase) {
    List<ACAttributeDto> acAtrList = new ArrayList<>();
    if (assignment == null || assignment.getConstruction() == null || assignment.getConstruction().getAttribute() == null || assignment.getConstruction() == null) {
        return acAtrList;
    }
    OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
    ConstructionType construction = assignment.getConstruction();
    ObjectReferenceType resourceRef = construction.getResourceRef();
    PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
    if (resource == null) {
        resource = getReference(construction.getResourceRef(), result, pageBase);
    }
    try {
        PrismContext prismContext = pageBase.getPrismContext();
        ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource, LayerType.PRESENTATION);
        ResourceObjectDefinition objectClassDefinition = refinedSchema.findObjectDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
        if (objectClassDefinition == null) {
            return attributes;
        }
        PrismContainerDefinition<?> definition = objectClassDefinition.toResourceAttributeContainerDefinition();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
        }
        Collection<? extends ItemDefinition<?>> definitions = definition.getDefinitions();
        for (ResourceAttributeDefinitionType attribute : assignment.getConstruction().getAttribute()) {
            for (ItemDefinition attrDef : definitions) {
                if (attrDef instanceof PrismPropertyDefinition) {
                    PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) attrDef;
                    if (propertyDef.isOperational() || propertyDef.isIgnored()) {
                        continue;
                    }
                    if (ItemPathTypeUtil.asSingleNameOrFail(attribute.getRef()).equals(propertyDef.getItemName())) {
                        acAtrList.add(ACAttributeDto.createACAttributeDto(propertyDef, attribute, prismContext));
                        break;
                    }
                }
            }
        }
        result.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
        result.recordFatalError(pageBase.createStringResource("AssignmentEditorDto.message.prepareAssignmentAttributes.fatalError").getString(), ex);
    } finally {
        result.recomputeStatus();
    }
    return acAtrList;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)

Example 25 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class AssignmentEditorPanel method loadAttributes.

private List<ACAttributeDto> loadAttributes() {
    AssignmentEditorDto dto = getModel().getObject();
    OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
    List<ACAttributeDto> attributes = new ArrayList<>();
    try {
        ConstructionType construction = WebComponentUtil.getContainerValue(dto.getOldValue(), AssignmentType.F_CONSTRUCTION, ConstructionType.class);
        if (construction == null) {
            return attributes;
        }
        PrismObject<ResourceType> resource = getReference(construction.getResourceRef(), result);
        PrismContext prismContext = getPageBase().getPrismContext();
        ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resource, LayerType.PRESENTATION);
        ResourceObjectDefinition objectClassDefinition = refinedSchema.findObjectDefinition(ShadowKindType.ACCOUNT, construction.getIntent());
        if (objectClassDefinition == null) {
            return attributes;
        }
        PrismContainerDefinition definition = objectClassDefinition.toResourceAttributeContainerDefinition();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Refined definition for {}\n{}", construction, definition.debugDump());
        }
        Collection<ItemDefinition<?>> definitions = definition.getDefinitions();
        for (ItemDefinition<?> attrDef : definitions) {
            if (!(attrDef instanceof PrismPropertyDefinition)) {
                // log skipping or something...
                continue;
            }
            PrismPropertyDefinition<?> propertyDef = (PrismPropertyDefinition<?>) attrDef;
            if (propertyDef.isOperational() || propertyDef.isIgnored()) {
                continue;
            }
            attributes.add(ACAttributeDto.createACAttributeDto(propertyDef, findOrCreateValueConstruction(propertyDef), prismContext));
        }
        result.recordSuccess();
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Exception occurred during assignment attribute loading", ex);
        result.recordFatalError(createStringResource("AssignmentEditorPanel.message.loadAttributes.fatalError").getString(), ex);
    } finally {
        result.recomputeStatus();
    }
    attributes.sort((a1, a2) -> String.CASE_INSENSITIVE_ORDER.compare(a1.getName(), a2.getName()));
    if (dto.getAttributes() != null && !dto.getAttributes().isEmpty()) {
        for (ACAttributeDto assignmentAttribute : dto.getAttributes()) {
            for (ACAttributeDto attributeDto : attributes) {
                if (attributeDto.getName().equals(assignmentAttribute.getName())) {
                    attributes.set(attributes.indexOf(attributeDto), assignmentAttribute);
                    continue;
                }
            }
        }
    }
    dto.setAttributes(attributes);
    getPageBase().showResult(result, false);
    return dto.getAttributes();
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2