Search in sources :

Example 51 with ResourceAttribute

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

the class ObjectAlreadyExistHandler method createQueryBySecondaryIdentifier.

protected static ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow, PrismContext prismContext) {
    // TODO ensure that the identifiers are normalized here
    // Note that if the query is to be used against the repository, we should not provide matching rules here. See MID-5547.
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow);
    S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
    q = q.block();
    if (secondaryIdentifiers.isEmpty()) {
        for (ResourceAttribute<?> primaryIdentifier : ShadowUtil.getPrimaryIdentifiers(shadow)) {
            q = q.itemAs(primaryIdentifier).or();
        }
    } else {
        // secondary identifiers connected by 'or' clause
        for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) {
            q = q.itemAs(secondaryIdentifier).or();
        }
    }
    q = q.none().endBlock().and();
    // resource + object class
    q = q.item(ShadowType.F_RESOURCE_REF).ref(shadow.getResourceRef().getOid()).and();
    return q.item(ShadowType.F_OBJECT_CLASS).eq(shadow.getObjectClass()).build();
}
Also used : S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 52 with ResourceAttribute

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

the class AbstractEDirTest method test200AssignAccountBarbossa.

@Test
public void test200AssignAccountBarbossa() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    long tsStart = System.currentTimeMillis();
    // WHEN
    when();
    assignAccountToUser(USER_BARBOSSA_OID, getResourceOid(), null, task, result);
    // THEN
    then();
    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", MiscUtil.binaryToHex(entry.get(getPrimaryIdentifierAttributeName()).getBytes()), accountBarbossaIcfUid);
    assertLdapPassword(USER_BARBOSSA_USERNAME, USER_BARBOSSA_PASSWORD);
    assertPasswordAllowChange(shadow, null);
    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) - 1000, roundTsUp(tsEnd) + 1000, createTimestamp);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Entry(org.apache.directory.api.ldap.model.entry.Entry) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) Test(org.testng.annotations.Test)

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