use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class MappingContextTest method testMappingContextIdentityRoles.
@Test
public void testMappingContextIdentityRoles() {
SysSystemDto system = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
Assert.assertNotNull(mapping);
// Create the description attribute (print context as string).
createDescriptionAttribute(system, mapping);
// Set context transformation to the mapping.
// Add identity roles to the context.
mapping.setAddContextIdentityRoles(true);
mapping = initContextForMapping(mapping);
IdmRoleDto roleWithSystem = helper.createRole();
IdmRoleDto roleWithoutSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, system);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithoutSystem, null, null);
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
Assert.assertEquals(2, identityRoles.size());
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertEquals(identity.getFirstName(), resource.getFirstname());
MappingContext context = new MappingContext();
context.put("test", "TestValueOne");
context.setIdentityRoles(identityRoles);
assertEquals(context.toString(), resource.getDescrip());
// Delete role mapping
systemMappingService.delete(mapping);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method getIdentityRoles.
/**
* Load assigned roles.
*
* @param dto
* @param permission
* @return
*/
protected List<IdmIdentityRoleDto> getIdentityRoles(IdmIdentityProjectionDto dto, BasePermission... permission) {
// check all assigned roles has to be loaded
IdmIdentityDto identity = dto.getIdentity();
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
ConfigurationMap properties = formProjection.getProperties();
//
if (// backward compatible
properties.containsKey(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES) && !properties.getBooleanValue(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES)) {
LOG.debug("Projection [{}] does not load all assigned roles.", formProjection.getCode());
//
return Lists.newArrayList();
}
}
//
// load all assigned identity roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
//
return Lists.newArrayList(identityRoleService.find(filter, null, permission).getContent());
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method removeAutomaticRolesInternal.
@Override
@Transactional
public void removeAutomaticRolesInternal(UUID contractId, Set<AbstractIdmAutomaticRoleDto> automaticRoles) {
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
// Identity id is get from embedded identity role. This is little speedup.
UUID identityId = null;
for (AbstractIdmAutomaticRoleDto autoRole : automaticRoles) {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(contractId);
identityRoleFilter.setAutomaticRoleId(autoRole.getId());
// TODO: possible performance update with pageable
for (IdmIdentityRoleDto identityRole : identityRoleService.find(identityRoleFilter, null).getContent()) {
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setIdentityContract(contractId);
concept.setRole(autoRole.getRole());
concept.setAutomaticRole(autoRole.getId());
concept.setIdentityRole(identityRole.getId());
concept.setOperation(ConceptRoleRequestOperation.REMOVE);
concepts.add(concept);
if (identityId == null) {
IdmIdentityContractDto contractDto = DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract, IdmIdentityContractDto.class);
identityId = contractDto.getIdentity();
}
}
}
//
// Execute concepts
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setConceptRoles(concepts);
roleRequest.setApplicant(identityId);
roleRequest = roleRequestService.startConcepts(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest), null);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityAndContractEav.
@Test
public void testAssignAutomaticRoleIdentityAndContractEav() throws Exception {
UUID identityId = null;
try {
getHelper().enableAsynchronousProcessing();
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
IdmRoleDto roleContract = getHelper().createRole();
IdmRoleDto subRoleContract = getHelper().createRole();
getHelper().createRoleComposition(roleContract, subRoleContract);
//
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
//
IdmFormAttributeDto formAttributeContract = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinitionContract = formService.createDefinition(IdmIdentityContractDto.class, getHelper().createName(), Lists.newArrayList(formAttributeContract));
formAttributeContract = formDefinitionContract.getMappedAttributeByCode(formAttributeContract.getCode());
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
IdmAutomaticRoleAttributeDto automaticRoleContract = getHelper().createAutomaticRole(roleContract.getId());
getHelper().createAutomaticRoleRule(automaticRoleContract.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, formAttributeContract.getId(), "mockContract");
// form projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES, false);
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
FormDefinitionAttributes attributes = new FormDefinitionAttributes();
attributes.setDefinition(formDefinition.getId());
attributes.getAttributes().add(formAttributeOne.getId());
FormDefinitionAttributes attributesContract = new FormDefinitionAttributes();
attributesContract.setDefinition(formDefinitionContract.getId());
attributesContract.getAttributes().add(formAttributeContract.getId());
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.setFormDefinitions(mapper.writeValueAsString(Lists.newArrayList(attributes, attributesContract)));
formProjection = projectionService.save(formProjection);
//
// prepare identity projection with two contract
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(formProjection.getId());
IdmFormValueDto formValue = new IdmFormValueDto(formAttributeOne);
formValue.setValue("mockOne");
identity.getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
contractOne.setPosition(getHelper().createName());
IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
contractTwo.setPosition(getHelper().createName());
IdmFormValueDto formValueContract = new IdmFormValueDto(formAttributeContract);
formValueContract.setValue("mockContract");
contractTwo.getEavs().add(new IdmFormInstanceDto(contractTwo, formDefinitionContract, Lists.newArrayList(formValueContract)));
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(contractOne);
projection.setOtherContracts(Lists.newArrayList(contractTwo));
//
// create by projection
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
identityId = createdProjection.getIdentity().getId();
Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
IdmIdentityContractDto primeContract = createdProjection.getContract();
Assert.assertNotNull(primeContract);
Assert.assertEquals(contractOne.getPosition(), primeContract.getPosition());
Assert.assertEquals(1, createdProjection.getOtherContracts().size());
IdmIdentityContractDto otherContract = createdProjection.getOtherContracts().get(0);
Assert.assertEquals(contractTwo.getPosition(), otherContract.getPosition());
//
// 6 roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(createdProjection.getIdentity().getId());
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 6;
});
List<IdmIdentityRoleDto> identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(6, identityRoles.size());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(role.getId())).count());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(subRole.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
//
// change eav value => remove all automatic roles
formValue.setValue("mockUpdate");
createdProjection.getIdentity().getEavs().clear();
createdProjection.getIdentity().getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 2;
});
//
identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertEquals(2, identityRoles.size());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(roleContract.getId())).count());
Assert.assertEquals(1, identityRoles.stream().filter(ir -> ir.getRole().equals(subRoleContract.getId())).count());
} finally {
getHelper().disableAsynchronousProcessing();
getHelper().deleteIdentity(identityId);
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testAssignAutomaticRoleIdentityEav.
@Test
public void testAssignAutomaticRoleIdentityEav() throws Exception {
UUID identityId = null;
try {
getHelper().enableAsynchronousProcessing();
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
//
IdmFormAttributeDto formAttributeOne = new IdmFormAttributeDto(getHelper().createName());
IdmFormDefinitionDto formDefinition = formService.createDefinition(IdmIdentityDto.class, getHelper().createName(), Lists.newArrayList(formAttributeOne));
formAttributeOne = formDefinition.getMappedAttributeByCode(formAttributeOne.getCode());
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeOne.getId(), "mockOne");
//
// prepare identity projection with two contract
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
IdmFormValueDto formValue = new IdmFormValueDto(formAttributeOne);
formValue.setValue("mockOne");
identity.getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
contractOne.setPosition(getHelper().createName());
IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
contractTwo.setPosition(getHelper().createName());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(contractOne);
projection.setOtherContracts(Lists.newArrayList(contractTwo));
//
// create by projection
projection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
identityId = createdProjection.getId();
Assert.assertEquals(identity.getUsername(), createdProjection.getIdentity().getUsername());
IdmIdentityContractDto primeContract = createdProjection.getContract();
Assert.assertNotNull(primeContract);
Assert.assertEquals(contractOne.getPosition(), primeContract.getPosition());
Assert.assertEquals(1, createdProjection.getOtherContracts().size());
IdmIdentityContractDto otherContract = createdProjection.getOtherContracts().get(0);
Assert.assertEquals(contractTwo.getPosition(), otherContract.getPosition());
//
// 4 roles on each contract (2x role + sub) => role is assigned to each contract
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(createdProjection.getIdentity().getId());
getHelper().waitForResult(res -> {
return identityRoleService.find(filter, null).getContent().size() != 4;
});
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(4, identityRoles.size());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(role.getId())).count());
Assert.assertEquals(2, identityRoles.stream().filter(ir -> ir.getRole().equals(subRole.getId())).count());
//
// change eav value => remove all automatic roles
formValue.setValue("mockUpdate");
createdProjection.getIdentity().getEavs().clear();
createdProjection.getIdentity().getEavs().add(new IdmFormInstanceDto(identity, formDefinition, Lists.newArrayList(formValue)));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, createdProjection)).getContent();
getHelper().waitForResult(res -> {
return !identityRoleService.find(filter, null).getContent().isEmpty();
});
//
identityRoles = Lists.newArrayList(identityRoleService.find(filter, null).getContent());
Assert.assertTrue(identityRoles.isEmpty());
} finally {
getHelper().disableAsynchronousProcessing();
getHelper().deleteIdentity(identityId);
}
}
Aggregations