use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAutomaticRolesRemovalAfterContractEnds.
@Test
public void testAutomaticRolesRemovalAfterContractEnds() {
// automatic roles by tree structure
prepareAutomaticRoles();
// automatic role by attribute on contract
String autoPosition = getHelper().createName();
IdmRoleDto autoAttributeRole = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(autoAttributeRole.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, autoPosition);
//
// prepare identity, contract, direct roles and automatic roles
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusDays(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract.setMain(true);
contract.setDescription("test-node-d");
contract.setPosition(autoPosition);
contract = service.save(contract);
UUID contractId = contract.getId();
IdmRoleDto directRole = getHelper().createRole();
getHelper().createIdentityRole(contract, directRole);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(5, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return directRole.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return autoAttributeRole.getId().equals(ir.getRole());
}));
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// end contract - all roles should be removed, after asynchronous role request ends
contract.setValidTill(LocalDate.now().minusDays(1));
contract = service.save(contract);
//
Assert.assertFalse(contract.isValidNowOrInFuture());
//
getHelper().waitForResult(res -> {
return !identityRoleService.findAllByContract(contractId).isEmpty();
}, 300, Integer.MAX_VALUE);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertTrue(identityRoles.isEmpty());
//
service.delete(contract);
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
}
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.
the class IdmIdentityContractControllerRestTest method testSortByPrimeContract.
@Test
public void testSortByPrimeContract() {
IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
IdmIdentityDto identityThree = getHelper().createIdentity((GuardedString) null);
// other contract jus for sure
IdmIdentityContractDto contractOther = getHelper().createContract(identityTwo);
//
IdmIdentityContractDto contract = getHelper().createContract(identityOne);
contract.setValidFrom(LocalDate.now().minusDays(5));
contract.setState(ContractState.DISABLED);
contract.setMain(true);
IdmIdentityContractDto contractOne = contractService.save(contract);
//
contract = getHelper().createContract(identityOne);
contract.setValidFrom(LocalDate.now().minusDays(4));
// two
contractService.save(contract);
//
contract = getHelper().createContract(identityOne);
contract.setValidFrom(LocalDate.now().minusDays(3));
// three
contractService.save(contract);
//
contract = getHelper().createContract(identityOne);
contract.setMain(true);
contract.setValidFrom(LocalDate.now().minusDays(2));
IdmIdentityContractDto primeContract = contractService.save(contract);
//
List<IdmIdentityContractDto> contracts = controller.find((IdmIdentityContractFilter) null, PageRequest.of(0, 1), null).getContent();
Assert.assertFalse(contracts.isEmpty());
//
IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
contracts = controller.find((IdmIdentityContractFilter) null, PageRequest.of(0, 1), null).getContent();
Assert.assertFalse(contracts.isEmpty());
//
filter.setIdentity(identityOne.getId());
contracts = controller.find(filter, PageRequest.of(0, 5), null).getContent();
Assert.assertEquals(4, contracts.size());
Assert.assertTrue(contracts.stream().allMatch(c -> !c.getId().equals(contractOther.getId())));
Assert.assertEquals(primeContract.getId(), contracts.get(0).getId());
//
filter.setIdentity(identityThree.getId());
contracts = controller.find(filter, PageRequest.of(0, 5), null).getContent();
Assert.assertTrue(contracts.isEmpty());
//
filter.setIdentity(identityOne.getId());
contracts = controller.find(filter, PageRequest.of(0, 5, Sort.by(Direction.ASC, IdmIdentityContract_.validFrom.getName())), null).getContent();
Assert.assertEquals(4, contracts.size());
Assert.assertEquals(contractOne.getId(), contracts.get(0).getId());
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testCreateContractWithAutomaticRoleByEavAttribute.
@Test
public void testCreateContractWithAutomaticRoleByEavAttribute() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
//
// create form definition, roles, automatic role etc.
IdmRoleDto roleContract = getHelper().createRole();
IdmRoleDto subRoleContract = getHelper().createRole();
getHelper().createRoleComposition(roleContract, subRoleContract);
// sync supports default definition only
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeContract = formService.saveAttribute(IdmIdentityContractDto.class, formAttribute);
//
IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
//
// create mapping to eav attribute - leader = eav
SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
SysSystemAttributeMappingDto leaderAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), "leader");
leaderAttributeMapping.setEntityAttribute(false);
leaderAttributeMapping.setExtendedAttribute(true);
leaderAttributeMapping.setIdmPropertyName(formAttributeContract.getCode());
schemaAttributeMappingService.save(leaderAttributeMapping);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
String positionCode = getHelper().createName();
this.getBean().createContractData(positionCode, identity.getUsername(), "mockContract", Boolean.TRUE.toString(), null, null, null);
//
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertTrue(assignedRoles.isEmpty());
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(identity.getId());
contractFilter.setAddEavMetadata(Boolean.TRUE);
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue(positionCode);
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertEquals("mockContract", contracts.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeContract.getId())).findFirst().get().getShortTextValue());
assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(roleContract.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRoleContract.getId())));
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_ in project CzechIdMng by bcvsolutions.
the class IdentityRoleDeleteProvisioningProcessor method process.
@SuppressWarnings("unchecked")
@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
IdmIdentityRoleDto identityRole = event.getContent();
// If for this role doesn't exists any mapped system, then is provisioning useless!
UUID roleId = identityRole.getRole();
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setRoleId(roleId);
long numberOfMappedSystem = roleSystemService.count(roleSystemFilter);
if (numberOfMappedSystem == 0) {
return new DefaultEventResult<>(event, this);
}
// TODO: Optimalization - load identity by identity-role with filter
IdmIdentityContractDto identityContract = identityContractService.get(identityRole.getIdentityContract());
IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity);
Serializable accountsIdsObj = event.getProperties().get(AccAccountManagementService.ACCOUNT_IDS_FOR_DELETED_IDENTITY_ROLE);
List<UUID> accountsIds = null;
if (accountsIdsObj instanceof List) {
accountsIds = (List<UUID>) accountsIdsObj;
}
if (accountsIds == null) {
// We don't know about specific accounts, so we will execute provisioning for all accounts.
LOG.debug("Call provisioning for identity [{}]", identity.getUsername());
provisioningService.doProvisioning(identity);
return new DefaultEventResult<>(event, this);
}
// If default creation of accounts is disabled for this role-system (or system is in a cross-domain group), then relation between identity
// and account may not exist. In this scenario we have to made provisioning too.
// So we try to find these role-systems and its accounts.
SysRoleSystemFilter roleSystemForProvisioningFilter = new SysRoleSystemFilter();
roleSystemForProvisioningFilter.setRoleId(roleId);
List<UUID> finalAccountsIds = accountsIds;
roleSystemService.find(roleSystemForProvisioningFilter, null).getContent().stream().filter(roleSystem -> {
if (!roleSystem.isCreateAccountByDefault()) {
return true;
} else {
SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
systemGroupSystemFilter.setCrossDomainsGroupsForRoleSystemId(roleSystem.getId());
if ((identityRole.getRoleSystem() == null || roleSystem.getId().equals(identityRole.getRoleSystem()) && systemGroupSystemService.count(systemGroupSystemFilter) >= 1)) {
// -> Provisioning should be made.
return true;
}
}
return false;
}).forEach(roleSystem -> {
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSystemId(roleSystem.getSystem());
accountFilter.setIdentityId(identity.getId());
accountService.find(accountFilter, null).getContent().stream().filter(account -> !finalAccountsIds.contains(account.getId())).forEach(account -> {
finalAccountsIds.add(account.getId());
});
});
finalAccountsIds.forEach(accountId -> {
AccAccountDto account = accountService.get(accountId);
if (account != null) {
// Account could be null (was deleted).
LOG.debug("Call provisioning for identity [{}] and account [{}]", identity.getUsername(), account.getUid());
provisioningService.doProvisioning(account, identity);
}
});
return new DefaultEventResult<>(event, this);
}
Aggregations