Search in sources :

Example 26 with ResourceAttribute

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

the class ConsistencyTest method test800Reconciliation.

// This should run last. It starts a task that may interfere with other tests
@Test
public void test800Reconciliation() throws Exception {
    final String TEST_NAME = "test800Reconciliation";
    TestUtil.displayTestTile(this, TEST_NAME);
    openDJController.assumeRunning();
    final OperationResult result = new OperationResult(ConsistencyTest.class.getName() + "." + TEST_NAME);
    // TODO: remove this if the previous test is enabled
    //		openDJController.start();
    // rename eobject dirrectly on resource before the recon start ..it tests the rename + recon situation (MID-1594)
    // precondition
    assertTrue(EmbeddedUtils.isRunning());
    UserType userJack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result).asObjectable();
    display("Jack before", userJack);
    LOGGER.info("start running task");
    // WHEN
    repoAddObjectFromFile(TASK_OPENDJ_RECONCILIATION_FILENAME, result);
    verbose = true;
    long started = System.currentTimeMillis();
    waitForTaskNextRunAssertSuccess(TASK_OPENDJ_RECONCILIATION_OID, false, 120000);
    LOGGER.info("Reconciliation task run took {} seconds", (System.currentTimeMillis() - started) / 1000L);
    // THEN
    // STOP the task. We don't need it any more. Even if it's non-recurrent its safer to delete it
    taskManager.deleteTask(TASK_OPENDJ_RECONCILIATION_OID, result);
    // check if the account was added after reconciliation
    UserType userE = repositoryService.getObject(UserType.class, USER_E_OID, null, result).asObjectable();
    String accountOid = assertUserOneAccountRef(USER_E_OID);
    ShadowType eAccount = checkNormalizedShadowWithAttributes(accountOid, "e", "Jackkk", "e", "e", true, null, result);
    assertAttribute(eAccount, "employeeNumber", "emp4321");
    ResourceAttributeContainer attributeContainer = ShadowUtil.getAttributesContainer(eAccount);
    Collection<ResourceAttribute<?>> identifiers = attributeContainer.getPrimaryIdentifiers();
    assertNotNull(identifiers);
    assertFalse(identifiers.isEmpty());
    assertEquals(1, identifiers.size());
    // check if the account was modified during reconciliation process
    String jackAccountOid = assertUserOneAccountRef(USER_JACK_OID);
    ShadowType modifiedAccount = checkNormalizedShadowBasic(jackAccountOid, "jack", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
    assertAttribute(modifiedAccount, "givenName", "Jackkk");
    assertAttribute(modifiedAccount, "employeeNumber", "emp4321");
    // check if the account was deleted during the reconciliation process
    try {
        modelService.getObject(ShadowType.class, ACCOUNT_DENIELS_OID, null, null, result);
        fail("Expected ObjectNotFoundException but haven't got one.");
    } catch (Exception ex) {
        if (!(ex instanceof ObjectNotFoundException)) {
            fail("Expected ObjectNotFoundException but got " + ex);
        }
    }
    String elaineAccountOid = assertUserOneAccountRef(USER_ELAINE_OID);
    modifiedAccount = checkNormalizedShadowBasic(elaineAccountOid, "elaine", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
    assertAttribute(modifiedAccount, getOpenDjSecondaryIdentifierQName(), "uid=elaine,ou=people,dc=example,dc=com");
    accountOid = assertUserOneAccountRef(USER_JACK2_OID);
    ShadowType jack2Shadow = checkNormalizedShadowBasic(accountOid, "jack2", true, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), null, result);
    assertAttribute(jack2Shadow, "givenName", "jackNew2a");
    assertAttribute(jack2Shadow, "cn", "jackNew2a");
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) JAXBException(javax.xml.bind.JAXBException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 27 with ResourceAttribute

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

the class ConsistencyTest method test801TestReconciliationRename.

@Test
public void test801TestReconciliationRename() throws Exception {
    final String TEST_NAME = "test801TestReconciliationRename";
    TestUtil.displayTestTile(this, TEST_NAME);
    openDJController.assumeRunning();
    Task task = createTask(TEST_NAME);
    final OperationResult result = task.getResult();
    LOGGER.info("starting rename");
    openDJController.executeRenameChange(LDIF_MODIFY_RENAME_FILENAME);
    LOGGER.info("rename ended");
    //		Entry res = openDJController.searchByUid("e");
    //		LOGGER.info("E OBJECT AFTER RENAME " + res.toString());
    LOGGER.info("start running task");
    // WHEN
    long started = System.currentTimeMillis();
    repoAddObjectFromFile(TASK_OPENDJ_RECONCILIATION_FILENAME, result);
    waitForTaskFinish(TASK_OPENDJ_RECONCILIATION_OID, false, 120000);
    LOGGER.info("Reconciliation task run took {} seconds", (System.currentTimeMillis() - started) / 1000L);
    // THEN
    // STOP the task. We don't need it any more. Even if it's non-recurrent its safer to delete it
    taskManager.deleteTask(TASK_OPENDJ_RECONCILIATION_OID, result);
    // check if the account was added after reconciliation
    UserType userE = repositoryService.getObject(UserType.class, USER_E_OID, null, result).asObjectable();
    String accountOid = assertUserOneAccountRef(USER_E_OID);
    ShadowType eAccount = checkNormalizedShadowWithAttributes(accountOid, "e123", "Jackkk", "e", "e", true, null, result);
    assertAttribute(eAccount, "employeeNumber", "emp4321");
    ResourceAttributeContainer attributeContainer = ShadowUtil.getAttributesContainer(eAccount);
    Collection<ResourceAttribute<?>> identifiers = attributeContainer.getPrimaryIdentifiers();
    assertNotNull(identifiers);
    assertFalse(identifiers.isEmpty());
    assertEquals(1, identifiers.size());
    ResourceAttribute icfNameAttr = attributeContainer.findAttribute(getOpenDjSecondaryIdentifierQName());
    assertEquals("Wrong secondary indetifier.", "uid=e123,ou=people,dc=example,dc=com", icfNameAttr.getRealValue());
    assertEquals("Wrong shadow name. ", "uid=e123,ou=people,dc=example,dc=com", eAccount.getName().getOrig());
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    provisioningService.applyDefinition(repoShadow, task, result);
    ResourceAttributeContainer repoAttributeContainer = ShadowUtil.getAttributesContainer(repoShadow);
    ResourceAttribute repoIcfNameAttr = repoAttributeContainer.findAttribute(getOpenDjSecondaryIdentifierQName());
    assertEquals("Wrong secondary indetifier.", "uid=e123,ou=people,dc=example,dc=com", repoIcfNameAttr.getRealValue());
    assertEquals("Wrong shadow name. ", "uid=e123,ou=people,dc=example,dc=com", repoShadow.asObjectable().getName().getOrig());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) 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) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 28 with ResourceAttribute

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

