Search in sources :

Example 21 with ResourceObjectTypeDefinition

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

the class AbstractBasicDummyTest method test023RefinedSchema.

@Test
public void test023RefinedSchema() throws Exception {
    // GIVEN
    // WHEN
    ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(resourceBean);
    displayDumpable("Refined schema", refinedSchema);
    // Check whether it is reusing the existing schema and not parsing it
    // all over again
    // Not equals() but == ... we want to really know if exactly the same
    // object instance is returned
    assertTrue("Broken caching", refinedSchema == ResourceSchemaFactory.getCompleteSchema(resourceBean));
    ResourceObjectTypeDefinition accountDef = refinedSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("Account definition is missing", accountDef);
    assertNotNull("Null identifiers in account", accountDef.getPrimaryIdentifiers());
    assertFalse("Empty identifiers in account", accountDef.getPrimaryIdentifiers().isEmpty());
    assertNotNull("Null secondary identifiers in account", accountDef.getSecondaryIdentifiers());
    assertFalse("Empty secondary identifiers in account", accountDef.getSecondaryIdentifiers().isEmpty());
    assertNotNull("No naming attribute in account", accountDef.getNamingAttribute());
    assertFalse("No nativeObjectClass in account", StringUtils.isEmpty(accountDef.getObjectClassDefinition().getNativeObjectClass()));
    assertEquals("Unexpected kind in account definition", ShadowKindType.ACCOUNT, accountDef.getKind());
    assertTrue("Account definition in not default", accountDef.isDefaultForKind());
    assertEquals("Wrong intent in account definition", SchemaConstants.INTENT_DEFAULT, accountDef.getIntent());
    assertFalse("Account definition is deprecated", accountDef.isDeprecated());
    assertFalse("Account definition in auxiliary", accountDef.getObjectClassDefinition().isAuxiliary());
    ResourceAttributeDefinition<?> uidDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_UID);
    assertEquals(1, uidDef.getMaxOccurs());
    assertEquals(0, uidDef.getMinOccurs());
    assertFalse("No UID display name", StringUtils.isBlank(uidDef.getDisplayName()));
    assertFalse("UID has create", uidDef.canAdd());
    assertFalse("UID has update", uidDef.canModify());
    assertTrue("No UID read", uidDef.canRead());
    assertTrue("UID definition not in identifiers", accountDef.getPrimaryIdentifiers().contains(uidDef));
    ResourceAttributeDefinition<?> nameDef = accountDef.findAttributeDefinition(SchemaConstants.ICFS_NAME);
    assertEquals(1, nameDef.getMaxOccurs());
    assertEquals(1, nameDef.getMinOccurs());
    assertFalse("No NAME displayName", StringUtils.isBlank(nameDef.getDisplayName()));
    assertTrue("No NAME create", nameDef.canAdd());
    assertTrue("No NAME update", nameDef.canModify());
    assertTrue("No NAME read", nameDef.canRead());
    assertTrue("NAME definition not in identifiers", accountDef.getSecondaryIdentifiers().contains(nameDef));
    // MID-3144
    assertEquals("Wrong NAME displayOrder", (Integer) 110, nameDef.getDisplayOrder());
    assertEquals("Wrong NAME displayName", "Username", nameDef.getDisplayName());
    ResourceAttributeDefinition<?> fullnameDef = accountDef.findAttributeDefinition("fullname");
    assertNotNull("No definition for fullname", fullnameDef);
    assertEquals(1, fullnameDef.getMaxOccurs());
    assertEquals(1, fullnameDef.getMinOccurs());
    assertTrue("No fullname create", fullnameDef.canAdd());
    assertTrue("No fullname update", fullnameDef.canModify());
    assertTrue("No fullname read", fullnameDef.canRead());
    // MID-3144
    if (fullnameDef.getDisplayOrder() == null || fullnameDef.getDisplayOrder() < 100 || fullnameDef.getDisplayOrder() > 400) {
        AssertJUnit.fail("Wrong fullname displayOrder: " + fullnameDef.getDisplayOrder());
    }
    assertEquals("Wrong fullname displayName", null, fullnameDef.getDisplayName());
    assertNull("The _PASSSWORD_ attribute sneaked into schema", accountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "password")));
    rememberRefinedResourceSchema(refinedSchema);
    // FIXME re-enable this assert when there's a little time
    // assertEquals("Unexpected number of schema definitions",
    // getExpectedRefinedSchemaDefinitions(),
    // refinedSchema.getDefinitions().size());
    assertSteadyResource();
    dummyResource.assertConnections(1);
    assertDummyConnectorInstances(1);
}
Also used : ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) QName(javax.xml.namespace.QName) Test(org.testng.annotations.Test)

