Search in sources :

Example 16 with ResourceAttributeContainer

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

the class ConsistencyTest method test142ModifyObjectNotFoundAssignedAccount.

/**
	 * Modify account not found => reaction: Re-create account, apply changes.
	 */
@Test
public void test142ModifyObjectNotFoundAssignedAccount() throws Exception {
    final String TEST_NAME = "test142ModifyObjectNotFoundAssignedAccount";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult parentResult = new OperationResult(TEST_NAME);
    repoAddShadowFromFile(ACCOUNT_GUYBRUSH_MODIFY_DELETE_FILE, parentResult);
    repoAddObjectFromFile(USER_GUYBRUSH_NOT_FOUND_FILENAME, parentResult);
    assertUserOneAccountRef(USER_GUYBRUSH_NOT_FOUND_OID);
    Task task = taskManager.createTaskInstance();
    //WHEN
    TestUtil.displayWhen(TEST_NAME);
    requestToExecuteChanges(REQUEST_ACCOUNT_MODIFY_NOT_FOUND_DELETE_ACCOUNT, ACCOUNT_GUYBRUSH_MODIFY_DELETE_OID, ShadowType.class, task, null, parentResult);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    String accountOid = assertUserOneAccountRef(USER_GUYBRUSH_NOT_FOUND_OID);
    PrismObject<ShadowType> modifiedAccount = provisioningService.getObject(ShadowType.class, accountOid, null, task, parentResult);
    assertNotNull(modifiedAccount);
    display("Modified shadow", modifiedAccount);
    assertShadowName(modifiedAccount.asObjectable(), "uid=guybrush123,ou=people,dc=example,dc=com");
    //		PrismAsserts.assertEqualsPolyString("Wrong shadow name", "uid=guybrush123,ou=people,dc=example,dc=com", modifiedAccount.asObjectable().getName());
    ResourceAttributeContainer attributeContainer = ShadowUtil.getAttributesContainer(modifiedAccount);
    assertAttribute(modifiedAccount.asObjectable(), new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "roomNumber"), "cabin");
    assertNotNull(attributeContainer.findProperty(new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "businessCategory")));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 17 with ResourceAttributeContainer

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

the class ConnIdConvertor method convertToResourceObject.

/**
	 * Converts ICF ConnectorObject to the midPoint ResourceObject.
	 * <p/>
	 * All the attributes are mapped using the same way as they are mapped in
	 * the schema (which is actually no mapping at all now).
	 * <p/>
	 * If an optional ResourceObjectDefinition was provided, the resulting
	 * ResourceObject is schema-aware (getDefinition() method works). If no
	 * ResourceObjectDefinition was provided, the object is schema-less. TODO:
	 * this still needs to be implemented.
	 * 
	 * @param co
	 *            ICF ConnectorObject to convert
	 * @param def
	 *            ResourceObjectDefinition (from the schema) or null
	 * @param full
	 *            if true it describes if the returned resource object should
	 *            contain all of the attributes defined in the schema, if false
	 *            the returned resource object will contain only attributed with
	 *            the non-null values.
	 * @return new mapped ResourceObject instance.
	 * @throws SchemaException
	 */
