Search in sources :

Example 1 with ResourceAttribute

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

the class TestUtil method setAttribute.

public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException {
    PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES);
    ResourceAttributeDefinition attrDef = new ResourceAttributeDefinitionImpl(attrName, typeName, prismContext);
    ResourceAttribute attribute = attrDef.instantiate();
    attribute.setRealValue(value);
    attributesContainer.add(attribute);
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceAttributeDefinitionImpl(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinitionImpl)

Example 2 with ResourceAttribute

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

the class DefaultGuiProgressListener method updateStatusItemState.

private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
    si.setActivityType(progressInformation.getActivityType());
    si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
    if (progressInformation.getResourceShadowDiscriminator() != null) {
        String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
        String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
        si.setResourceName(resourceName);
    }
    if (progressInformation.getStateType() == null) {
        si.setStatus(null);
    } else if (progressInformation.getStateType() == ENTERING) {
        si.setStatus(OperationResultStatusType.IN_PROGRESS);
    } else {
        OperationResult result = progressInformation.getOperationResult();
        if (result != null) {
            OperationResultStatus status = result.getStatus();
            if (status == OperationResultStatus.UNKNOWN) {
                status = result.getComputeStatus();
            }
            si.setStatus(status.createStatusType());
        } else {
            si.setStatus(OperationResultStatusType.UNKNOWN);
        }
    }
    // information about modifications on a resource
    if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
        ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
        if (mpc != null) {
            // it shouldn't be null!
            // operations performed (TODO aggregate them somehow?)
            List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
            List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
            for (ObjectDeltaOperation executedDelta : executedDeltas) {
                ObjectDelta delta = executedDelta.getObjectDelta();
                if (delta != null) {
                    OperationResult r = executedDelta.getExecutionResult();
                    OperationResultStatus status = r.getStatus();
                    if (status == OperationResultStatus.UNKNOWN) {
                        status = r.getComputeStatus();
                    }
                    resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
                }
            }
            si.setResourceOperationResultList(resourceOperationResultList);
            // object name
            PrismObject<ShadowType> object = mpc.getObjectNew();
            if (object == null) {
                object = mpc.getObjectOld();
            }
            String name = null;
            if (object != null) {
                if (object.asObjectable().getName() != null) {
                    name = PolyString.getOrig(object.asObjectable().getName());
                } else {
                    // determine from attributes
                    ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
                    if (nameAttribute != null) {
                        name = String.valueOf(nameAttribute.getAnyRealValue());
                    }
                }
            }
            if (name != null) {
                si.setResourceObjectName(name);
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 3 with ResourceAttribute

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

the class AbstractAdLdapMultidomainTest method test200AssignAccountBarbossa.

//	/**
//	 * Blocksize is 5, so this gets more than two blocks.
//	 */
//	@Test
//    public void test154SeachFirst11Accounts() throws Exception {
//		final String TEST_NAME = "test154SeachFirst11Accounts";
//        TestUtil.displayTestTile(this, TEST_NAME);
//        
//        // GIVEN
//        Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        
//        ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//        
//        ObjectPaging paging = ObjectPaging.createEmptyPaging();
//        paging.setMaxSize(11);
//		query.setPaging(paging);
//		
//		SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 11, task, result);
//                
//        assertConnectorOperationIncrement(1);
//        assertConnectorSimulatedPagingSearchIncrement(0);
//        
//        SearchResultMetadata metadata = searchResultList.getMetadata();
//        if (metadata != null) {
//        	assertFalse(metadata.isPartialResults());
//        }
//        
//        assertLdapConnectorInstances(2);
//    }
//	
//	@Test
//    public void test162SeachFirst2AccountsOffset0() throws Exception {
//		final String TEST_NAME = "test162SeachFirst2AccountsOffset0";
//        TestUtil.displayTestTile(this, TEST_NAME);
//        
//        // GIVEN
//        Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        
//        ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//        
//        ObjectPaging paging = ObjectPaging.createEmptyPaging();
//        paging.setOffset(0);
//        paging.setMaxSize(2);
//		query.setPaging(paging);
//        
//		SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 2, task, result);
//        
//        assertConnectorOperationIncrement(1);
//        assertConnectorSimulatedPagingSearchIncrement(0);
//        
//        SearchResultMetadata metadata = searchResultList.getMetadata();
//        if (metadata != null) {
//        	assertFalse(metadata.isPartialResults());
//        }
//        
//        assertLdapConnectorInstances(2);
//    }
//	
//	/**
//	 * Blocksize is 5, so this is in one block.
//	 * There is offset, so VLV should be used.
//	 * No explicit sorting.
//	 */
//	@Test
//    public void test172Search2AccountsOffset1() throws Exception {
//		final String TEST_NAME = "test172Search2AccountsOffset1";
//        TestUtil.displayTestTile(this, TEST_NAME);
//        
//        // GIVEN
//        Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        
//        ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//        
//        ObjectPaging paging = ObjectPaging.createPaging(1, 2);
//		query.setPaging(paging);
//        
//		SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 2, task, result);
//        
//        assertConnectorOperationIncrement(1);
//        assertConnectorSimulatedPagingSearchIncrement(0);
//        
//        SearchResultMetadata metadata = searchResultList.getMetadata();
//        if (metadata != null) {
//        	assertFalse(metadata.isPartialResults());
//        }
//        
//        assertLdapConnectorInstances(2);
//    }
//	
//	/**
//	 * Blocksize is 5, so this gets more than two blocks.
//	 * There is offset, so VLV should be used.
//	 * No explicit sorting.
//	 */
//	@Test
//    public void test174SeachFirst11AccountsOffset2() throws Exception {
//		final String TEST_NAME = "test174SeachFirst11AccountsOffset2";
//        TestUtil.displayTestTile(this, TEST_NAME);
//        
//        // GIVEN
//        Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        
//        ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//        
//        ObjectPaging paging = ObjectPaging.createPaging(2, 11);
//		query.setPaging(paging);
//        
//		allowDuplicateSearchResults = true;
//		
//		// WHEN
//		SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(TEST_NAME, query, 11, task, result);
//        
//		// THEN
//		allowDuplicateSearchResults = false;
//		
//        assertConnectorOperationIncrement(1);
//        assertConnectorSimulatedPagingSearchIncrement(0);
//        
//        SearchResultMetadata metadata = searchResultList.getMetadata();
//        if (metadata != null) {
//        	assertFalse(metadata.isPartialResults());
//        }
//        
//        assertLdapConnectorInstances(2);
//    }
//	
//	/**
//	 * Blocksize is 5, so this is in one block.
//	 * There is offset, so VLV should be used.
//	 * Explicit sorting.
//	 */
//	@Test
//    public void test182Search2AccountsOffset1SortCn() throws Exception {
//		final String TEST_NAME = "test182Search2AccountsOffset1SortCn";
//        TestUtil.displayTestTile(this, TEST_NAME);
//        
//        // GIVEN
//        Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        
//        ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
//        
//        ObjectPaging paging = ObjectPaging.createPaging(1, 2);
//        paging.setOrdering(getAttributePath(resource, "cn"), OrderDirection.ASCENDING);
//		query.setPaging(paging);
//        
//		SearchResultList<PrismObject<ShadowType>> shadows = doSearch(TEST_NAME, query, 2, task, result);
//        
//        assertAccountShadow(shadows.get(0), "CN=Adalbert Meduza,OU=evolveum,DC=win,DC=evolveum,DC=com");
//        assertAccountShadow(shadows.get(1), "CN=Adalbert Meduza1,OU=evolveum,DC=win,DC=evolveum,DC=com");
//        
//        assertConnectorOperationIncrement(1);
//        assertConnectorSimulatedPagingSearchIncrement(0);
//        
//        SearchResultMetadata metadata = shadows.getMetadata();
//        if (metadata != null) {
//        	assertFalse(metadata.isPartialResults());
//        }
//
//        assertLdapConnectorInstances(2);
//    }
@Test
public void test200AssignAccountBarbossa() throws Exception {
    final String TEST_NAME = "test200AssignAccountBarbossa";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    long tsStart = System.currentTimeMillis();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assignAccount(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    long tsEnd = System.currentTimeMillis();
    Entry entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    assertAttribute(entry, "title", null);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    String shadowOid = getSingleLinkOid(user);
    PrismObject<ShadowType> shadow = getShadowModel(shadowOid);
    display("Shadow (model)", shadow);
    accountBarbossaOid = shadow.getOid();
    Collection<ResourceAttribute<?>> identifiers = ShadowUtil.getPrimaryIdentifiers(shadow);
    String accountBarbossaIcfUid = (String) identifiers.iterator().next().getRealValue();
    assertNotNull("No identifier in " + shadow, accountBarbossaIcfUid);
    assertEquals("Wrong ICFS UID", AdUtils.formatGuidToDashedNotation(MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes())), accountBarbossaIcfUid);
    assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, USER_BARBOSSA_PASSWORD);
    assertAttribute(entry, ATTRIBUTE_USER_ACCOUNT_CONTROL_NAME, "512");
    ResourceAttribute<Long> createTimestampAttribute = ShadowUtil.getAttribute(shadow, new QName(MidPointConstants.NS_RI, "createTimeStamp"));
    assertNotNull("No createTimestamp in " + shadow, createTimestampAttribute);
    Long createTimestamp = createTimestampAttribute.getRealValue();
    // LDAP server may be on a different host. Allow for some clock offset.
    TestUtil.assertBetween("Wrong createTimestamp in " + shadow, roundTsDown(tsStart) - 120000, roundTsUp(tsEnd) + 120000, createTimestamp);
//        assertLdapConnectorInstances(2);
}
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) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 4 with ResourceAttribute

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

the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.

/**
	 * Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers. 
	 */
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (identifiers == null) {
        return null;
    }
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, ctx.getObjectClassDefinition());
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        return null;
    }
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        return null;
    }
    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 identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, ocDef);
    return primaryIdentifiers;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 5 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)

Aggregations

ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)52 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)23 Test (org.testng.annotations.Test)18 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)16 Task (com.evolveum.midpoint.task.api.Task)16 QName (javax.xml.namespace.QName)16 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 Entry (org.apache.directory.api.ldap.model.entry.Entry)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ArrayList (java.util.ArrayList)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)7 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 Containerable (com.evolveum.midpoint.prism.Containerable)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)4 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)4 ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)4