Example 22 with ResourceObjectTypeDefinition

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

the class TestRefinedSchema method assertRefinedObjectClass.

private void assertRefinedObjectClass(ResourceObjectDefinition objectClass, QName objectClassQName, ShadowKindType kind, String intent) {
    assertNotNull("No object class", objectClass);
    if (!(objectClass instanceof ResourceObjectTypeDefinition)) {
        AssertJUnit.fail("Expected refined object class definition, but it was " + objectClass + " (" + objectClass.getClass() + ")");
    }
    ResourceObjectTypeDefinition rOcDef = (ResourceObjectTypeDefinition) objectClass;
    assertEquals("Wrong object class QName in rOcDef " + rOcDef, objectClassQName, rOcDef.getTypeName());
    assertEquals("Wrong kind in rOcDef " + rOcDef, kind, rOcDef.getKind());
    assertEquals("Wrong kind in rOcDef " + rOcDef, intent, rOcDef.getIntent());
}
Also used : ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 23 with ResourceObjectTypeDefinition

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

the class EntitlementConverter method determineSearchHierarchyConstraints.

// This is perhaps not the best place for this method. It has nothing to do with entitlements.
// But given class dependencies this is a very convenient place. Let's leave it here for now.
SearchHierarchyConstraints determineSearchHierarchyConstraints(ProvisioningContext ctx, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException, SecurityViolationException {
    if (!ctx.isTypeBased()) {
        return null;
    }
    ResourceObjectTypeDefinition objectTypeDef = ctx.getObjectTypeDefinitionRequired();
    ResourceObjectReferenceType baseContextRef = objectTypeDef.getBaseContext();
    SearchHierarchyScope scope = objectTypeDef.getSearchHierarchyScope();
    ResourceObjectIdentification baseContextIdentification = determineBaseContextIdentification(baseContextRef, ctx, result);
    if (baseContextIdentification != null || scope != null) {
        return new SearchHierarchyConstraints(baseContextIdentification, scope);
    } else {
        return null;
    }
}
Also used : ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 24 with ResourceObjectTypeDefinition

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

the class MidpointFunctionsImpl method createAttributeQuery.

private <T> ObjectQuery createAttributeQuery(ResourceType resourceType, QName attributeName, T attributeValue) throws SchemaException {
    ResourceSchema rSchema = ResourceSchemaFactory.getCompleteSchema(resourceType);
    ResourceObjectTypeDefinition rAccountDef = rSchema.findDefaultOrAnyObjectTypeDefinition(ShadowKindType.ACCOUNT);
    ResourceAttributeDefinition<?> attrDef = rAccountDef.findAttributeDefinition(attributeName);
    if (attrDef == null) {
        throw new SchemaException("No attribute '" + attributeName + "' in " + rAccountDef);
    }
    return prismContext.queryFor(ShadowType.class).itemWithDef(attrDef, ShadowType.F_ATTRIBUTES, attrDef.getItemName()).eq(attributeValue).and().item(ShadowType.F_OBJECT_CLASS).eq(rAccountDef.getObjectClassDefinition().getTypeName()).and().item(ShadowType.F_RESOURCE_REF).ref(resourceType.getOid()).build();
}
Also used : ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 25 with ResourceObjectTypeDefinition

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

the class ShadowIntegrityCheckItemProcessor method checkShadow.

private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
    ShadowCheckConfiguration cfg = activityRun.getConfiguration();
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = shadowType.getResourceRef();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
    }
    getStats().incrementShadows();
    if (resourceRef == null) {
        checkResult.recordError(ShadowStatistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
        fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    String resourceOid = resourceRef.getOid();
    if (resourceOid == null) {
        checkResult.recordError(ShadowStatistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
        fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    PrismObject<ResourceType> resource = getCachedResource(resourceOid);
    if (resource == null) {
        getStats().incrementResources();
        try {
            resource = getProvisioningService().getObject(ResourceType.class, resourceOid, null, workerTask, result);
        } catch (ObjectNotFoundException e) {
            checkResult.recordError(ShadowStatistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
            fixNoResourceIfRequested(checkResult, ShadowStatistics.NO_RESOURCE);
            applyFixes(checkResult, shadow, workerTask, result);
            return;
        } catch (SchemaException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
            return;
        } catch (CommonException | RuntimeException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
            return;
        }
        cacheResource(resource);
    }
    checkResult.setResource(resource);
    ShadowKindType kind = shadowType.getKind();
    if (kind == null) {
        // TODO or simply assume account?
        checkResult.recordError(ShadowStatistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
        return;
    }
    if (cfg.checkExtraData) {
        checkOrFixShadowActivationConsistency(checkResult, shadow);
    }
    PrismObject<ShadowType> fetchedShadow = null;
    if (cfg.checkFetch) {
        fetchedShadow = fetchShadow(checkResult, shadow, workerTask, result);
        if (fetchedShadow != null) {
            shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
        }
    }
    if (cfg.checkOwners) {
        List<PrismObject<FocusType>> owners = activityRun.searchOwners(shadow, result);
        if (owners != null) {
            shadow.setUserData(KEY_OWNERS, owners);
            if (owners.size() > 1) {
                checkResult.recordError(ShadowStatistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
            }
        }
        if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
            checkResult.recordError(ShadowStatistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
        }
        if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
            checkResult.recordError(ShadowStatistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
        }
    }
    String intent = shadowType.getIntent();
    if (cfg.checkIntents && (intent == null || intent.isEmpty())) {
        checkResult.recordWarning(ShadowStatistics.NO_INTENT_SPECIFIED, "None or empty intent");
    }
    if (cfg.fixIntents && (intent == null || intent.isEmpty())) {
        doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
    }
    QName objectClassName = shadowType.getObjectClass();
    if (objectClassName == null) {
        checkResult.recordError(ShadowStatistics.NO_OBJECT_CLASS_SPECIFIED, new SchemaException("No object class specified"));
        return;
    }
    ContextMapKey key = new ContextMapKey(resourceOid, objectClassName);
    ObjectTypeContext context = activityRun.getObjectTypeContext(key);
    if (context == null) {
        context = new ObjectTypeContext();
        context.setResource(resource);
        ResourceSchema refinedSchema;
        try {
            refinedSchema = ResourceSchemaFactory.getCompleteSchema(context.getResource(), LayerType.MODEL);
        } catch (SchemaException e) {
            checkResult.recordError(ShadowStatistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
            return;
        }
        if (refinedSchema == null) {
            checkResult.recordError(ShadowStatistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
            return;
        }
        ResourceObjectDefinition objectDefinition = refinedSchema.findObjectDefinition(kind, ShadowUtil.getIntent(shadow));
        if (objectDefinition instanceof ResourceObjectTypeDefinition) {
            context.setObjectTypeDefinition((ResourceObjectTypeDefinition) objectDefinition);
        } else {
            // TODO or warning only?
            checkResult.recordError(ShadowStatistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
            return;
        }
        activityRun.putObjectTypeContext(key, context);
    }
    try {
        getProvisioningService().applyDefinition(shadow, workerTask, result);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
        return;
    }
    Set<ResourceAttributeDefinition<?>> identifiers = new HashSet<>();
    Collection<? extends ResourceAttributeDefinition<?>> primaryIdentifiers = context.getObjectTypeDefinition().getPrimaryIdentifiers();
    identifiers.addAll(primaryIdentifiers);
    identifiers.addAll(context.getObjectTypeDefinition().getSecondaryIdentifiers());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // might happen on unfinished shadows?
        checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("No attributes container"));
        return;
    }
    for (ResourceAttributeDefinition<?> identifier : identifiers) {
        PrismProperty<String> property = attributesContainer.getValue().findProperty(identifier.getItemName());
        if (property == null || property.size() == 0) {
            checkResult.recordWarning(ShadowStatistics.OTHER_FAILURE, "No value for identifier " + identifier.getItemName());
            continue;
        }
        if (property.size() > 1) {
            // we don't expect multi-valued identifiers
            checkResult.recordError(ShadowStatistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getItemName() + " with values " + property.getValues()));
            continue;
        }
        // size == 1
        String value = property.getValue().getValue();
        if (value == null) {
            checkResult.recordWarning(ShadowStatistics.OTHER_FAILURE, "Null value for identifier " + identifier.getItemName());
            continue;
        }
        if (cfg.checkUniqueness) {
            if (!cfg.checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
                addIdentifierValue(context, identifier.getItemName(), value, shadow);
            }
        }
        if (cfg.checkNormalization) {
            doCheckNormalization(checkResult, identifier, value);
        }
    }
    applyFixes(checkResult, shadow, workerTask, result);
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) QName(javax.xml.namespace.QName) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)

Aggregations

ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)32 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)14 QName (javax.xml.namespace.QName)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)5 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)3 List (java.util.List)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)2 Definition (com.evolveum.midpoint.prism.Definition)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 NotNull (org.jetbrains.annotations.NotNull)2 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)1