use of eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testFilteringByValidFromAndTillCombination.
@Test
public void testFilteringByValidFromAndTillCombination() {
String password = "password-" + System.currentTimeMillis();
GuardedString passwordAsGuardedString = new GuardedString(password);
// Change 1
IdmIdentityDto identity = testHelper.createIdentity(passwordAsGuardedString);
ZonedDateTime from = ZonedDateTime.now();
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setOldPassword(passwordAsGuardedString);
passwordChange.setAll(true);
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
// Change 2
identityService.passwordChange(identity, passwordChange);
// Change 3
identityService.passwordChange(identity, passwordChange);
ZonedDateTime till = ZonedDateTime.now();
// Change 4
identityService.passwordChange(identity, passwordChange);
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identity.getId());
filter.setFrom(from);
filter.setTill(till);
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(filter, null).getContent();
assertEquals(2, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testCreateNewPasswordAsNoAdmin.
@Test
public void testCreateNewPasswordAsNoAdmin() {
String password = "test-password-" + System.currentTimeMillis();
String originalPassword = "test-password-" + System.currentTimeMillis();
IdmIdentityDto identity = testHelper.createIdentity(new GuardedString(originalPassword));
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identity.getId());
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(filter, null).getContent();
// after create identity is only one record
assertEquals(1, content.size());
this.loginAsNoAdmin(identity.getUsername());
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setOldPassword(new GuardedString(originalPassword));
passwordChange.setAll(true);
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
identityService.passwordChange(identity, passwordChange);
content = passwordHistoryService.find(filter, null).getContent();
assertEquals(2, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testFilteringByCreatorOne.
@Test
public void testFilteringByCreatorOne() {
String password = "password-" + System.currentTimeMillis();
GuardedString passwordAsGuardedString = new GuardedString(password);
IdmIdentityDto admin = testHelper.createIdentity();
loginAsAdmin(admin.getUsername());
// Change 1
IdmIdentityDto identity = testHelper.createIdentity(passwordAsGuardedString);
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setOldPassword(passwordAsGuardedString);
passwordChange.setAll(true);
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
// Change 2
identityService.passwordChange(identity, passwordChange);
// Change 3
identityService.passwordChange(identity, passwordChange);
// Change 4
identityService.passwordChange(identity, passwordChange);
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setCreator(admin.getCode());
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(filter, null).getContent();
assertEquals(4, content.size());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter in project CzechIdMng by bcvsolutions.
the class DefaultPasswordHistoryIntegrationTest method testFilteringByIdentity.
@Test
public void testFilteringByIdentity() {
passwordHistoryService.find(null).getContent();
String password = "test-password-" + System.currentTimeMillis();
String originalPassword = "test-password-" + System.currentTimeMillis();
IdmIdentityDto identity = testHelper.createIdentity(new GuardedString(originalPassword));
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString(password));
identityService.passwordChange(identity, passwordChange);
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identity.getId());
List<IdmPasswordHistoryDto> content = passwordHistoryService.find(filter, null).getContent();
// after create identity is create only one password history record
assertEquals(2, content.size());
IdmPasswordDto identityPassword = passwordService.findOneByIdentity(identity.getId());
// behavior with content.get(0) is not good for use, order comes from DB!
boolean existsSamePassword = false;
for (IdmPasswordHistoryDto pass : content) {
if (pass.getPassword().equals(identityPassword.getPassword())) {
existsSamePassword = true;
}
}
assertTrue(existsSamePassword);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordHistoryService method deleteAllByIdentity.
@Override
public void deleteAllByIdentity(UUID identityId) {
Assert.notNull(identityId, "Identity id can't be null.");
//
IdmPasswordHistoryFilter filter = new IdmPasswordHistoryFilter();
filter.setIdentityId(identityId);
//
for (IdmPasswordHistoryDto passwordHistory : this.find(filter, null)) {
this.delete(passwordHistory);
}
}
Aggregations