Search in sources :

Example 6 with ResourceAttribute

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

the class ProvisioningUtil method normalizeShadow.

public static <T extends ShadowType> void normalizeShadow(T shadow, OperationResult result) throws SchemaException {
    if (shadow.getAttemptNumber() != null) {
        shadow.setAttemptNumber(null);
    }
    if (shadow.getFailedOperationType() != null) {
        shadow.setFailedOperationType(null);
    }
    if (shadow.getObjectChange() != null) {
        shadow.setObjectChange(null);
    }
    if (shadow.getResult() != null) {
        shadow.setResult(null);
    }
    if (shadow.getCredentials() != null) {
        shadow.setCredentials(null);
    }
    ResourceAttributeContainer normalizedContainer = ShadowUtil.getAttributesContainer(shadow);
    ResourceAttributeContainer oldContainer = normalizedContainer.clone();
    normalizedContainer.clear();
    Collection<ResourceAttribute<?>> identifiers = oldContainer.getPrimaryIdentifiers();
    for (PrismProperty<?> p : identifiers) {
        normalizedContainer.getValue().add(p.clone());
    }
    Collection<ResourceAttribute<?>> secondaryIdentifiers = oldContainer.getSecondaryIdentifiers();
    for (PrismProperty<?> p : secondaryIdentifiers) {
        normalizedContainer.getValue().add(p.clone());
    }
    cleanupShadowActivation(shadow);
}
Also used : ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 7 with ResourceAttribute

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

the class AbstractBasicDummyTest method test106GetModifiedAccount.

/**
	 * Make a native modification to an account and read it again. Make sure that
	 * fresh data are returned - even though caching may be in effect.
	 * MID-3481
	 */
@Test
public void test106GetModifiedAccount() throws Exception {
    final String TEST_NAME = "test106GetModifiedAccount";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + "." + TEST_NAME);
    rememberShadowFetchOperationCount();
    DummyAccount accountWill = getDummyAccountAssert(transformNameFromResource(ACCOUNT_WILL_USERNAME), willIcfUid);
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    accountWill.replaceAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    accountWill.setEnabled(false);
    XMLGregorianCalendar startTs = clock.currentTimeXMLGregorianCalendar();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, null, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    assertShadowFetchOperationCountIncrement(1);
    XMLGregorianCalendar endTs = clock.currentTimeXMLGregorianCalendar();
    display("Retrieved account shadow", shadow);
    assertNotNull("No dummy account", shadow);
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "Sword", "LOVE");
    assertAttribute(shadow, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    Collection<ResourceAttribute<?>> attributes = ShadowUtil.getAttributes(shadow);
    assertEquals("Unexpected number of attributes", 7, attributes.size());
    PrismObject<ShadowType> shadowRepo = repositoryService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, result);
    checkRepoAccountShadowWillBasic(shadowRepo, startTs, endTs, null);
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME, "Pirate");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "Black Pearl");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_NAME, "sword", "love");
    assertRepoShadowCachedAttributeValue(shadowRepo, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOOT_NAME, 42);
    assertRepoShadowCacheActivation(shadowRepo, ActivationStatusType.DISABLED);
    checkConsistency(shadow);
    assertCachingMetadata(shadow, false, startTs, endTs);
    assertSteadyResource();
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test)

Example 8 with ResourceAttribute

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

the class ShadowManager method createRepositoryShadow.

/**
	 * Create a copy of a shadow that is suitable for repository storage. 
	 */
