Search in sources :

Example 41 with ProtectedStringType

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

the class TestSanityLegacy method test023ChangeUserPasswordJAXB.

/**
     * Similar to previous test just the request is constructed a bit differently.
     */
@Test
public void test023ChangeUserPasswordJAXB() throws Exception {
    final String TEST_NAME = "test023ChangeUserPasswordJAXB";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    final String NEW_PASSWORD = "abandonSHIP";
    Document doc = ModelClientUtil.getDocumnent();
    ObjectDeltaType userDelta = new ObjectDeltaType();
    userDelta.setOid(USER_JACK_OID);
    userDelta.setChangeType(ChangeTypeType.MODIFY);
    userDelta.setObjectType(UserType.COMPLEX_TYPE);
    ItemDeltaType passwordDelta = new ItemDeltaType();
    passwordDelta.setModificationType(ModificationTypeType.REPLACE);
    passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
    ProtectedStringType pass = new ProtectedStringType();
    pass.setClearValue(NEW_PASSWORD);
    XNode passValue = ((PrismContextImpl) prismContext).getBeanMarshaller().marshall(pass);
    System.out.println("PASSWORD VALUE: " + passValue.debugDump());
    RawType passwordValue = new RawType(passValue, prismContext);
    passwordDelta.getValue().add(passwordValue);
    userDelta.getItemDelta().add(passwordDelta);
    // WHEN ObjectTypes.USER.getTypeQName(), 
    OperationResultType result = modifyObjectViaModelWS(userDelta);
    // THEN
    assertUserPasswordChange(NEW_PASSWORD, result);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) PrismAsserts.assertEqualsPolyString(com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Document(org.w3c.dom.Document) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 42 with ProtectedStringType

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

the class TestSanity method checkOpenResourceConfiguration.

private void checkOpenResourceConfiguration(PrismObject<ResourceType> resource, String connectorNamespace, String credentialsPropertyName, int numConfigProps, String source) {
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertNotNull("No configuration container in " + resource + " from " + source, configurationContainer);
    PrismContainer<Containerable> configPropsContainer = configurationContainer.findContainer(SchemaTestConstants.ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No configuration properties container in " + resource + " from " + source, configPropsContainer);
    List<? extends Item<?, ?>> configProps = configPropsContainer.getValue().getItems();
    assertEquals("Wrong number of config properties in " + resource + " from " + source, numConfigProps, configProps.size());
    PrismProperty<Object> credentialsProp = configPropsContainer.findProperty(new QName(connectorNamespace, credentialsPropertyName));
    if (credentialsProp == null) {
        // The is the heisenbug we are looking for. Just dump the entire damn thing.
        display("Configuration with the heisenbug", configurationContainer.debugDump());
    }
    assertNotNull("No " + credentialsPropertyName + " property in " + resource + " from " + source, credentialsProp);
    assertEquals("Wrong number of " + credentialsPropertyName + " property value in " + resource + " from " + source, 1, credentialsProp.getValues().size());
    PrismPropertyValue<Object> credentialsPropertyValue = credentialsProp.getValues().iterator().next();
    assertNotNull("No " + credentialsPropertyName + " property value in " + resource + " from " + source, credentialsPropertyValue);
    if (credentialsPropertyValue.isRaw()) {
        Object rawElement = credentialsPropertyValue.getRawElement();
        assertTrue("Wrong element class " + rawElement.getClass() + " in " + resource + " from " + source, rawElement instanceof MapXNode);
        //			Element rawDomElement = (Element)rawElement;
        MapXNode xmap = (MapXNode) rawElement;
        try {
            ProtectedStringType protectedType = new ProtectedStringType();
            XNodeProcessorUtil.parseProtectedType(protectedType, xmap, prismContext);
            //		display("LDAP credentials raw element", DOMUtil.serializeDOMToString(rawDomElement));
            //			assertEquals("Wrong credentials element namespace in "+resource+" from "+source, connectorNamespace, rawDomElement.getNamespaceURI());
            //			assertEquals("Wrong credentials element local name in "+resource+" from "+source, credentialsPropertyName, rawDomElement.getLocalName());
            //			Element encryptedDataElement = DOMUtil.getChildElement(rawDomElement, new QName(DOMUtil.NS_XML_ENC, "EncryptedData"));
            EncryptedDataType encryptedDataType = protectedType.getEncryptedDataType();
            assertNotNull("No EncryptedData element", encryptedDataType);
        } catch (SchemaException ex) {
            throw new IllegalArgumentException(ex);
        }
    //			assertEquals("Wrong EncryptedData element namespace in "+resource+" from "+source, DOMUtil.NS_XML_ENC, encryptedDataType.getNamespaceURI());
    //			assertEquals("Wrong EncryptedData element local name in "+resource+" from "+source, "EncryptedData", encryptedDataType.getLocalName());
    } else {
        Object credentials = credentialsPropertyValue.getValue();
        assertTrue("Wrong type of credentials configuration property in " + resource + " from " + source + ": " + credentials.getClass(), credentials instanceof ProtectedStringType);
        ProtectedStringType credentialsPs = (ProtectedStringType) credentials;
        EncryptedDataType encryptedData = credentialsPs.getEncryptedDataType();
        assertNotNull("No EncryptedData element", encryptedData);
    }
}
Also used : EncryptedDataType(com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType) QName(javax.xml.namespace.QName) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 43 with ProtectedStringType

use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType 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)

Example 44 with ProtectedStringType

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

the class AbstractModelIntegrationTest method assertUserLdapPassword.

protected void assertUserLdapPassword(PrismObject<UserType> user, String expectedPassword) throws EncryptionException {
    CredentialsType credentialsType = user.asObjectable().getCredentials();
    assertNotNull("No credentials in " + user, credentialsType);
    PasswordType passwordType = credentialsType.getPassword();
    assertNotNull("No password in " + user, passwordType);
    ProtectedStringType protectedStringType = passwordType.getValue();
    assertLdapPassword(protectedStringType, expectedPassword, user);
}
Also used : CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 45 with ProtectedStringType

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

the class AbstractModelIntegrationTest method assertPassword.

protected void assertPassword(PrismObject<UserType> user, String expectedPassword) throws EncryptionException {
    CredentialsType credentialsType = user.asObjectable().getCredentials();
    assertNotNull("No credentials in " + user, credentialsType);
    PasswordType passwordType = credentialsType.getPassword();
    assertNotNull("No password in " + user, passwordType);
    ProtectedStringType protectedStringType = passwordType.getValue();
    assertNotNull("No password value in " + user, protectedStringType);
    String decryptedUserPassword = protector.decryptString(protectedStringType);
    assertEquals("Wrong password in " + user, expectedPassword, decryptedUserPassword);
}
Also used : CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Aggregations

ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)120 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 Test (org.testng.annotations.Test)48 Task (com.evolveum.midpoint.task.api.Task)39 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 QName (javax.xml.namespace.QName)20 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)18 PasswordType (com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType)18 CredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)11 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)9 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)9 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)9 Document (org.w3c.dom.Document)8 ArrayList (java.util.ArrayList)7 Entry (org.apache.directory.api.ldap.model.entry.Entry)7