use of com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType in project midpoint by Evolveum.
the class ObjectValuePolicyEvaluator method getSortedHistoryList.
private List<PasswordHistoryEntryType> getSortedHistoryList(PrismContainer<PasswordHistoryEntryType> historyEntries, boolean ascending) {
if (historyEntries == null || historyEntries.isEmpty()) {
return new ArrayList<>();
}
List<PasswordHistoryEntryType> historyEntryValues = (List<PasswordHistoryEntryType>) historyEntries.getRealValues();
Collections.sort(historyEntryValues, (o1, o2) -> {
XMLGregorianCalendar changeTimestampFirst = o1.getChangeTimestamp();
XMLGregorianCalendar changeTimestampSecond = o2.getChangeTimestamp();
if (ascending) {
return changeTimestampFirst.compare(changeTimestampSecond);
} else {
return changeTimestampSecond.compare(changeTimestampFirst);
}
});
return historyEntryValues;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType in project midpoint by Evolveum.
the class TestPasswordPolicyProcessor method test203modifyUserJackPasswordNoPasswordHistory.
@Test
public void test203modifyUserJackPasswordNoPasswordHistory() throws Exception {
final String TEST_NAME = "test203modifyUserJackPasswordNoPasswordHistory";
TestUtil.displayTestTile(TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
OperationResult result = task.getResult();
// WHEN
ProtectedStringType newValue = new ProtectedStringType();
newValue.setClearValue("n0Hist0ryEntr7");
modifyObjectReplaceProperty(UserType.class, USER_JACK_OID, new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), task, result, newValue);
// THEN
PrismObject<UserType> userJack = getObject(UserType.class, USER_JACK_OID);
assertNotNull("Expected to find user Jack, but no one exists here", userJack);
UserType userJackType = userJack.asObjectable();
CredentialsType credentials = userJackType.getCredentials();
assertNotNull("User Jack has no credentials", credentials);
PasswordType password = credentials.getPassword();
assertNotNull("User Jack has no password", password);
List<PasswordHistoryEntryType> historyEntries = password.getHistoryEntry();
assertEquals("Expected no history entries, but found: " + historyEntries.size(), 0, historyEntries.size());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType in project midpoint by Evolveum.
the class ObjectValuePolicyEvaluator method validateHistory.
private void validateHistory(String clearValue, StringBuilder messageBuilder, OperationResult result) throws SchemaException {
if (!QNameUtil.match(CredentialsType.F_PASSWORD, credentialQName)) {
LOGGER.trace("Skipping validating {} history, only passowrd history is supported", shortDesc);
return;
}
int historyLegth = getHistoryLength();
if (historyLegth == 0) {
LOGGER.trace("Skipping validating {} history, because history length is set to zero", shortDesc);
return;
}
PasswordType currentPasswordType = (PasswordType) oldCredentialType;
if (currentPasswordType == null) {
LOGGER.trace("Skipping validating {} history, because it is empty", shortDesc);
return;
}
ProtectedStringType newPasswordPs = new ProtectedStringType();
newPasswordPs.setClearValue(clearValue);
if (passwordEquals(newPasswordPs, currentPasswordType.getValue())) {
LOGGER.trace("{} matched current value", shortDesc);
appendHistoryViolationMessage(messageBuilder, result);
return;
}
List<PasswordHistoryEntryType> sortedHistoryList = getSortedHistoryList(currentPasswordType.asPrismContainerValue().findContainer(PasswordType.F_HISTORY_ENTRY), false);
int i = 1;
for (PasswordHistoryEntryType historyEntry : sortedHistoryList) {
if (i >= historyLegth) {
// success (history has more entries than needed)
return;
}
if (passwordEquals(newPasswordPs, historyEntry.getValue())) {
LOGGER.trace("Password history entry #{} matched (changed {})", i, historyEntry.getChangeTimestamp());
appendHistoryViolationMessage(messageBuilder, result);
return;
}
i++;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType in project midpoint by Evolveum.
the class CredentialPolicyEvaluator method createDeleteHistoryDeltasIfNeeded.
// TODO: generalize for other credentials
private <F extends FocusType> void createDeleteHistoryDeltasIfNeeded(int historyLength, int addedValues, PrismContainer<R> currentCredentialContainer) throws SchemaException {
PrismContainer<PasswordHistoryEntryType> historyEntries = currentCredentialContainer.findOrCreateContainer(PasswordType.F_HISTORY_ENTRY);
List<PrismContainerValue<PasswordHistoryEntryType>> historyEntryValues = historyEntries.getValues();
if (historyEntries.size() == 0) {
return;
}
// We need to delete one more entry than intuitively expected - because we are computing from the history entries
// in the old object. In the new object there will be one new history entry for the changed password.
int numberOfHistoryEntriesToDelete = historyEntries.size() - historyLength + addedValues + 1;
for (int i = 0; i < numberOfHistoryEntriesToDelete; i++) {
ContainerDelta<PasswordHistoryEntryType> deleteHistoryDelta = ContainerDelta.createModificationDelete(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_HISTORY_ENTRY), UserType.class, prismContext, historyEntryValues.get(i).clone());
context.getFocusContext().swallowToSecondaryDelta(deleteHistoryDelta);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordHistoryEntryType in project midpoint by Evolveum.
the class CredentialPolicyEvaluator method createAddHistoryDelta.
// TODO: generalize for other credentials
private <F extends FocusType> int createAddHistoryDelta(PrismContainer<R> oldCredentialContainer) throws SchemaException {
R oldCredentialContainerType = oldCredentialContainer.getValue().asContainerable();
MetadataType oldCredentialMetadata = oldCredentialContainerType.getMetadata();
PrismProperty<ProtectedStringType> oldValueProperty = oldCredentialContainer.findProperty(getCredentialRelativeValuePath());
if (oldValueProperty == null) {
return 0;
}
ProtectedStringType newHistoryValue = oldValueProperty.getRealValue();
ProtectedStringType passwordPsForStorage = newHistoryValue.clone();
CredentialsStorageTypeType storageType = SecurityUtil.getCredentialStoragetTypeType(getCredentialPolicy().getHistoryStorageMethod());
if (storageType == null) {
storageType = CredentialsStorageTypeType.HASHING;
}
prepareProtectedStringForStorage(passwordPsForStorage, storageType);
PrismContainerDefinition<PasswordHistoryEntryType> historyEntryDefinition = oldCredentialContainer.getDefinition().findContainerDefinition(PasswordType.F_HISTORY_ENTRY);
PrismContainer<PasswordHistoryEntryType> historyEntry = historyEntryDefinition.instantiate();
PrismContainerValue<PasswordHistoryEntryType> hisotryEntryValue = historyEntry.createNewValue();
PasswordHistoryEntryType entryType = hisotryEntryValue.asContainerable();
entryType.setValue(passwordPsForStorage);
entryType.setMetadata(oldCredentialMetadata == null ? null : oldCredentialMetadata.clone());
entryType.setChangeTimestamp(now);
ContainerDelta<PasswordHistoryEntryType> addHisotryDelta = ContainerDelta.createModificationAdd(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_HISTORY_ENTRY), UserType.class, prismContext, entryType.clone());
context.getFocusContext().swallowToSecondaryDelta(addHisotryDelta);
return 1;
}
Aggregations