Search in sources :

Example 76 with ObjectType

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

the class TestSanity method test016ProvisioningSearchAccountsIterative.

@Test
public void test016ProvisioningSearchAccountsIterative() throws Exception {
    TestUtil.displayTestTile("test016ProvisioningSearchAccountsIterative");
    // GIVEN
    OperationResult result = new OperationResult(TestSanity.class.getName() + ".test016ProvisioningSearchAccountsIterative");
    RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resourceTypeOpenDjrepo, prismContext);
    final RefinedObjectClassDefinition refinedAccountDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    QName objectClass = refinedAccountDefinition.getObjectClassDefinition().getTypeName();
    ObjectQuery q = ObjectQueryUtil.createResourceAndObjectClassQuery(resourceTypeOpenDjrepo.getOid(), objectClass, prismContext);
    //        ObjectQuery q = QueryConvertor.createObjectQuery(ResourceObjectShadowType.class, query, prismContext);
    final Collection<ObjectType> objects = new HashSet<ObjectType>();
    final MatchingRule caseIgnoreMatchingRule = matchingRuleRegistry.getMatchingRule(StringIgnoreCaseMatchingRule.NAME, DOMUtil.XSD_STRING);
    ResultHandler handler = new ResultHandler<ObjectType>() {

        @Override
        public boolean handle(PrismObject<ObjectType> prismObject, OperationResult parentResult) {
            ObjectType objectType = prismObject.asObjectable();
            objects.add(objectType);
            display("Found object", objectType);
            assertTrue(objectType instanceof ShadowType);
            ShadowType shadow = (ShadowType) objectType;
            assertNotNull(shadow.getOid());
            assertNotNull(shadow.getName());
            assertEquals(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS, shadow.getObjectClass());
            assertEquals(RESOURCE_OPENDJ_OID, shadow.getResourceRef().getOid());
            String icfUid = getAttributeValue(shadow, getOpenDjPrimaryIdentifierQName());
            assertNotNull("No ICF UID", icfUid);
            String icfName = getNormalizedAttributeValue(shadow, refinedAccountDefinition, getOpenDjSecondaryIdentifierQName());
            assertNotNull("No ICF NAME", icfName);
            try {
                PrismAsserts.assertEquals("Wrong shadow name", caseIgnoreMatchingRule, shadow.getName().getOrig(), icfName);
            } catch (SchemaException e) {
                throw new IllegalArgumentException(e.getMessage(), e);
            }
            assertNotNull("Missing LDAP uid", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "uid")));
            assertNotNull("Missing LDAP cn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "cn")));
            assertNotNull("Missing LDAP sn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "sn")));
            assertNotNull("Missing activation", shadow.getActivation());
            assertNotNull("Missing activation status", shadow.getActivation().getAdministrativeStatus());
            return true;
        }
    };
    // WHEN
    provisioningService.searchObjectsIterative(ShadowType.class, q, null, handler, null, result);
    // THEN
    display("Count", objects.size());
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) StringIgnoreCaseMatchingRule(com.evolveum.midpoint.prism.match.StringIgnoreCaseMatchingRule) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 77 with ObjectType

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

the class TestSanity method searchAccountByOid.

private ShadowType searchAccountByOid(final String accountOid) throws Exception {
    OperationResultType resultType = new OperationResultType();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>(resultType);
    Holder<ObjectType> accountHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountOid, options, accountHolder, resultHolder);
    ObjectType object = accountHolder.value;
    TestUtil.assertSuccess("searchObjects has failed", resultHolder.value);
    assertNotNull("Account is null", object);
    if (!(object instanceof ShadowType)) {
        fail("Object is not account.");
    }
    ShadowType account = (ShadowType) object;
    assertEquals(accountOid, account.getOid());
    return account;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(javax.xml.ws.Holder) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 78 with ObjectType

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

the class TestSanity method test030DisableUser.

/**
     * Try to disable user. As the user has an account, the account should be disabled as well.
     */