<T extends ShadowType> PrismObject<T> convertToResourceObject(ConnectorObject co, PrismObjectDefinition<T> objectDefinition, boolean full, boolean caseIgnoreAttributeNames, boolean legacySchema) throws SchemaException {
    PrismObject<T> shadowPrism = null;
    if (objectDefinition != null) {
        shadowPrism = objectDefinition.instantiate();
    } else {
        throw new SchemaException("No definition");
    }
    // LOGGER.trace("Instantiated prism object {} from connector object.",
    // shadowPrism.debugDump());
    T shadow = shadowPrism.asObjectable();
    ResourceAttributeContainer attributesContainer = (ResourceAttributeContainer) shadowPrism.findOrCreateContainer(ShadowType.F_ATTRIBUTES);
    ResourceAttributeContainerDefinition attributesContainerDefinition = attributesContainer.getDefinition();
    shadow.setObjectClass(attributesContainerDefinition.getTypeName());
    List<ObjectClassComplexTypeDefinition> auxiliaryObjectClassDefinitions = new ArrayList<>();
    for (Attribute icfAttr : co.getAttributes()) {
        if (icfAttr.is(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME)) {
            List<QName> auxiliaryObjectClasses = shadow.getAuxiliaryObjectClass();
            for (Object auxiliaryIcfObjectClass : icfAttr.getValue()) {
                QName auxiliaryObjectClassQname = icfNameMapper.objectClassToQname(new ObjectClass((String) auxiliaryIcfObjectClass), resourceSchemaNamespace, legacySchema);
                auxiliaryObjectClasses.add(auxiliaryObjectClassQname);
                ObjectClassComplexTypeDefinition auxiliaryObjectClassDefinition = icfNameMapper.getResourceSchema().findObjectClassDefinition(auxiliaryObjectClassQname);
                if (auxiliaryObjectClassDefinition == null) {
                    throw new SchemaException("Resource object " + co + " refers to auxiliary object class " + auxiliaryObjectClassQname + " which is not in the schema");
                }
                auxiliaryObjectClassDefinitions.add(auxiliaryObjectClassDefinition);
            }
            break;
        }
    }
    for (Attribute icfAttr : co.getAttributes()) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Reading ICF attribute {}: {}", icfAttr.getName(), icfAttr.getValue());
        }
        if (icfAttr.getName().equals(Uid.NAME)) {
            // UID is handled specially (see above)
            continue;
        }
        if (icfAttr.is(PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME)) {
            // Already processed
            continue;
        }
        if (icfAttr.getName().equals(OperationalAttributes.PASSWORD_NAME)) {
            // password has to go to the credentials section
            ProtectedStringType password = getSingleValue(icfAttr, ProtectedStringType.class);
            if (password == null) {
                // equals() instead of == is needed. The AttributeValueCompleteness enum may be loaded by different classloader
                if (!AttributeValueCompleteness.INCOMPLETE.equals(icfAttr.getAttributeValueCompleteness())) {
                    continue;
                }
                // There is no password value in the ConnId attribute. But it was indicated that
                // that attribute is incomplete. Therefore we can assume that there in fact is a value.
                // We just do not know it.
                ShadowUtil.setPasswordIncomplete(shadow);
                LOGGER.trace("Converted password: (incomplete)");
            } else {
                ShadowUtil.setPassword(shadow, password);
                LOGGER.trace("Converted password: {}", password);
            }
            continue;
        }
        if (icfAttr.getName().equals(OperationalAttributes.ENABLE_NAME)) {
            Boolean enabled = getSingleValue(icfAttr, Boolean.class);
            if (enabled == null) {
                continue;
            }
            ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
            ActivationStatusType activationStatusType;
            if (enabled) {
                activationStatusType = ActivationStatusType.ENABLED;
            } else {
                activationStatusType = ActivationStatusType.DISABLED;
            }
            activationType.setAdministrativeStatus(activationStatusType);
            activationType.setEffectiveStatus(activationStatusType);
            LOGGER.trace("Converted activation administrativeStatus: {}", activationStatusType);
            continue;
        }
        if (icfAttr.getName().equals(OperationalAttributes.ENABLE_DATE_NAME)) {
            Long millis = getSingleValue(icfAttr, Long.class);
            if (millis == null) {
                continue;
            }
            ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
            activationType.setValidFrom(XmlTypeConverter.createXMLGregorianCalendar(millis));
            continue;
        }
        if (icfAttr.getName().equals(OperationalAttributes.DISABLE_DATE_NAME)) {
            Long millis = getSingleValue(icfAttr, Long.class);
            if (millis == null) {
                continue;
            }
            ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
            activationType.setValidTo(XmlTypeConverter.createXMLGregorianCalendar(millis));
            continue;
        }
        if (icfAttr.getName().equals(OperationalAttributes.LOCK_OUT_NAME)) {
            Boolean lockOut = getSingleValue(icfAttr, Boolean.class);
            if (lockOut == null) {
                continue;
            }
            ActivationType activationType = ShadowUtil.getOrCreateActivation(shadow);
            LockoutStatusType lockoutStatusType;
            if (lockOut) {
                lockoutStatusType = LockoutStatusType.LOCKED;
            } else {
                lockoutStatusType = LockoutStatusType.NORMAL;
            }
            activationType.setLockoutStatus(lockoutStatusType);
            LOGGER.trace("Converted activation lockoutStatus: {}", lockoutStatusType);
            continue;
        }
        QName qname = icfNameMapper.convertAttributeNameToQName(icfAttr.getName(), attributesContainerDefinition);
        ResourceAttributeDefinition attributeDefinition = attributesContainerDefinition.findAttributeDefinition(qname, caseIgnoreAttributeNames);
        if (attributeDefinition == null) {
            // Try to locate definition in auxiliary object classes
            for (ObjectClassComplexTypeDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
                attributeDefinition = auxiliaryObjectClassDefinition.findAttributeDefinition(qname, caseIgnoreAttributeNames);
                if (attributeDefinition != null) {
                    break;
                }
            }
            if (attributeDefinition == null) {
                throw new SchemaException("Unknown attribute " + qname + " in definition of object class " + attributesContainerDefinition.getTypeName() + ". Original ICF name: " + icfAttr.getName(), qname);
            }
        }
        if (caseIgnoreAttributeNames) {
            // normalized version
            qname = attributeDefinition.getName();
        }
        ResourceAttribute<Object> resourceAttribute = attributeDefinition.instantiate(qname);
        // resource object also with the null-values attributes
        if (full) {
            if (icfAttr.getValue() != null) {
                // of them may need it (e.g. GuardedString)
                for (Object icfValue : icfAttr.getValue()) {
                    Object value = convertValueFromIcf(icfValue, qname);
                    resourceAttribute.add(new PrismPropertyValue<>(value));
                }
            }
            LOGGER.trace("Converted attribute {}", resourceAttribute);
            attributesContainer.getValue().add(resourceAttribute);
        // in this case when false, we need only the attributes with the
        // non-null values.
        } else {
            if (icfAttr.getValue() != null && !icfAttr.getValue().isEmpty()) {
                // Convert the values. While most values do not need
                // conversions, some of them may need it (e.g. GuardedString)
                boolean empty = true;
                for (Object icfValue : icfAttr.getValue()) {
                    if (icfValue != null) {
                        Object value = convertValueFromIcf(icfValue, qname);
                        empty = false;
                        resourceAttribute.add(new PrismPropertyValue<>(value));
                    }
                }
                if (!empty) {
                    LOGGER.trace("Converted attribute {}", resourceAttribute);
                    attributesContainer.getValue().add(resourceAttribute);
                }
            }
        }
    }
    // Add Uid if it is not there already. It can be already present, 
    // e.g. if Uid and Name represent the same attribute
    Uid uid = co.getUid();
    ObjectClassComplexTypeDefinition ocDef = attributesContainerDefinition.getComplexTypeDefinition();
    ResourceAttributeDefinition<String> uidDefinition = ConnIdUtil.getUidDefinition(ocDef);
    if (uidDefinition == null) {
        throw new SchemaException("No definition for ConnId UID attribute found in definition " + ocDef);
    }
    if (attributesContainer.getValue().findItem(uidDefinition.getName()) == null) {
        ResourceAttribute<String> uidRoa = uidDefinition.instantiate();
        uidRoa.setValue(new PrismPropertyValue<String>(uid.getUidValue()));
        attributesContainer.getValue().add(uidRoa);
    }
    return shadowPrism;
}
Also used : ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) Attribute(org.identityconnectors.framework.common.objects.Attribute) ArrayList(java.util.ArrayList) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) GuardedString(org.identityconnectors.common.security.GuardedString) ResourceAttributeContainerDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeContainerDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) QName(javax.xml.namespace.QName) ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) Uid(org.identityconnectors.framework.common.objects.Uid) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) LockoutStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 18 with ResourceAttributeContainer

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

