use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testFilterByPassword.
@Test
public void testFilterByPassword() {
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());
filter = new IdmPasswordFilter();
filter.setPassword(passwordDto.getPassword());
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());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testFilterValidFrom.
@Test
public void testFilterValidFrom() {
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.setValidFrom(LocalDate.now().minusDays(55));
passwordTwo.setValidFrom(LocalDate.now().minusDays(1));
passwordThree.setValidFrom(LocalDate.now().plusDays(100));
passwordService.save(passwordOne);
passwordService.save(passwordTwo);
passwordService.save(passwordThree);
filter = new IdmPasswordFilter();
filter.setValidFrom(LocalDate.now().minusDays(99));
List<IdmPasswordDto> passwords = passwordService.find(filter, null).getContent();
assertTrue(passwords.size() >= 3);
IdmPasswordDto 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);
filter = new IdmPasswordFilter();
filter.setValidFrom(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.setValidFrom(LocalDate.now().plusDays(50));
passwords = passwordService.find(filter, null).getContent();
assertTrue(passwords.size() >= 1);
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);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testPreserveValidFromUnderDifferentIdentity.
@Test
public void testPreserveValidFromUnderDifferentIdentity() {
IdmIdentityDto manager = getHelper().createIdentity();
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(manager);
identityService.passwordChange(identity, passwordChangeDto);
password = passwordService.findOneByIdentity(identity.getId());
Assert.assertNotNull(password.getValidFrom());
Assert.assertNull(password.getValidTill());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testSetFalidFromUnderSameUser.
@Test
public void testSetFalidFromUnderSameUser() {
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"));
//
try {
getHelper().login(identity);
identityService.passwordChange(identity, passwordChangeDto);
password = passwordService.findOneByIdentity(identity.getId());
Assert.assertNotNull(password.getValidFrom());
Assert.assertNull(password.getValidTill());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testCreatePasswordNonDefaultPolicy.
@Test
public void testCreatePasswordNonDefaultPolicy() {
IdmPasswordPolicyDto policy = getTestPolicy(false);
assertNotNull(policy);
IdmIdentityDto identity = getHelper().createIdentity();
//
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
Assert.assertNull(password.getValidFrom());
Assert.assertEquals(identity.getId(), password.getIdentity());
// when not exists default validation policy valid till be null
Assert.assertNull(password.getValidTill());
}
Aggregations