Search in sources :

Example 1 with IdmPasswordHistoryDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordHistoryDto 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());
}
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 2 with IdmPasswordHistoryDto

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

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

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

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

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