use of eu.bcvsolutions.idm.acc.event.SystemEvent in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningServiceTest method doIdentityProvisioningChangePasswordUnsupportSystem.
@Test
public void doIdentityProvisioningChangePasswordUnsupportSystem() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
SysSystemDto system = systemService.get(accountService.get(accountIdentityOne.getAccount()).getSystem());
EntityEvent<SysSystemDto> event = new SystemEvent(SystemEventType.DUPLICATE, system);
SysSystemDto clonedSystem = systemService.publish(event).getContent();
clonedSystem.setReadonly(false);
clonedSystem.setDisabled(false);
clonedSystem = systemService.save(clonedSystem);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemId(clonedSystem.getId());
SysSystemAttributeMappingDto passwordAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
return ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME.equals(schemaAttributeService.get(attribute.getSchemaAttribute()).getName());
}).findFirst().orElse(null);
Assert.assertNotNull(passwordAttribute);
SysSystemAttributeMappingDto uidAttribute = systemAttributeMappingService.find(attributeMappingFilter, null).getContent().stream().filter(attribute -> {
return attribute.isUid();
}).findFirst().orElse(null);
Assert.assertNotNull(uidAttribute);
uidAttribute.setTransformToResourceScript("if(attributeValue){return \"y\"+ attributeValue;}");
uidAttribute = systemAttributeMappingService.save(uidAttribute);
SysSystemEntityDto sysEntity = new SysSystemEntityDto("y" + IDENTITY_USERNAME, SystemEntityType.IDENTITY);
sysEntity.setSystem(clonedSystem.getId());
sysEntity = systemEntityService.save(sysEntity);
AccAccountDto account = new AccAccountDto();
account.setSystem(clonedSystem.getId());
account.setUid("y" + IDENTITY_USERNAME);
account.setAccountType(AccountType.PERSONAL);
account.setEntityType(SystemEntityType.IDENTITY);
account.setSystemEntity(sysEntity.getId());
account = accountService.save(account);
AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
accountIdentity.setIdentity(identity.getId());
accountIdentity.setOwnership(true);
accountIdentity.setAccount(account.getId());
accountIdentity = identityAccountService.save(accountIdentity);
provisioningService.doProvisioning(account);
TestResource createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
String password = createdAccount.getPassword();
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setIdentityId(identity.getId());
accountFilter.setOwnership(Boolean.TRUE);
accountFilter.setSupportChangePassword(Boolean.TRUE);
// Two accounts supported change password expects
Assert.assertEquals(2, accountService.find(accountFilter, null).getContent().size());
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setNewPassword(new GuardedString("newPWD12"));
passwordChange.getAccounts().add(account.getId().toString());
identityService.passwordChange(identity, passwordChange);
createdAccount = entityManager.find(TestResource.class, accountService.get(accountIdentity.getAccount()).getUid());
Assert.assertNotEquals(password, createdAccount.getPassword());
// After success password change, we delete password attribute.
systemAttributeMappingService.delete(passwordAttribute);
// One account supported change password expects
Assert.assertEquals(1, accountService.find(accountFilter, null).getContent().size());
// Change password .. now this doesn't end with exception but with failed state
passwordChange = new PasswordChangeDto();
passwordChange.setNewPassword(new GuardedString("newPWDUnsupported"));
passwordChange.getAccounts().add(account.getId().toString());
List<OperationResult> results = identityService.passwordChange(identity, passwordChange);
// for idm will be password changed executed with success state for system doesn't
for (OperationResult result : results) {
IdmAccountDto idmAccount = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
String statusEnum = result.getModel().getStatusEnum();
assertNotNull(statusEnum);
assertNotNull(idmAccount);
if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name())) {
// idm
assertNull(idmAccount.getSystemId());
assertNull(idmAccount.getSystemName());
continue;
} else if (statusEnum.equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED.name())) {
assertEquals(clonedSystem.getId(), idmAccount.getSystemId());
assertEquals(clonedSystem.getName(), idmAccount.getSystemName());
continue;
}
fail("Different result!");
}
}
Aggregations