the class ConnIdNameMapper method objectClassToIcf.

public ObjectClass objectClassToIcf(PrismObject<? extends ShadowType> shadow, String schemaNamespace, ConnectorType connectorType, boolean legacySchema) {
    ShadowType shadowType = shadow.asObjectable();
    QName qnameObjectClass = shadowType.getObjectClass();
    if (qnameObjectClass == null) {
        ResourceAttributeContainer attrContainer = ShadowUtil.getAttributesContainer(shadowType);
        if (attrContainer == null) {
            return null;
        }
        ResourceAttributeContainerDefinition objectClassDefinition = attrContainer.getDefinition();
        qnameObjectClass = objectClassDefinition.getTypeName();
    }
    return objectClassToIcf(qnameObjectClass, schemaNamespace, connectorType, legacySchema);
}
Also used : ResourceAttributeContainerDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeContainerDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)

Example 19 with ResourceAttributeContainer

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

the class TestUcfDummyMulti method test100AddAccount.

@Test
public void test100AddAccount() throws Exception {
    final String TEST_NAME = "test100AddAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    ShadowType shadowType = new ShadowType();
    PrismTestUtil.getPrismContext().adopt(shadowType);
    shadowType.setName(PrismTestUtil.createPolyStringType(ACCOUNT_JACK_USERNAME));
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.setOid(resource.getOid());
    shadowType.setResourceRef(resourceRef);
    shadowType.setObjectClass(defaultAccountDefinition.getTypeName());
    PrismObject<ShadowType> shadow = shadowType.asPrismObject();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, defaultAccountDefinition);
    ResourceAttribute<String> icfsNameProp = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME);
    icfsNameProp.setRealValue(ACCOUNT_JACK_USERNAME);
    // WHEN
    cc.addObject(shadow, null, null, result);
    // THEN
    DummyAccount dummyAccount = dummyResource.getAccountByUsername(ACCOUNT_JACK_USERNAME);
    assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " was not created", dummyAccount);
    assertNotNull("Account " + ACCOUNT_JACK_USERNAME + " has no username", dummyAccount.getName());
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 20 with ResourceAttributeContainer

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

