Search in sources :

Example 71 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordServiceIntegrationTest method testFilterMustChange.

@Test
public void testFilterMustChange() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString("test" + System.currentTimeMillis()));
    IdmPasswordFilter filter = new IdmPasswordFilter();
    filter.setIdentityId(identity.getId());
    List<IdmPasswordDto> passwords = passwordService.find(filter, null).getContent();
    assertEquals(1, passwords.size());
    IdmPasswordDto passwordDto = passwords.get(0);
    assertEquals(identity.getId(), passwordDto.getIdentity());
    passwordDto.setMustChange(true);
    passwordService.save(passwordDto);
    filter = new IdmPasswordFilter();
    filter.setMustChange(true);
    passwords = passwordService.find(filter, null).getContent();
    assertEquals(1, passwords.size());
    IdmPasswordDto passwordDtoTwo = passwords.get(0);
    assertEquals(identity.getId(), passwordDtoTwo.getIdentity());
    assertEquals(passwordDto.getId(), passwordDtoTwo.getId());
    assertEquals(passwordDto.getPassword(), passwordDtoTwo.getPassword());
}
Also used : IdmPasswordFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 72 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordServiceIntegrationTest method testFilterValidTill.

@Test
public void testFilterValidTill() {
    IdmIdentityDto identityOne = getHelper().createIdentity(new GuardedString("test" + System.currentTimeMillis()));
    IdmIdentityDto identityTwo = getHelper().createIdentity(new GuardedString("test" + System.currentTimeMillis()));
    IdmIdentityDto identityTree = getHelper().createIdentity(new GuardedString("test" + System.currentTimeMillis()));
    IdmPasswordFilter filter = new IdmPasswordFilter();
    filter.setIdentityId(identityOne.getId());
    IdmPasswordDto passwordOne = passwordService.find(filter, null).getContent().get(0);
    filter.setIdentityId(identityTwo.getId());
    IdmPasswordDto passwordTwo = passwordService.find(filter, null).getContent().get(0);
    filter.setIdentityId(identityTree.getId());
    IdmPasswordDto passwordThree = passwordService.find(filter, null).getContent().get(0);
    passwordOne.setValidTill(LocalDate.now().minusDays(1));
    passwordTwo.setValidTill(LocalDate.now().minusDays(10));
    passwordThree.setValidTill(LocalDate.now().minusDays(100));
    passwordService.save(passwordOne);
    passwordService.save(passwordTwo);
    passwordService.save(passwordThree);
    filter = new IdmPasswordFilter();
    filter.setValidTill(LocalDate.now().minusDays(99));
    List<IdmPasswordDto> passwords = passwordService.find(filter, null).getContent();
    assertTrue(passwords.size() >= 1);
    IdmPasswordDto passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityOne.getId());
    }).findFirst().orElse(null);
    assertNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTwo.getId());
    }).findFirst().orElse(null);
    assertNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTree.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
    filter = new IdmPasswordFilter();
    filter.setValidTill(LocalDate.now().minusDays(9));
    passwords = passwordService.find(filter, null).getContent();
    assertTrue(passwords.size() >= 2);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityOne.getId());
    }).findFirst().orElse(null);
    assertNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTwo.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTree.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
    filter = new IdmPasswordFilter();
    filter.setValidTill(LocalDate.now());
    passwords = passwordService.find(filter, null).getContent();
    assertTrue(passwords.size() >= 2);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityOne.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTwo.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
    passwordDto = passwords.stream().filter(pass -> {
        return pass.getIdentity().equals(identityTree.getId());
    }).findFirst().orElse(null);
    assertNotNull(passwordDto);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) LoginController(eu.bcvsolutions.idm.core.security.rest.impl.LoginController) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) IdmPasswordPolicyType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) IdmPasswordFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter) ApplicationContext(org.springframework.context.ApplicationContext) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) List(java.util.List) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmPasswordPolicyService(eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService) IdmPasswordFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 73 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordServiceIntegrationTest method testFilterIdentityUsername.

@Test
public void testFilterIdentityUsername() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString("test" + System.currentTimeMillis()));
    IdmPasswordFilter filter = new IdmPasswordFilter();
    filter.setIdentityUsername(identity.getUsername());
    List<IdmPasswordDto> passwords = passwordService.find(filter, null).getContent();
    assertEquals(1, passwords.size());
    IdmPasswordDto passwordDto = passwords.get(0);
    assertEquals(identity.getId(), passwordDto.getIdentity());
}
Also used : IdmPasswordFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 74 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordServiceIntegrationTest method testPreserveValidFromUnderSameIdentity.

@Test
public void testPreserveValidFromUnderSameIdentity() {
    IdmIdentityDto identity = getHelper().createIdentity();
    // 
    IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
    Assert.assertNull(password.getValidFrom());
    Assert.assertEquals(identity.getId(), password.getIdentity());
    // 
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAll(true);
    passwordChangeDto.setIdm(true);
    passwordChangeDto.setOldPassword(identity.getPassword());
    passwordChangeDto.setNewPassword(new GuardedString("testPassword"));
    passwordChangeDto.setSkipResetValidFrom(true);
    // 
    try {
        getHelper().login(identity);
        identityService.passwordChange(identity, passwordChangeDto);
        password = passwordService.findOneByIdentity(identity.getId());
        Assert.assertNotNull(password.getValidFrom());
        Assert.assertNull(password.getValidTill());
    } finally {
        logout();
    }
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 75 with IdmPasswordDto

use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordServiceIntegrationTest method checkNullBothPasswords.

@Test
public void checkNullBothPasswords() {
    GuardedString passwordForCheck = new GuardedString();
    IdmPasswordDto newPassword = new IdmPasswordDto();
    assertFalse(passwordService.checkPassword(passwordForCheck, newPassword));
}
Also used : IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)88 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)71 Test (org.junit.Test)65 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)53 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)52 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)28 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)9 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)9 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)9 ZonedDateTime (java.time.ZonedDateTime)9 UUID (java.util.UUID)9 IdmPasswordFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter)8 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException)8 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7