Search in sources :

Example 41 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestPasswordPolicy method testPasswordGeneratorComplexNegative.

@Test
public void testPasswordGeneratorComplexNegative() throws Exception {
    final String TEST_NAME = "testPasswordGeneratorComplexNegative";
    TestUtil.displayTestTile(TEST_NAME);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    File file = new File(TEST_DIR, "password-policy-complex.xml");
    ValuePolicyType pp = (ValuePolicyType) PrismTestUtil.parseObject(file).asObjectable();
    // Make switch some cosistency
    pp.getStringPolicy().getLimitations().setMinLength(2);
    pp.getStringPolicy().getLimitations().setMinUniqueChars(5);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    String psswd = valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, null, TEST_NAME, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Generated password", psswd);
    result.computeStatus();
    AssertJUnit.assertTrue(result.isAcceptable());
    assertNotNull(psswd);
    // Switch to all must be first :-) to test if there is error
    for (StringLimitType l : pp.getStringPolicy().getLimitations().getLimit()) {
        l.setMustBeFirst(true);
    }
    LOGGER.info("Negative testing: passwordGeneratorComplexTest");
    try {
        valuePolicyProcessor.generate(SchemaConstants.PATH_PASSWORD_VALUE, pp.getStringPolicy(), 10, null, TEST_NAME, task, result);
        assertNotReached();
    } catch (ExpressionEvaluationException e) {
        result.computeStatus();
        TestUtil.assertFailure(result);
    }
}
Also used : StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 42 with ValuePolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType in project midpoint by Evolveum.

the class TestImportRecon method test330ReconcileDummyAzureAddAccountRapp.

/**
	 * Create account that will correlate to existing user.
	 * See that it is linked and modified.
	 */
@Test
public void test330ReconcileDummyAzureAddAccountRapp() throws Exception {
    final String TEST_NAME = "test330ReconcileDummyAzureAddAccountRapp";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestImportRecon.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    getDummyResource().setBreakMode(BreakMode.NONE);
    dummyResourceAzure.setBreakMode(BreakMode.NONE);
    dummyResourceCtlAzure.addAccount(USER_RAPP_USERNAME, USER_RAPP_FULLNAME);
    display("Rapp azure account before", dummyResourceAzure.getAccountByUsername(USER_RAPP_USERNAME));
    PrismObject<UserType> userRappBefore = getUser(USER_RAPP_OID);
    display("User rapp before", userRappBefore);
    PrismAsserts.assertPropertyValue(userRappBefore, UserType.F_ORGANIZATIONAL_UNIT, PrismTestUtil.createPolyString("The crew of The Elaine"));
    dummyResourceAzure.purgeScriptHistory();
    dummyAuditService.clear();
    reconciliationTaskResultListener.clear();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    restartTask(TASK_RECONCILE_DUMMY_AZURE_OID);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    waitForTaskFinish(TASK_RECONCILE_DUMMY_AZURE_OID, false);
    TestUtil.displayThen(TEST_NAME);
    List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
    display("Users after reconcile", users);
    reconciliationTaskResultListener.assertResult(RESOURCE_DUMMY_AZURE_OID, 0, 1, 0, 0);
    assertImportedUserByOid(USER_ADMINISTRATOR_OID);
    assertImportedUserByOid(USER_JACK_OID);
    assertImportedUserByOid(USER_BARBOSSA_OID);
    assertImportedUserByUsername(ACCOUNT_HERMAN_DUMMY_USERNAME);
    assertImportedUserByUsername(ACCOUNT_HTM_NAME, RESOURCE_DUMMY_OID);
    // Rapp
    display("Rapp azure account after", dummyResourceAzure.getAccountByUsername(USER_RAPP_USERNAME));
    assertImportedUserByOid(USER_RAPP_OID, RESOURCE_DUMMY_OID, RESOURCE_DUMMY_LIME_OID, RESOURCE_DUMMY_AZURE_OID);
    assertDummyAccount(RESOURCE_DUMMY_AZURE_NAME, USER_RAPP_USERNAME, USER_RAPP_FULLNAME, true);
    assertDummyAccountAttribute(RESOURCE_DUMMY_AZURE_NAME, USER_RAPP_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME, "The crew of The Elaine");
    //Checking password policy
    PrismObject<UserType> userRapp = findUserByUsername(USER_RAPP_USERNAME);
    assertNotNull("No user Rapp", userRapp);
    UserType userTypeRapp = userRapp.asObjectable();
    assertNotNull("User Rapp has no credentials", userTypeRapp.getCredentials());
    PasswordType password = userTypeRapp.getCredentials().getPassword();
    assertNotNull("User Rapp has no password", password);
    ProtectedStringType passwordType = password.getValue();
    String stringPassword = null;
    if (passwordType.getClearValue() == null) {
        stringPassword = protector.decryptString(passwordType);
    }
    assertNotNull("No clear text password", stringPassword);
    PrismObject<ValuePolicyType> passwordPolicy = getObjectViaRepo(ValuePolicyType.class, PASSWORD_POLICY_LOWER_CASE_ALPHA_AZURE_OID);
    boolean isPasswordValid = valuePolicyProcessor.validateValue(stringPassword, passwordPolicy.asObjectable(), userRapp, TEST_NAME, task, result);
    assertTrue("Password doesn't satisfy password policy, generated password: " + stringPassword, isPasswordValid);
    // These are protected accounts, they should not be imported
    assertNoImporterUserByUsername(ACCOUNT_DAVIEJONES_DUMMY_USERNAME);
    assertNoImporterUserByUsername(ACCOUNT_CALYPSO_DUMMY_USERNAME);
    // Calypso is protected account. Reconciliation should not touch it
    assertDummyAccountAttribute(null, ACCOUNT_CALYPSO_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Calypso");
    assertEquals("Unexpected number of users", 11, users.size());
    display("Dummy resource (azure)", dummyResourceAzure.debugDump());
    assertReconAuditModifications(1, TASK_RECONCILE_DUMMY_AZURE_OID);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PasswordType(com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType) PrismObject(com.evolveum.midpoint.prism.PrismObject) 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

ValuePolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)19 Test (org.testng.annotations.Test)14 Task (com.evolveum.midpoint.task.api.Task)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 File (java.io.File)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 StringPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 StringPolicyResolver (com.evolveum.midpoint.repo.common.expression.StringPolicyResolver)4 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)4 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3