private PrismObject<ShadowType> createRepositoryShadow(ProvisioningContext ctx, PrismObject<ShadowType> shadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow);
    PrismObject<ShadowType> repoShadow = shadow.clone();
    ShadowType repoShadowType = repoShadow.asObjectable();
    ResourceAttributeContainer repoAttributesContainer = ShadowUtil.getAttributesContainer(repoShadow);
    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).
        RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
        for (RefinedAssociationDefinition associationDef : objectClassDefinition.getAssociationDefinitions()) {
            if (associationDef.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT) {
                QName valueAttributeName = associationDef.getResourceObjectAssociationType().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);
    }
    setKindIfNecessary(repoShadowType, ctx.getObjectClassDefinition());
    //        setIntentIfNecessary(repoShadowType, objectClassDefinition);
    // Store only password meta-data in repo
    CredentialsType creds = repoShadowType.getCredentials();
    if (creds != null) {
        PasswordType passwordType = creds.getPassword();
        if (passwordType != null) {
            ProvisioningUtil.cleanupShadowPassword(passwordType);
            PrismObject<UserType> owner = null;
            if (ctx.getTask() != null) {
                owner = ctx.getTask().getOwner();
            }
            ProvisioningUtil.addPasswordMetadata(passwordType, clock.currentTimeXMLGregorianCalendar(), owner);
        }
    // TODO: other credential types - later
    }
    // convert to the resource reference.
    if (repoShadowType.getResource() != null) {
        repoShadowType.setResource(null);
        repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
    }
    // now
    if (repoShadowType.getResourceRef() == null) {
        repoShadowType.setResourceRef(ObjectTypeUtil.createObjectRef(ctx.getResource()));
    }
    if (repoShadowType.getName() == null) {
        repoShadowType.setName(new PolyStringType(ShadowUtil.determineShadowName(shadow)));
    }
    if (repoShadowType.getObjectClass() == null) {
        repoShadowType.setObjectClass(attributesContainer.getDefinition().getTypeName());
    }
    if (repoShadowType.isProtectedObject() != null) {
        repoShadowType.setProtectedObject(null);
    }
    normalizeAttributes(repoShadow, ctx.getObjectClassDefinition());
    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) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 9 with ResourceAttribute

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

the class TestDummy method testLiveSyncDeleteCorsairs.

public void testLiveSyncDeleteCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    if (isNameUnique()) {
        dummyResource.deleteGroupByName(GROUP_CORSAIRS_NAME);
    } else {
        dummyResource.deleteGroupById(corsairsIcfUid);
    }
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
        ShadowType oldShadowType = oldShadow.asObjectable();
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
        assertNotNull("No attributes container in old shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
        assertNotNull("No ICF name attribute in old  shadow", icfsNameAttribute);
        assertEquals("Wrong value of ICF name attribute in old  shadow", GROUP_CORSAIRS_NAME, icfsNameAttribute.getRealValue());
        ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
        assertNotNull("Delta missing", objectDelta);
        assertEquals("Wrong delta changetype", ChangeType.DELETE, objectDelta.getChangeType());
        PrismAsserts.assertClass("delta", ShadowType.class, objectDelta);
        assertNotNull("No OID in delta", objectDelta.getOid());
        assertNull("Unexpected current shadow", lastChange.getCurrentShadow());
        try {
            // The shadow should be gone
            PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
            AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
        } catch (ObjectNotFoundException e) {
        // This is expected
        }
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 10 with ResourceAttribute

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

the class TestDummy method testLiveSyncAddCorsairs.

public void testLiveSyncAddCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    DummyGroup newGroup = new DummyGroup(GROUP_CORSAIRS_NAME);
    newGroup.setEnabled(true);
    dummyResource.addGroup(newGroup);
    corsairsIcfUid = newGroup.getId();
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        if (syncStyle == DummySyncStyle.DUMB) {
            assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
        } else {
            ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
            assertNotNull("Delta present when not expecting it", objectDelta);
            assertTrue("Delta is not add: " + objectDelta, objectDelta.isAdd());
        }
        ShadowType currentShadowType = lastChange.getCurrentShadow().asObjectable();
        assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
        PrismAsserts.assertClass("current shadow", ShadowType.class, currentShadowType);
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadowType);
        assertNotNull("No attributes container in current shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        corsairsShadowOid = currentShadowType.getOid();
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
        display("Corsairs repo shadow", repoShadow);
        PrismObject<ShadowType> accountRepo = findShadowByName(new QName(RESOURCE_DUMMY_NS, SchemaConstants.GROUP_OBJECT_CLASS_LOCAL_NAME), GROUP_CORSAIRS_NAME, resource, result);
        assertNotNull("Shadow was not created in the repository", accountRepo);
        display("Repository shadow", accountRepo);
        ProvisioningTestUtil.checkRepoShadow(repoShadow, ShadowKindType.ENTITLEMENT);
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : 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) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup)

Aggregations

ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)39 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)30 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)23 Test (org.testng.annotations.Test)18 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)16 Task (com.evolveum.midpoint.task.api.Task)12 QName (javax.xml.namespace.QName)12 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 Entry (org.apache.directory.api.ldap.model.entry.Entry)7 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)6 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)6 ArrayList (java.util.ArrayList)6 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)3 Containerable (com.evolveum.midpoint.prism.Containerable)3