use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemMappingService method getMappingContext.
@Override
public MappingContext getMappingContext(SysSystemMappingDto mapping, SysSystemEntityDto systemEntity, AbstractDto dto, SysSystemDto system) {
Assert.notNull(mapping, "Mapping cannot be null!");
Assert.notNull(systemEntity, "System entity cannot be null!");
Assert.notNull(system, "System cannot be null!");
// Create new context.
MappingContext mappingContext = new MappingContext();
if (dto == null) {
return mappingContext;
}
if ((mapping.isAddContextIdentityRoles() || mapping.isAddContextIdentityRolesForSystem()) && dto instanceof IdmIdentityDto) {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(dto.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
if (mapping.isAddContextIdentityRoles()) {
// Set all identity-roles to the context.
mappingContext.setIdentityRoles(identityRoles);
}
if (mapping.isAddContextIdentityRolesForSystem()) {
Assert.notNull(system.getId(), "System identifier is required.");
List<IdmIdentityRoleDto> identityRolesForSystem = Lists.newArrayList();
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setIdentityId(dto.getId());
identityAccountFilter.setSystemId(system.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
// Filtering only identity-roles for this system.
identityAccounts.forEach(identityAccount -> {
identityRolesForSystem.addAll(identityRoles.stream().filter(identityRole -> identityRole.getId().equals(identityAccount.getIdentityRole())).collect(Collectors.toList()));
});
// Set identity-roles for this system to the context.
mappingContext.setIdentityRolesForSystem(identityRolesForSystem);
}
}
if (mapping.isAddContextContracts() && dto instanceof IdmIdentityDto) {
// Set all identity contracts to the context.
mappingContext.setContracts(identityContractService.findAllByIdentity(dto.getId()));
}
if (mapping.isAddContextConnectorObject()) {
// Set connector object to the context.
mappingContext.setConnectorObject(systemEntityService.getConnectorObject(systemEntity));
}
String script = mapping.getMappingContextScript();
if (StringUtils.isEmpty(script)) {
return mappingContext;
} else {
Map<String, Object> variables = new HashMap<>();
variables.put(SysSystemAttributeMappingService.ACCOUNT_UID, systemEntity.getUid());
variables.put(SysSystemAttributeMappingService.SYSTEM_KEY, system);
variables.put(SysSystemAttributeMappingService.ENTITY_KEY, dto);
variables.put(SysSystemAttributeMappingService.CONTEXT_KEY, mappingContext);
// Add default script evaluator, for call another scripts
variables.put(AbstractScriptEvaluator.SCRIPT_EVALUATOR, pluginExecutors.getPluginFor(IdmScriptCategory.MAPPING_CONTEXT));
// Add access for script evaluator
List<Class<?>> extraClass = new ArrayList<>();
extraClass.add(AbstractScriptEvaluator.Builder.class);
extraClass.add(IcConnectorObject.class);
//
Object result = groovyScriptService.evaluate(script, variables, extraClass);
if (result instanceof MappingContext) {
return (MappingContext) result;
} else {
throw new ProvisioningException(AccResultCode.MAPPING_CONTEXT_SCRIPT_RETURNS_WRONG_TYPE, ImmutableMap.of("system", system.getCode()));
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter 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.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testUpdateContractWithAutomaticRoles.
@Test
public void testUpdateContractWithAutomaticRoles() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
// create first contract with validity and automatic role
String positionCode = getHelper().createName();
IdmTreeNodeDto node = getHelper().createTreeNode();
IdmRoleDto role = getHelper().createRole();
getHelper().createAutomaticRole(role, node);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusMonths(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setDescription(positionCode);
contract.setPosition(positionCode);
contract.setWorkPosition(node.getId());
contract = contractService.save(contract);
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue(positionCode);
Assert.assertEquals(1, contractService.find(contractFilter, null).getTotalElements());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contract.getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNotNull(assignedRoles.get(0).getValidFrom());
Assert.assertNotNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(contract.getValidFrom(), assignedRoles.get(0).getValidFrom());
Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
// create target system entity
this.getBean().createContractData(positionCode, identity.getUsername(), null, Boolean.TRUE.toString(), node.getId().toString(), null, null);
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1);
Assert.assertFalse(log.isRunning());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contracts.size());
Assert.assertEquals(contract.getId(), contracts.get(0).getId());
Assert.assertEquals(identity.getId(), contracts.get(0).getIdentity());
Assert.assertNull(contracts.get(0).getValidTill());
Assert.assertNull(contracts.get(0).getValidFrom());
//
assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNull(assignedRoles.get(0).getValidFrom());
Assert.assertNull(assignedRoles.get(0).getValidTill());
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleWorkflowAdSyncTest method n92_testSyncWithWfSituationLinkedResolveMember.
@Test
public void n92_testSyncWithWfSituationLinkedResolveMember() {
createRolesInSystem();
final String newDN = "CN=" + ROLE_NAME + ",OU=Flat,OU=Pardubice,DC=bcvsolutions,DC=eu";
this.getBean().initIdentityData(ROLE_NAME, newDN);
String valueOfMemberAtt = "" + System.currentTimeMillis();
String nameOfEav = "externalIdentifier";
configurationService.setValue("idm.pub.acc.syncRole.identity.eav.externalIdentifier.code", nameOfEav);
configurationService.setValue("idm.pub.acc.syncRole.roles.attributeNameOfMembership", helper.getSchemaColumnName(ATTRIBUTE_MEMBER));
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", true);
IdmIdentityDto identity = this.getHelper().createIdentity();
IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
attributeFilter.setCode(nameOfEav);
IdmFormAttributeDto formAttribute = formAttributeService.find(attributeFilter, null).getContent().stream().findFirst().orElse(null);
Assert.assertNotNull(formAttribute);
helper.setEavValue(identity, formAttribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
this.getBean().deleteAllResourceData();
this.getBean().addRoleToResource(ROLE_NAME, ATTRIBUTE_DN, valueOfMemberAtt);
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setText(ROLE_NAME);
List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
// role is in already synced ind idm
Assert.assertEquals(1, roles.size());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
// identity does not have assigned this role
Assert.assertEquals(0, content.size());
SysSystemDto systemDto = systemService.getByCode(SYSTEM_NAME);
Assert.assertNotNull(systemDto);
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(systemDto.getId());
List<AbstractSysSyncConfigDto> syncConfig = syncConfigService.find(syncFilter, null).getContent();
// find synchronization config to start sync
Assert.assertEquals(1, syncConfig.size());
// Start sync
helper.startSynchronization(syncConfig.get(0));
SysSyncLogDto log = checkSyncLog(syncConfig.get(0), SynchronizationActionType.LINKED, 1, OperationResultType.WF);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
roles = roleService.find(roleFilter, null).getContent();
Assert.assertEquals(1, roles.size());
content = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
identityRoleService.delete(content.get(0));
// Delete log
syncLogService.delete(log);
configurationService.deleteValue("idm.pub.acc.syncRole.provisioningOfIdentities.system.code");
configurationService.deleteValue("idm.pub.acc.syncRole.system.mapping.attributeMemberOf");
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", false);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityDeleteBulkAction method end.
@Override
protected OperationResult end(OperationResult result, Exception exception) {
if (exception != null || (result != null && OperationState.EXECUTED != result.getState())) {
return super.end(result, exception);
}
// success - force by default
for (UUID identityId : processedIds) {
IdmIdentityDto identity = getService().get(identityId);
if (identity != null) {
// delete identity contracts => contract related records are removed asynchornously, but contract itself will be removed here
for (IdmIdentityContractDto contract : contractService.findAllByIdentity(identityId)) {
// check assigned roles again - can be assigned in the meantime ...
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
UUID contractId = contract.getId();
identityRoleFilter.setIdentityContractId(contractId);
if (identityRoleService.count(identityRoleFilter) > 0) {
return super.end(result, new ResultCodeException(CoreResultCode.CONTRACT_DELETE_FAILED_ROLE_ASSIGNED, ImmutableMap.of("contract", contractId)));
}
contractService.deleteInternal(contract);
//
LOG.debug("Contract [{}] deleted.", contractId);
// clean up all states
entityStateManager.deleteStates(contract, null, null);
}
//
// Delete all role requests where is this identity applicant - processed asynchronous requests should be deleted here
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identityId);
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
//
identityService.deleteInternal(identity);
//
LOG.debug("Identity [{}] deleted.", identity.getUsername());
} else {
LOG.debug("Identity [{}] already deleted.", identityId);
}
// clean up all states
entityStateManager.deleteStates(new IdmIdentityDto(identityId), null, null);
}
return super.end(result, exception);
}
Aggregations