Search in sources :

Example 21 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestSanity method test040UnlinkDerbyAccountFromUser.

/**
     * Unlink account by removing the accountRef from the user.
     * The account will not be deleted, just the association to user will be broken.
     */
@Test
public void test040UnlinkDerbyAccountFromUser() throws FileNotFoundException, JAXBException, FaultMessage, ObjectNotFoundException, SchemaException, DirectoryException, SQLException {
    TestUtil.displayTestTile("test040UnlinkDerbyAccountFromUser");
    // GIVEN
    ObjectDeltaType objectChange = new ObjectDeltaType();
    objectChange.setOid(USER_JACK_OID);
    ItemDeltaType modificationDeleteAccountRef = new ItemDeltaType();
    modificationDeleteAccountRef.setModificationType(ModificationTypeType.DELETE);
    ObjectReferenceType accountRefToDelete = new ObjectReferenceType();
    accountRefToDelete.setOid(accountShadowOidDerby);
    RawType modificationValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(accountRefToDelete), prismContext);
    modificationDeleteAccountRef.getValue().add(modificationValue);
    modificationDeleteAccountRef.setPath(new ItemPathType(new ItemPath(UserType.F_LINK_REF)));
    objectChange.getItemDelta().add(modificationDeleteAccountRef);
    objectChange.setChangeType(ChangeTypeType.MODIFY);
    objectChange.setObjectType(UserType.COMPLEX_TYPE);
    displayJaxb("modifyObject input", objectChange, new QName(SchemaConstants.NS_C, "change"));
    assertNoRepoCache();
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    assertNoRepoCache();
    displayJaxb("modifyObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("modifyObject has failed", result);
    // Check if user object was modified in the repo
    OperationResult repoResult = new OperationResult("getObject");
    PrismObject<UserType> uObject = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
    UserType repoUser = uObject.asObjectable();
    repoResult.computeStatus();
    display("User (repository)", repoUser);
    List<ObjectReferenceType> accountRefs = repoUser.getLinkRef();
    // only OpenDJ account should be left now
    assertEquals(1, accountRefs.size());
    ObjectReferenceType ref = accountRefs.get(0);
    assertEquals("Wrong OID in accountRef in " + repoUser, accountShadowOidOpendj, ref.getOid());
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 22 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestSanityLegacy method test501NotifyChangeModifyAccount.

@Test
public void test501NotifyChangeModifyAccount() throws Exception {
    TestUtil.displayTestTile("test501NotifyChangeModifyAccount");
    OperationResult parentResult = new OperationResult("test500notifyChange.addAngelicaAccount");
    PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelika);
    UserType user = userAngelika.asObjectable();
    assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
    assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
    String oid = user.getLinkRef().get(0).getOid();
    ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
    ObjectDeltaType delta = new ObjectDeltaType();
    delta.setChangeType(ChangeTypeType.MODIFY);
    delta.setObjectType(ShadowType.COMPLEX_TYPE);
    ItemDeltaType mod1 = new ItemDeltaType();
    mod1.setModificationType(ModificationTypeType.REPLACE);
    ItemPathType path = new ItemPathType(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(resourceTypeOpenDjrepo.getNamespace(), "givenName")));
    mod1.setPath(path);
    RawType value = new RawType(new PrimitiveXNode<String>("newAngelika"), prismContext);
    //TODO: shouldn't it be JaxbElement<PolyString>? 
    //    	Element el = DOMUtil.createElement(DOMUtil.getDocument(), new QName(resourceTypeOpenDjrepo.getNamespace(), "givenName"));
    //    	el.setTextContent("newAngelika");
    mod1.getValue().add(value);
    delta.getItemDelta().add(mod1);
    delta.setOid(oid);
    LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(mod1));
    LOGGER.info("delta: {}", DebugUtil.dump(mod1));
    changeDescription.setObjectDelta(delta);
    changeDescription.setOldShadowOid(oid);
    changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
    TaskType task = modelWeb.notifyChange(changeDescription);
    OperationResult result = OperationResult.createOperationResult(task.getResult());
    display(result);
    assertSuccess(result);
    PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
    assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
    UserType userAfterSync = userAngelikaAfterSync.asObjectable();
    PrismAsserts.assertEqualsPolyString("wrong given name in user angelika", PrismTestUtil.createPolyStringType("newAngelika"), userAfterSync.getGivenName());
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ResourceObjectShadowChangeDescriptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 23 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestUcfOpenDj method test610ChangePassword.