the class AbstractIntegrationTest method createShadow.

protected PrismObject<ShadowType> createShadow(PrismObject<ResourceType> resource, String uid, String name) throws SchemaException {
    PrismObject<ShadowType> shadow = getShadowDefinition().instantiate();
    ShadowType shadowType = shadow.asObjectable();
    if (name != null) {
        shadowType.setName(PrismTestUtil.createPolyStringType(name));
    }
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.setOid(resource.getOid());
    shadowType.setResourceRef(resourceRef);
    shadowType.setKind(ShadowKindType.ACCOUNT);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
    RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    shadowType.setObjectClass(objectClassDefinition.getTypeName());
    ResourceAttributeContainer attrContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, objectClassDefinition);
    if (uid != null) {
        RefinedAttributeDefinition uidAttrDef = objectClassDefinition.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"));
        ResourceAttribute<String> uidAttr = uidAttrDef.instantiate();
        uidAttr.setRealValue(uid);
        attrContainer.add(uidAttr);
    }
    if (name != null) {
        RefinedAttributeDefinition nameAttrDef = objectClassDefinition.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
        ResourceAttribute<String> nameAttr = nameAttrDef.instantiate();
        nameAttr.setRealValue(name);
        attrContainer.add(nameAttr);
    }
    return shadow;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) QName(javax.xml.namespace.QName) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)20 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 Test (org.testng.annotations.Test)8 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)6 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)6 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 Task (com.evolveum.midpoint.task.api.Task)5 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)5 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PropertyModificationOperation (com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation)3 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)3