@Test
public void test030DisableUser() throws Exception {
    final String TEST_NAME = "test030DisableUser";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    ObjectDeltaType objectChange = unmarshallValueFromFile(REQUEST_USER_MODIFY_ACTIVATION_DISABLE_FILENAME, ObjectDeltaType.class);
    Entry entry = openDJController.searchByUid("jack");
    assertOpenDJAccountJack(entry, "jack");
    String pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled before change", pwpAccountDisabled);
    assertTrue("LDAP account is not enabled (precondition)", openDJController.isAccountEnabled(entry));
    assertNoRepoCache();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    OperationResultType result = modifyObjectViaModelWS(objectChange);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    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> repoUser = repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
    display("repository user", repoUser);
    UserType repoUserType = repoUser.asObjectable();
    // Check if nothing else was modified
    assertEqualsPolyString("wrong repo fullName", "Cpt. Jack Sparrow", repoUserType.getFullName());
    assertEqualsPolyString("wrong repo locality", "somewhere", repoUserType.getLocality());
    // Check if appropriate accountRef is still there
    List<ObjectReferenceType> accountRefs = repoUserType.getLinkRef();
    assertEquals(2, accountRefs.size());
    for (ObjectReferenceType accountRef : accountRefs) {
        assertTrue("No OID in " + accountRef + " in " + repoUserType, accountRef.getOid().equals(accountShadowOidOpendj) || accountRef.getOid().equals(accountShadowOidDerby));
    }
    // Check if shadow is still in the repo and that it is untouched
    repoResult = new OperationResult("getObject");
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
    display("repo shadow", repoShadow);
    ShadowType repoShadowType = repoShadow.asObjectable();
    repoResult.computeStatus();
    TestUtil.assertSuccess("getObject(repo) has failed", repoResult);
    AssertJUnit.assertNotNull(repoShadowType);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, repoShadowType.getResourceRef().getOid());
    // check attributes in the shadow: should be only identifiers (ICF UID)
    String uid = checkRepoShadow(repoShadow);
    // Check if LDAP account was updated
    entry = openDJController.searchAndAssertByEntryUuid(uid);
    assertOpenDJAccountJack(entry, "jack");
    pwpAccountDisabled = OpenDJController.getAttributeValue(entry, "ds-pwp-account-disabled");
    display("ds-pwp-account-disabled after change", pwpAccountDisabled);
    assertFalse("LDAP account was not disabled", openDJController.isAccountEnabled(entry));
    // Use getObject to test fetch of complete shadow
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    assertNoRepoCache();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modelWeb.getObject(ObjectTypes.SHADOW.getTypeQName(), accountShadowOidOpendj, options, objectHolder, resultHolder);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertNoRepoCache();
    displayJaxb("getObject result", resultHolder.value, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("getObject has failed", resultHolder.value);
    ShadowType modelShadow = (ShadowType) objectHolder.value;
    display("Shadow (model)", modelShadow);
    AssertJUnit.assertNotNull(modelShadow);
    AssertJUnit.assertEquals(RESOURCE_OPENDJ_OID, modelShadow.getResourceRef().getOid());
    assertAttributeNotNull(modelShadow, getOpenDjPrimaryIdentifierQName());
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "uid", "jack");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "givenName", "Jack");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "sn", "Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "cn", "Cpt. Jack Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "displayName", "Cpt. Jack Sparrow");
    assertAttribute(resourceTypeOpenDjrepo, modelShadow, "l", "somewhere");
    assertNotNull("The account activation is null in the shadow", modelShadow.getActivation());
    assertNotNull("The account activation status was not present in shadow", modelShadow.getActivation().getAdministrativeStatus());
    assertEquals("The account was not disabled in the shadow", ActivationStatusType.DISABLED, modelShadow.getActivation().getAdministrativeStatus());
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) Holder(javax.xml.ws.Holder) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GenericObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType) ChangeRecordEntry(org.opends.server.util.ChangeRecordEntry) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 79 with ObjectType

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

the class ModelClientUtil method getOidFromDeltaOperationList.

/**
     * Retrieves OID created by model Web Service from the returned list of ObjectDeltaOperations.
     *
     * @param operationListType result of the model web service executeChanges call
     * @param originalDelta original request used to find corresponding ObjectDeltaOperationType instance. Must be of ADD type.
     * @return OID if found
     *
     * PRELIMINARY IMPLEMENTATION. Currently the first returned ADD delta with the same object type as original delta is returned.
     */
public static String getOidFromDeltaOperationList(ObjectDeltaOperationListType operationListType, ObjectDeltaType originalDelta) {
    Validate.notNull(operationListType);
    Validate.notNull(originalDelta);
    if (originalDelta.getChangeType() != ChangeTypeType.ADD) {
        throw new IllegalArgumentException("Original delta is not of ADD type");
    }
    if (originalDelta.getObjectToAdd() == null) {
        throw new IllegalArgumentException("Original delta contains no object-to-be-added");
    }
    for (ObjectDeltaOperationType operationType : operationListType.getDeltaOperation()) {
        ObjectDeltaType objectDeltaType = operationType.getObjectDelta();
        if (objectDeltaType.getChangeType() == ChangeTypeType.ADD && objectDeltaType.getObjectToAdd() != null) {
            ObjectType objectAdded = (ObjectType) objectDeltaType.getObjectToAdd();
            if (objectAdded.getClass().equals(originalDelta.getObjectToAdd().getClass())) {
                return objectAdded.getOid();
            }
        }
    }
    return null;
}
Also used : ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)