@Test
public void test610ChangePassword() throws Exception {
    final String TEST_NAME = "test610ChangePassword";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    ResourceAttributeContainer resourceObject = createResourceObject("uid=drake,ou=People,dc=example,dc=com", "Sir Francis Drake", "Drake");
    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);
    OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME);
    // Add a testing object
    cc.addObject(shadow, null, null, addResult);
    String entryUuid = (String) resourceObject.getPrimaryIdentifier().getValue().getValue();
    Entry entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry before change", entry);
    String passwordBefore = OpenDJController.getAttributeValue(entry, "userPassword");
    // We have set no password during create, therefore the password should
    // be empty
    assertNull(passwordBefore);
    ObjectClassComplexTypeDefinition accountDefinition = resourceObject.getDefinition().getComplexTypeDefinition();
    Collection<ResourceAttribute<?>> identifiers = resourceObject.getPrimaryIdentifiers();
    // Determine object class from the schema
    OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchObject");
    // WHEN
    Set<Operation> changes = new HashSet<Operation>();
    ProtectedStringType passPs = protector.encryptString("salalala");
    ItemDeltaType propMod = new ItemDeltaType();
    //create modification path
    Document doc = DOMUtil.getDocument();
    ItemPathType path = new ItemPathType("credentials/password/value");
    //		PropertyPath propPath = new PropertyPath(new PropertyPath(ResourceObjectShadowType.F_CREDENTIALS), CredentialsType.F_PASSWORD);
    propMod.setPath(path);
    //set the replace value
    MapXNode passPsXnode = ((PrismContextImpl) prismContext).getBeanMarshaller().marshalProtectedDataType(passPs, null);
    RawType value = new RawType(passPsXnode, prismContext);
    propMod.getValue().add(value);
    //set the modificaion type
    propMod.setModificationType(ModificationTypeType.REPLACE);
    PropertyDelta passDelta = (PropertyDelta) DeltaConvertor.createItemDelta(propMod, shadow.getDefinition());
    PropertyModificationOperation passwordModification = new PropertyModificationOperation(passDelta);
    changes.add(passwordModification);
    //		PasswordChangeOperation passwordChange = new PasswordChangeOperation(passPs);
    //		changes.add(passwordChange);
    cc.modifyObject(accountDefinition, identifiers, changes, null, result);
    // THEN
    entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry after change", entry);
    String passwordAfter = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull(passwordAfter);
    System.out.println("Account password: " + passwordAfter);
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Document(org.w3c.dom.Document) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Entry(org.opends.server.types.Entry) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) HashSet(java.util.HashSet)

Example 24 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method checkNoAssignmentConstruction.

private void checkNoAssignmentConstruction(UserType jack, String attributeName) {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    AssignmentType assignmentType = jack.getAssignment().get(0);
    ConstructionType constructionType = assignmentType.getConstruction();
    assertNotNull("construction is null", constructionType);
    for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) {
        if (attributeDefinitionType.getRef().equivalent(new ItemPathType(new ItemPath(new QName(attributeName))))) {
            fail("Construction attribute " + attributeName + " present, although it shouldn't");
        }
    }
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 25 with ItemPathType

use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.

the class TestUserChangeApprovalLegacy method modifyAssignmentConstruction.

protected void modifyAssignmentConstruction(LensContext<UserType> context, UserType jack, String attributeName, String value, boolean add) throws SchemaException {
    assertEquals("jack's assignments", 1, jack.getAssignment().size());
    PrismPropertyDefinition<ResourceAttributeDefinitionType> attributeDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findPropertyDefinition(new ItemPath(UserType.F_ASSIGNMENT, AssignmentType.F_CONSTRUCTION, ConstructionType.F_ATTRIBUTE));
    assertNotNull("no attributeDef", attributeDef);
    Long assignmentId = jack.getAssignment().get(0).getId();
    PropertyDelta<ResourceAttributeDefinitionType> attributeDelta = new PropertyDelta<ResourceAttributeDefinitionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(assignmentId), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION), new NameItemPathSegment(ConstructionType.F_ATTRIBUTE)), attributeDef, prismContext);
    ResourceAttributeDefinitionType attributeDefinitionType = new ResourceAttributeDefinitionType();
    attributeDefinitionType.setRef(new ItemPathType(new ItemPath(new QName(RESOURCE_DUMMY_NAMESPACE, attributeName))));
    MappingType outbound = new MappingType();
    // to see changes on the resource
    outbound.setStrength(MappingStrengthType.STRONG);
    ExpressionType expression = new ExpressionType();
    expression.getExpressionEvaluator().add(new ObjectFactory().createValue(value));
    outbound.setExpression(expression);
    attributeDefinitionType.setOutbound(outbound);
    if (add) {
        attributeDelta.addValueToAdd(new PrismPropertyValue<>(attributeDefinitionType));
    } else {
        attributeDelta.addValueToDelete(new PrismPropertyValue<>(attributeDefinitionType));
    }
    ObjectDelta<UserType> userDelta = new ObjectDelta<>(UserType.class, ChangeType.MODIFY, prismContext);
    userDelta.setOid(USER_JACK_OID);
    userDelta.addModification(attributeDelta);
    addFocusDeltaToContext(context, userDelta);
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)36 QName (javax.xml.namespace.QName)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)10 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 Test (org.testng.annotations.Test)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)6 List (java.util.List)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)3