Search in sources :

Example 6 with IdmPasswordHistoryDto

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());
}
Also used : IdmPasswordHistoryFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter) IdmPasswordHistoryDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto)

Example 7 with IdmPasswordHistoryDto

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;
}
Also used : IdmPasswordHistoryDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 8 with IdmPasswordHistoryDto

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);
}
Also used : IdmPasswordHistoryDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto)

Example 9 with IdmPasswordHistoryDto

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());
}
Also used : IdmPasswordHistoryFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter) ZonedDateTime(java.time.ZonedDateTime) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordHistoryDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 10 with IdmPasswordHistoryDto

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());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordHistoryDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmPasswordHistoryDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto)13 IdmPasswordHistoryFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordHistoryFilter)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)9 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Test (org.junit.Test)9 ZonedDateTime (java.time.ZonedDateTime)3 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)1 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1