use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestUserChangeApprovalLegacy method test040UserModifyPasswordChangeBlocked.
@Test(enabled = true)
public void test040UserModifyPasswordChangeBlocked() throws Exception {
TestUtil.displayTestTile(this, "test040UserModifyPasswordChangeBlocked");
login(userAdministrator);
PrismObject<UserType> jack = getUser(USER_JACK_OID);
final ProtectedStringType originalPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password before test = " + originalPasswordValue);
executeTest("test040UserModifyPasswordChangeBlocked", USER_JACK_OID, new TestDetails() {
@Override
int subtaskCount() {
return 1;
}
@Override
boolean immediate() {
return false;
}
@Override
boolean checkObjectOnSubtasks() {
return true;
}
@Override
public LensContext createModelContext(Task task, OperationResult result) throws Exception {
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
encryptAndAddFocusModificationToContext(context, REQ_USER_JACK_MODIFY_CHANGE_PASSWORD);
//context.setOptions(ModelExecuteOptions.createNoCrypt());
return context;
}
@Override
public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception {
ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result);
assertEquals("There are modifications left in primary focus delta", 0, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size());
}
@Override
void assertsRootTaskFinishes(Task task, List<Task> subtasks, OperationResult result) throws Exception {
PrismObject<UserType> jack = getUser(USER_JACK_OID);
ProtectedStringType afterTestPasswordValue = jack.asObjectable().getCredentials().getPassword().getValue();
LOGGER.trace("password after test = " + afterTestPasswordValue);
//assertNotNull("password was not set", afterTestPasswordValue.getEncryptedData());
assertTrue("password was changed", originalPasswordValue.getEncryptedDataType().equals(afterTestPasswordValue.getEncryptedDataType()));
checkDummyTransportMessages("simpleUserNotifier", 0);
// we don't check for modifyApproverRef because in this test the value was not changed (no change was executed)
}
@Override
boolean decideOnApproval(String executionId) throws Exception {
login(getUser(USER_ADMINISTRATOR_OID));
return false;
}
});
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestDBTable method test005GetAccount.
// MID-1234
@Test(enabled = false)
public void test005GetAccount() throws Exception {
final String TEST_NAME = "test005GetAccount";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult result = new OperationResult(TestDBTable.class.getName() + "." + TEST_NAME);
Task task = taskManager.createTaskInstance();
// WHEN
PrismObject<ShadowType> account = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result);
// THEN
result.computeStatus();
display(result);
TestUtil.assertSuccess(result);
PrismAsserts.assertEqualsPolyString("Name not equal.", ACCOUNT_WILL_USERNAME, account.asObjectable().getName());
assertNotNull("No credentials", account.asObjectable().getCredentials());
assertNotNull("No password", account.asObjectable().getCredentials().getPassword());
assertNotNull("No password value", account.asObjectable().getCredentials().getPassword().getValue());
ProtectedStringType password = account.asObjectable().getCredentials().getPassword().getValue();
display("Password", password);
String clearPassword = protector.decryptString(password);
assertEquals("Wrong password", ACCOUNT_WILL_PASSWORD, clearPassword);
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestProtector method testProtectorHashRoundTrip.
@Test
public void testProtectorHashRoundTrip() throws Exception {
String value = "someValue";
ProtectedStringType pst = new ProtectedStringType();
pst.setClearValue(value);
assertFalse(pst.isEmpty());
Protector protector256 = PrismInternalTestUtil.createProtector(XMLCipher.AES_256);
// WHEN
protector256.hash(pst);
// THEN
assertFalse(pst.isEmpty());
assertTrue(pst.isHashed());
assertFalse(pst.isEncrypted());
assertNull(pst.getClearValue());
ProtectedStringType checkPstClear = new ProtectedStringType();
checkPstClear.setClearValue(value);
// WHEN
boolean compare1 = protector256.compare(pst, checkPstClear);
// THEN
assertTrue("compare1 failed", compare1);
// WHEN
boolean compare2 = protector256.compare(checkPstClear, pst);
// THEN
assertTrue("compare2 failed", compare2);
ProtectedStringType checkPstEnc = new ProtectedStringType();
checkPstEnc.setClearValue(value);
protector256.encrypt(checkPstEnc);
// WHEN
boolean compare3 = protector256.compare(pst, checkPstEnc);
// THEN
assertTrue("compare3 failed", compare3);
// WHEN
boolean compare4 = protector256.compare(checkPstEnc, pst);
// THEN
assertTrue("compare4 failed", compare4);
ProtectedStringType wrongPst = new ProtectedStringType();
wrongPst.setClearValue("nonono This is not it");
// WHEN
boolean compare5 = protector256.compare(pst, wrongPst);
// THEN
assertFalse("compare5 unexpected success", compare5);
// WHEN
boolean compare6 = protector256.compare(wrongPst, pst);
// THEN
assertFalse("compare6 unexpected success", compare6);
ProtectedStringType wrongPstEnc = new ProtectedStringType();
wrongPstEnc.setClearValue("nonono This is not it");
protector256.encrypt(wrongPstEnc);
// WHEN
boolean compare7 = protector256.compare(pst, wrongPstEnc);
// THEN
assertFalse("compare7 unexpected success", compare7);
// WHEN
boolean compare8 = protector256.compare(wrongPstEnc, pst);
// THEN
assertFalse("compare8 unexpected success", compare8);
// change the hash ... comparison should fail
pst.getHashedDataType().getDigestValue()[1] = 0x12;
// WHEN
boolean compare9 = protector256.compare(pst, checkPstClear);
// THEN
assertFalse("compare9 unexpected success", compare9);
// WHEN
boolean compare10 = protector256.compare(checkPstClear, pst);
// THEN
assertFalse("compare10 unexpected success", compare10);
ProtectedStringType pstEncHash = new ProtectedStringType();
pstEncHash.setClearValue(value);
assertFalse(pstEncHash.isEmpty());
protector256.encrypt(pstEncHash);
// WHEN
protector256.hash(pstEncHash);
// THEN
assertFalse(pstEncHash.isEmpty());
assertTrue(pstEncHash.isHashed());
assertFalse(pstEncHash.isEncrypted());
assertNull(pstEncHash.getClearValue());
// WHEN
boolean compare1e = protector256.compare(checkPstClear, pstEncHash);
// THEN
assertTrue("compare1e failed", compare1e);
// WHEN
boolean compare2e = protector256.compare(pstEncHash, checkPstClear);
// THEN
assertTrue("compare2e failed", compare2e);
// WHEN
boolean compare3e = protector256.compare(pstEncHash, checkPstEnc);
// THEN
assertTrue("compare3e failed", compare3e);
// WHEN
boolean compare4e = protector256.compare(checkPstEnc, pstEncHash);
// THEN
assertTrue("compare4e failed", compare4e);
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestEditSchema method test800OtisEditSchemaUser.
/**
* Login as Otis. Otis has a restricted authorizations. Check that schema is presented accordingly to
* these limitations.
*/
@Test
public void test800OtisEditSchemaUser() throws Exception {
final String TEST_NAME = "test800OtisEditSchemaUser";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
login(USER_OTIS_USERNAME);
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PrismObject<UserType> user = userDef.instantiate();
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObjectDefinition<UserType> editDef = getEditObjectDefinition(user);
IntegrationTestTools.display("Otis edit schema", editDef);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismPropertyDefinition<PolyString> nameDef = editDef.findPropertyDefinition(UserType.F_NAME);
assertNotNull("No definition for name in user", nameDef);
assertEquals("Wrong name displayName", "ObjectType.name", nameDef.getDisplayName());
assertTrue("name not readable", nameDef.canRead());
assertTrue("name is creatable", !nameDef.canAdd());
assertTrue("name is modifiable", !nameDef.canModify());
PrismPropertyDefinition<PolyString> additionalNameDef = editDef.findPropertyDefinition(UserType.F_ADDITIONAL_NAME);
assertNotNull("No definition for additionalName in user", additionalNameDef);
assertEquals("Wrong additionalName displayName", "Middle Name", additionalNameDef.getDisplayName());
assertTrue("additionalName is readable", !additionalNameDef.canRead());
assertTrue("additionalName is creatable", !additionalNameDef.canAdd());
assertTrue("additionalName not modifiable", additionalNameDef.canModify());
PrismPropertyDefinition<String> costCenterDef = editDef.findPropertyDefinition(UserType.F_COST_CENTER);
assertNotNull("No definition for costCenter in user", costCenterDef);
assertEquals("Wrong costCenter displayOrder", (Integer) 123, costCenterDef.getDisplayOrder());
assertTrue("costCenter is readable", !costCenterDef.canRead());
assertTrue("costCenter is creatable", !costCenterDef.canAdd());
assertTrue("costCenter is modifiable", !costCenterDef.canModify());
PrismPropertyDefinition<String> preferredLanguageDef = editDef.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
assertNotNull("No definition for preferredLanguage in user", preferredLanguageDef);
assertEquals("Wrong preferredLanguage displayName", "Language", preferredLanguageDef.getDisplayName());
PrismReferenceValue valueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
assertTrue("preferredLanguage is readable", !preferredLanguageDef.canRead());
assertTrue("preferredLanguage is creatable", !preferredLanguageDef.canAdd());
assertTrue("preferredLanguage is modifiable", !preferredLanguageDef.canModify());
PrismContainerDefinition<CredentialsType> credentialsDef = editDef.findContainerDefinition(UserType.F_CREDENTIALS);
assertNotNull("No definition for credentials in user", credentialsDef);
assertTrue("Credentials is readable", !credentialsDef.canRead());
assertTrue("Credentials is creatable", !credentialsDef.canAdd());
assertTrue("Credentials is modifiable", !credentialsDef.canModify());
ItemPath passwdValPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
PrismPropertyDefinition<ProtectedStringType> passwdValDef = editDef.findPropertyDefinition(passwdValPath);
assertNotNull("No definition for " + passwdValPath + " in user", passwdValDef);
assertTrue("Password is readable", !passwdValDef.canRead());
assertTrue("Password is creatable", !passwdValDef.canAdd());
assertTrue("Password is modifiable", !passwdValDef.canModify());
assertUntouchedUserDefinition();
assertSteadyResources();
}
use of com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType in project midpoint by Evolveum.
the class TestEditSchema method test200EditSchemaUser.
@Test
public void test200EditSchemaUser() throws Exception {
final String TEST_NAME = "test200EditSchemaUser";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestEditSchema.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
PrismObject<UserType> user = userDef.instantiate();
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObjectDefinition<UserType> editDef = getEditObjectDefinition(user);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismAsserts.assertEmphasized(editDef, UserType.F_NAME, true);
PrismAsserts.assertEmphasized(editDef, UserType.F_GIVEN_NAME, false);
PrismAsserts.assertEmphasized(editDef, UserType.F_FAMILY_NAME, true);
PrismAsserts.assertEmphasized(editDef, UserType.F_FULL_NAME, true);
PrismAsserts.assertEmphasized(editDef, UserType.F_DESCRIPTION, false);
PrismPropertyDefinition<PolyString> additionalNameDef = editDef.findPropertyDefinition(UserType.F_ADDITIONAL_NAME);
assertNotNull("No definition for additionalName in user", additionalNameDef);
assertEquals("Wrong additionalName displayName", "Middle Name", additionalNameDef.getDisplayName());
assertTrue("additionalName not readable", additionalNameDef.canRead());
PrismAsserts.assertEmphasized(additionalNameDef, false);
PrismPropertyDefinition<String> costCenterDef = editDef.findPropertyDefinition(UserType.F_COST_CENTER);
assertNotNull("No definition for costCenter in user", costCenterDef);
assertEquals("Wrong costCenter displayOrder", (Integer) 123, costCenterDef.getDisplayOrder());
assertTrue("costCenter not readable", costCenterDef.canRead());
PrismAsserts.assertEmphasized(costCenterDef, true);
// This has overridden lookup def in object template
PrismPropertyDefinition<String> preferredLanguageDef = editDef.findPropertyDefinition(UserType.F_PREFERRED_LANGUAGE);
assertNotNull("No definition for preferredLanguage in user", preferredLanguageDef);
assertEquals("Wrong preferredLanguage displayName", "Language", preferredLanguageDef.getDisplayName());
assertTrue("preferredLanguage not readable", preferredLanguageDef.canRead());
PrismReferenceValue valueEnumerationRef = preferredLanguageDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for preferredLanguage", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for preferredLanguage", LOOKUP_LANGUAGES_OID, valueEnumerationRef.getOid());
// This has default lookup def in schema
PrismPropertyDefinition<String> timezoneDef = editDef.findPropertyDefinition(UserType.F_TIMEZONE);
assertNotNull("No definition for timezone in user", timezoneDef);
assertEquals("Wrong timezone displayName", "UserType.timezone", timezoneDef.getDisplayName());
assertTrue("timezone not readable", timezoneDef.canRead());
valueEnumerationRef = timezoneDef.getValueEnumerationRef();
assertNotNull("No valueEnumerationRef for timezone", valueEnumerationRef);
assertEquals("Wrong valueEnumerationRef OID for timezone", SystemObjectsType.LOOKUP_TIMEZONES.value(), valueEnumerationRef.getOid());
PrismContainerDefinition<CredentialsType> credentialsDef = editDef.findContainerDefinition(UserType.F_CREDENTIALS);
assertNotNull("No definition for credentials in user", credentialsDef);
assertTrue("Credentials not readable", credentialsDef.canRead());
ItemPath passwdValPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
PrismPropertyDefinition<ProtectedStringType> passwdValDef = editDef.findPropertyDefinition(passwdValPath);
assertNotNull("No definition for " + passwdValPath + " in user", passwdValDef);
assertTrue("Password not readable", passwdValDef.canRead());
assertSteadyResources();
}
Aggregations