use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testCheckMappingReturnStringCreate.
@Test
public void testCheckMappingReturnStringCreate() {
String postfixForPassword = "-" + System.currentTimeMillis();
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
SysSystemAttributeMappingDto descriptionAttribute = initDescriptionAttribute(system);
descriptionAttribute = changeAttributeToPasswordMapping(descriptionAttribute, "" + "import eu.bcvsolutions.idm.core.security.api.domain.GuardedString;" + System.lineSeparator() + "" + System.lineSeparator() + "String newPassword = attributeValue.asString();" + System.lineSeparator() + "newPassword = newPassword + " + postfixForPassword + ";" + System.lineSeparator() + "" + System.lineSeparator() + "return newPassword;" + System.lineSeparator());
String identityUsername = "test-" + System.currentTimeMillis();
IdmIdentityDto identity = helper.createIdentity(identityUsername);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
TestResource findResource = helper.findResource(identityUsername);
assertNull(findResource);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityType(SystemEntityType.IDENTITY);
filter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> operations = provisioningOperationService.find(filter, null).getContent();
assertEquals(1, operations.size());
SysProvisioningOperationDto operationDto = operations.get(0);
assertEquals(OperationState.EXCEPTION, operationDto.getResultState());
OperationResult result = operationDto.getResult();
assertEquals(AccResultCode.PROVISIONING_PASSWORD_TRANSFORMATION_FAILED.getCode(), result.getCode());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testCheckMappingReturnNull.
@Test
public void testCheckMappingReturnNull() {
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
SysSystemAttributeMappingDto descriptionAttribute = initDescriptionAttribute(system);
descriptionAttribute = changeAttributeToPasswordMapping(descriptionAttribute, "return null;" + System.lineSeparator());
String identityUsername = "test-" + System.currentTimeMillis();
IdmIdentityDto identity = helper.createIdentity(identityUsername);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
TestResource findResource = helper.findResource(identityUsername);
assertNotNull(findResource);
assertEquals(DEFAULT_PASSWORD, findResource.getPassword());
assertNull(findResource.getDescrip());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method twoAttributesBothEnabled.
@Test
public void twoAttributesBothEnabled() {
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
SysSystemAttributeMappingDto descriptionAttribute = initDescriptionAttribute(system);
changeAttributeToPasswordMapping(descriptionAttribute, null);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
TestResource findResource = helper.findResource(identity.getUsername());
assertNotNull(findResource);
assertEquals(DEFAULT_PASSWORD, findResource.getPassword());
assertEquals(DEFAULT_PASSWORD, findResource.getDescrip());
String newPassword = "password" + System.currentTimeMillis();
// change password, but only for idm
List<OperationResult> results = changePassword(identity, null, newPassword);
assertEquals(2, results.size());
// check for results
for (OperationResult result : results) {
IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
String statusEnum = result.getModel().getStatusEnum();
assertNotNull(statusEnum);
assertNotNull(account);
if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name())) {
if (account.getSystemId() == null) {
// idm
assertNull(account.getSystemId());
assertNull(account.getSystemName());
} else {
assertEquals(system.getId(), account.getSystemId());
assertEquals(system.getName(), account.getSystemName());
}
continue;
}
fail("Different result!");
}
// password must be same as before
findResource = helper.findResource(identity.getUsername());
assertNotNull(findResource);
assertEquals(newPassword, findResource.getPassword());
assertEquals(newPassword, findResource.getDescrip());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method testSendPasswordNotificationProvisioningFailed.
@Test
public void testSendPasswordNotificationProvisioningFailed() {
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
IdmIdentityDto identity = helper.createIdentity();
// => new password is sent for valid identity only
identity.setState(IdentityState.VALID);
identityService.save(identity);
// Break the system (change the password column to not exists) - we need make a exception.
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system);
IdmFormAttributeDto formAttribute = savedFormDefinition.getMappedAttributeByCode("passwordColumn");
formService.saveValues(system, formAttribute, Lists.newArrayList("not-exist-column-password"));
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource entityOnSystem = helper.findResource(account.getUid());
assertNull(entityOnSystem);
// Check for send password notification
IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
notificationFilter.setTopic(AccModuleDescriptor.TOPIC_NEW_PASSWORD);
notificationFilter.setRecipient(identity.getUsername());
List<IdmNotificationLogDto> notifications = //
notificationLogService.find(notificationFilter, null).getContent().stream().filter(//
notification -> IdmEmailLog.NOTIFICATION_TYPE.equals(notification.getType())).collect(Collectors.toList());
assertEquals(0, notifications.size());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class IdentityPasswordProvisioningTest method twoAttributeDescriptionDisabled.
@Test
public void twoAttributeDescriptionDisabled() {
SysSystemDto system = initSystem();
IdmRoleDto role = initRole(system);
SysSystemAttributeMappingDto descriptionAttribute = initDescriptionAttribute(system);
changeAttributeToPasswordMapping(descriptionAttribute, null);
descriptionAttribute.setDisabledAttribute(true);
descriptionAttribute = systemAttributeMappingService.save(descriptionAttribute);
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
checkIdentityAccount(identity, identityRole, 1);
TestResource findResource = helper.findResource(identity.getUsername());
assertNotNull(findResource);
assertEquals(DEFAULT_PASSWORD, findResource.getPassword());
assertNull(findResource.getDescrip());
String newPassword = "password" + System.currentTimeMillis();
// change password, but only for idm
List<OperationResult> results = changePassword(identity, null, newPassword);
assertEquals(2, results.size());
// check for results
for (OperationResult result : results) {
IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
String statusEnum = result.getModel().getStatusEnum();
assertNotNull(statusEnum);
assertNotNull(account);
if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name())) {
if (account.getSystemId() == null) {
// idm
assertNull(account.getSystemId());
assertNull(account.getSystemName());
} else {
assertEquals(system.getId(), account.getSystemId());
assertEquals(system.getName(), account.getSystemName());
}
continue;
}
fail("Different result!");
}
// password must be same as before
findResource = helper.findResource(identity.getUsername());
assertNotNull(findResource);
assertEquals(newPassword, findResource.getPassword());
// description is disabled
assertNull(findResource.getDescrip());
}
Aggregations