Example 80 with ObjectType

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

the class TestAssignmentErrors method test210UserSharptoothAssignAccountBrokenGeneric.

// PARTIAL_ERROR: Unable to get object from the resource. Probably it has not been created yet because of previous unavailability of the resource.
// TODO: timeout or explicit retry
//	@Test
//    public void test205UserLemonheadRecovery() throws Exception {
//		final String TEST_NAME = "test205UserLemonheadRecovery";
//        TestUtil.displayTestTile(this, TEST_NAME);
//
//        // GIVEN
//        Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
//        OperationResult result = task.getResult();
//        assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
//                
//        dummyResource.setBreakMode(BreakMode.NONE);
//        dummyAuditService.clear();
//                
//		// WHEN
//		//not expected that it fails, instead the error in the result is expected
//        modelService.recompute(UserType.class, userLemonheadOid, task, result);
//        
//        result.computeStatus();
//        
//        display(result);
//        // This has to be a partial error as some changes were executed (user) and others were not (account)
//        TestUtil.assertSuccess(result);
//        
//        // Check audit
//        display("Audit", dummyAuditService);
//        dummyAuditService.assertSimpleRecordSanity();
//        dummyAuditService.assertRecords(2);
//        dummyAuditService.assertAnyRequestDeltas();
//        dummyAuditService.assertTarget(userLemonheadOid);
//        dummyAuditService.assertExecutionOutcome(OperationResultStatus.HANDLED_ERROR);
//        dummyAuditService.assertExecutionMessage();
//		
//	}
@Test
public void test210UserSharptoothAssignAccountBrokenGeneric() throws Exception {
    final String TEST_NAME = "test210UserSharptoothAssignAccountBrokenGeneric";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    PrismObject<UserType> user = createUser(USER_SHARPTOOTH_NAME, USER_SHARPTOOTH_FULLNAME);
    CredentialsType credentialsType = new CredentialsType();
    PasswordType passwordType = new PasswordType();
    ProtectedStringType passwordPs = new ProtectedStringType();
    passwordPs.setClearValue(USER_SHARPTOOTH_PASSWORD_1_CLEAR);
    passwordType.setValue(passwordPs);
    credentialsType.setPassword(passwordType);
    user.asObjectable().setCredentials(credentialsType);
    addObject(user);
    userSharptoothOid = user.getOid();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(user.getOid(), RESOURCE_DUMMY_OID, null, true);
    deltas.add(accountAssignmentUserDelta);
    getDummyResource().setBreakMode(BreakMode.GENERIC);
    dummyAuditService.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    //not expected that it fails, instead the error in the result is expected
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display(result);
    // This has to be a partial error as some changes were executed (user) and others were not (account)
    TestUtil.assertPartialError(result);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.ADD, ShadowType.class, OperationResultStatus.FATAL_ERROR);
    dummyAuditService.assertTarget(user.getOid());
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.PARTIAL_ERROR);
    dummyAuditService.assertExecutionMessage();
    LensContext<UserType> lastLensContext = lensDebugListener.getLastLensContext();
    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = lastLensContext.getExecutedDeltas();
    display("Executed deltas", executedDeltas);
    assertEquals("Unexpected number of execution deltas in context", 2, executedDeltas.size());
    Iterator<ObjectDeltaOperation<? extends ObjectType>> i = executedDeltas.iterator();
    ObjectDeltaOperation<? extends ObjectType> deltaop1 = i.next();
    assertEquals("Unexpected result of first executed deltas", OperationResultStatus.SUCCESS, deltaop1.getExecutionResult().getStatus());
    ObjectDeltaOperation<? extends ObjectType> deltaop2 = i.next();
    assertEquals("Unexpected result of second executed deltas", OperationResultStatus.FATAL_ERROR, deltaop2.getExecutionResult().getStatus());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)371 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)297 Test (org.testng.annotations.Test)264 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)253 Task (com.evolveum.midpoint.task.api.Task)252 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)223 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)155 ArrayList (java.util.ArrayList)123 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)100 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)58 Holder (javax.xml.ws.Holder)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)46 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)46 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)38 QName (javax.xml.namespace.QName)38 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)37 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)33 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)33 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32