the class AbstractModelIntegrationTest method createAccount.

protected PrismObject<ShadowType> createAccount(PrismObject<ResourceType> resource, String name, boolean enabled) throws SchemaException {
    PrismObject<ShadowType> shadow = getShadowDefinition().instantiate();
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = new ObjectReferenceType();
    resourceRef.setOid(resource.getOid());
    shadowType.setResourceRef(resourceRef);
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
    RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    shadowType.setObjectClass(objectClassDefinition.getTypeName());
    shadowType.setKind(ShadowKindType.ACCOUNT);
    ResourceAttributeContainer attrCont = ShadowUtil.getOrCreateAttributesContainer(shadow, objectClassDefinition);
    RefinedAttributeDefinition idSecondaryDef = objectClassDefinition.getSecondaryIdentifiers().iterator().next();
    ResourceAttribute icfsNameAttr = idSecondaryDef.instantiate();
    icfsNameAttr.setRealValue(name);
    attrCont.add(icfsNameAttr);
    ActivationType activation = new ActivationType();
    shadowType.setActivation(activation);
    if (enabled) {
        activation.setAdministrativeStatus(ActivationStatusType.ENABLED);
    } else {
        activation.setAdministrativeStatus(ActivationStatusType.DISABLED);
    }
    return shadow;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 29 with ResourceAttribute

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

the class ShadowManager method searchShadowByIdenifiers.

private List<PrismObject<ShadowType>> searchShadowByIdenifiers(ProvisioningContext ctx, Change change, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    Collection<ResourceAttribute<?>> identifiers = change.getIdentifiers();
    ObjectQuery query = createSearchShadowQuery(ctx, identifiers, true, prismContext, parentResult);
    List<PrismObject<ShadowType>> accountList = null;
    try {
        accountList = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
    } catch (SchemaException ex) {
        parentResult.recordFatalError("Failed to search shadow according to the identifiers: " + identifiers + ". Reason: " + ex.getMessage(), ex);
        throw new SchemaException("Failed to search shadow according to the identifiers: " + identifiers + ". Reason: " + ex.getMessage(), ex);
    }
    MiscSchemaUtil.reduceSearchResult(accountList);
    return accountList;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 30 with ResourceAttribute

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

the class ResourceObjectReferenceResolver method resolvePrimaryIdentifiers.

/**
	 * Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers. 
	 */
private ResourceObjectIdentification resolvePrimaryIdentifiers(ProvisioningContext ctx, ResourceObjectIdentification identification, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (identification == null) {
        return identification;
    }
    if (identification.hasPrimaryIdentifiers()) {
        return identification;
    }
    Collection<ResourceAttribute<?>> secondaryIdentifiers = (Collection<ResourceAttribute<?>>) identification.getSecondaryIdentifiers();
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        // TODO: we should attempt resource search here
        throw new ObjectNotFoundException("No repository shadow for " + secondaryIdentifiers + ", cannot resolve identifiers");
    }
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        throw new SchemaException("No attributes in " + repoShadow + ", cannot resolve identifiers " + secondaryIdentifiers);
    }
    RefinedObjectClassDefinition ocDef = ctx.getObjectClassDefinition();
    Collection primaryIdentifiers = new ArrayList<>();
    for (PrismProperty<?> property : attributesContainer.getValue().getProperties()) {
        if (ocDef.isPrimaryIdentifier(property.getElementName())) {
            RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName());
            ResourceAttribute<?> primaryIdentifier = new ResourceAttribute<>(property.getElementName(), attrDef, prismContext);
            primaryIdentifier.setRealValue(property.getRealValue());
            primaryIdentifiers.add(primaryIdentifier);
        }
    }
    LOGGER.trace("Resolved {} to primary identifiers {} (object class {})", identification, primaryIdentifiers, ocDef);
    return new ResourceObjectIdentification(identification.getObjectClassDefinition(), primaryIdentifiers, identification.getSecondaryIdentifiers());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ResourceObjectIdentification(com.evolveum.midpoint.schema.processor.ResourceObjectIdentification) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

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