use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto in project CzechIdMng by bcvsolutions.
the class AbstractPasswordFilterIntegrationTest method checkChangeInIdm.
protected void checkChangeInIdm(IdmIdentityDto identity, int count) {
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identity.getId());
List<IdmPasswordHistoryDto> histories = passwordHistoryService.find(filter, null).getContent();
assertEquals(count, histories.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordHistoryService method checkHistory.
@Override
public boolean checkHistory(UUID identityId, int countOfIteration, GuardedString newPassword) {
Assert.notNull(identityId, "Identity id can't be null.");
Assert.notNull(newPassword, "New password can't be null.");
//
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
//
for (IdmPasswordHistoryDto passwordHistory : getPasswordHistoryForIdentity(identityId, countOfIteration)) {
boolean matches = encoder.matches(newPassword.asString(), passwordHistory.getPassword());
if (matches) {
return true;
}
}
return false;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordService method createPasswordHistory.
/**
* Create new password history. This is done after success password change in IdM.
*
* @param passwordDto
*/
private void createPasswordHistory(IdmPasswordDto passwordDto) {
IdmPasswordHistoryDto passwordHistory = new IdmPasswordHistoryDto();
passwordHistory.setIdentity(passwordDto.getIdentity());
passwordHistory.setPassword(passwordDto.getPassword());
passwordHistoryService.save(passwordHistory);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testFilteringByValidTill.
@Test
public void testFilteringByValidTill() {
String password = "password-" + System.currentTimeMillis();
GuardedString passwordAsGuardedString = new GuardedString(password);
// Change 1
IdmIdentityDto identity = testHelper.createIdentity(passwordAsGuardedString);
ZonedDateTime tillOne = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setOldPassword(passwordAsGuardedString);
passwordChange.setAll(true);
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
// Change 2
identityService.passwordChange(identity, passwordChange);
getHelper().waitForResult(null, 1, 1);
ZonedDateTime tillTwo = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
// Change 3
identityService.passwordChange(identity, passwordChange);
getHelper().waitForResult(null, 1, 1);
ZonedDateTime tillThree = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
// Change 4
identityService.passwordChange(identity, passwordChange);
getHelper().waitForResult(null, 1, 1);
ZonedDateTime tillFour = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identity.getId());
filter.setTill(tillOne);
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(filter, null).getContent();
assertEquals(1, content.size());
filter.setTill(tillTwo);
content = passwordHistoryService.find(filter, null).getContent();
assertEquals(2, content.size());
filter.setTill(tillThree);
content = passwordHistoryService.find(filter, null).getContent();
assertEquals(3, content.size());
filter.setTill(tillFour);
content = passwordHistoryService.find(filter, null).getContent();
assertEquals(4, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testCreateNewPasswordHistoryRecord.
@Test
public void testCreateNewPasswordHistoryRecord() {
String password = "test-password-" + System.currentTimeMillis();
String originalPassword = "test-password-" + System.currentTimeMillis();
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(null).getContent();
int beforeSize = content.size();
IdmIdentityDto newIdentity = testHelper.createIdentity(new GuardedString(originalPassword));
IdmIdentityDto newIdentity2 = testHelper.createIdentity(new GuardedString(originalPassword));
content = passwordHistoryService.find(null).getContent();
// after create identity is create only one password history record
assertEquals(beforeSize + 2, content.size());
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
identityService.passwordChange(newIdentity, passwordChange);
content = passwordHistoryService.find(null).getContent();
assertEquals(beforeSize + 3, content.size());
passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
identityService.passwordChange(newIdentity2, passwordChange);
content = passwordHistoryService.find(null).getContent();
assertEquals(beforeSize + 4, content.size());
}
Aggregations