use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningExecutor method getAttributeValue.
@Override
protected Object getAttributeValue(String uid, IdmIdentityDto dto, AttributeMapping attribute, SysSystemDto system, MappingContext mappingContext) {
if (attribute instanceof SysRoleSystemAttributeDto) {
SysRoleSystemAttributeDto roleSystemAttributeDto = (SysRoleSystemAttributeDto) attribute;
if (roleSystemAttributeDto.isSkipValueIfExcluded() && (AttributeMappingStrategyType.MERGE == roleSystemAttributeDto.getStrategyType() || AttributeMappingStrategyType.AUTHORITATIVE_MERGE == roleSystemAttributeDto.getStrategyType())) {
// Get ID of the role
Assert.notNull(roleSystemAttributeDto.getRoleSystem(), "SysRoleSystem cannot be null!");
SysRoleSystemDto roleSystemDto = DtoUtils.getEmbedded(roleSystemAttributeDto, SysRoleSystemAttribute_.roleSystem.getName(), SysRoleSystemDto.class, (SysRoleSystemDto) null);
if (roleSystemDto == null) {
roleSystemDto = roleSystemService.get(roleSystemAttributeDto.getId());
}
UUID roleId = roleSystemDto.getRole();
Assert.notNull(roleId, "Role cannot be null!");
// Find count of NOT excluded contracts for this identity and role
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setIdentity(dto.getId());
contractFilter.setExcluded(Boolean.FALSE);
contractFilter.setRoleId(roleId);
// If exists some not excluded contract, then value will be not skipped!
long countOfNotExcludedContracts = identityContractService.count(contractFilter);
if (countOfNotExcludedContracts == 0) {
contractFilter.setExcluded(Boolean.TRUE);
// For skip the value must exist at least one excluded contract
long countOfexcludedContracts = identityContractService.count(contractFilter);
if (countOfexcludedContracts >= 0) {
return null;
}
}
}
}
// identity-roles). That list will be input for that fields.
if (//
attribute != null && (//
ASSIGNED_ROLES_FIELD.equals(attribute.getIdmPropertyName()) || //
ASSIGNED_ROLES_FOR_SYSTEM_FIELD.equals(attribute.getIdmPropertyName()))) {
//
assertNotNull(dto.getId());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(dto.getId());
identityRoleFilter.setValid(Boolean.TRUE);
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
List<IdmIdentityRoleDto> identityRolesToProcess;
if (ASSIGNED_ROLES_FOR_SYSTEM_FIELD.equals(attribute.getIdmPropertyName())) {
// For ASSIGNED_ROLES_FOR_SYSTEM_FIELD we will convert only identity-roles for
// that identity and given system
assertNotNull(system.getId());
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 that system
identityAccounts.forEach(identityAccount -> {
identityRolesForSystem.addAll(//
identityRoles.stream().filter(//
identityRole -> identityRole.getId().equals(identityAccount.getIdentityRole())).collect(//
Collectors.toList()));
});
identityRolesToProcess = identityRolesForSystem;
} else {
// For ASSIGNED_ROLES_FIELD we will convert all identity-roles for that identity
identityRolesToProcess = identityRoles;
}
List<AssignedRoleDto> assignedRoles = new ArrayList<>();
identityRolesToProcess.forEach(identityRole -> {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
identityRole.getEavs().clear();
identityRole.getEavs().add(formInstanceDto);
// Convert identityRole to AssignedRoleDto
assignedRoles.add(IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole));
});
return attributeMappingService.transformValueToResource(uid, assignedRoles, attribute, dto);
}
// For user-type (projection) will be attribute value IdmFormProjectionDto.
if (attribute != null && dto != null && dto.getFormProjection() != null && IdmIdentity_.formProjection.getName().equals(attribute.getIdmPropertyName())) {
BaseDto projection = lookupService.lookupEmbeddedDto(dto, IdmIdentity_.formProjection);
return attributeMappingService.transformValueToResource(uid, projection, attribute, dto);
}
// Default transformation of Identity state enum to string
if (attribute != null && dto != null && IDENTITY_STATE_IDM_NAME.equals(attribute.getIdmPropertyName())) {
String state = dto.getState().toString();
return attributeMappingService.transformValueToResource(uid, state, attribute, dto);
}
return super.getAttributeValue(uid, dto, attribute, system, mappingContext);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testCreateIdentityWithAutomaticRoleByEavAttribute.
@Test
public void testCreateIdentityWithAutomaticRoleByEavAttribute() {
String username = getHelper().createName();
SysSystemDto system = initData(username, "mockIdentity@idm.eu");
Assert.assertNotNull(system);
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
config.setCreateDefaultContract(true);
config.setStartAutoRoleRec(true);
syncConfigService.save(config);
//
// create form definition, roles, automatic role etc.
IdmRoleDto role = getHelper().createRole();
IdmRoleDto subRole = getHelper().createRole();
getHelper().createRoleComposition(role, subRole);
// sync supports default definition only
IdmFormAttributeDto formAttribute = new IdmFormAttributeDto(getHelper().createName());
IdmFormAttributeDto formAttributeIdentity = formService.saveAttribute(IdmIdentityDto.class, formAttribute);
//
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, formAttributeIdentity.getId(), "mockIdentity@idm.eu");
//
// create mapping to eav attribute - leader = eav
SysSystemMappingDto syncSystemMapping = systemMappingService.get(config.getSystemMapping());
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(syncSystemMapping.getId());
SysSystemAttributeMappingDto lastnameAttributeMapping = schemaAttributeMappingService.findBySystemMappingAndName(syncSystemMapping.getId(), ATTRIBUTE_EMAIL);
lastnameAttributeMapping.setEntityAttribute(false);
lastnameAttributeMapping.setExtendedAttribute(true);
lastnameAttributeMapping.setIdmPropertyName(formAttributeIdentity.getCode());
schemaAttributeMappingService.save(lastnameAttributeMapping);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setUsername(username);
identityFilter.setAddEavMetadata(Boolean.TRUE);
List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals("mockIdentity@idm.eu", identities.get(0).getEavs().stream().filter(fi -> fi.getFormDefinition().isMain()).findFirst().get().getValues().stream().filter(v -> v.getFormAttribute().equals(formAttributeIdentity.getId())).findFirst().get().getShortTextValue());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identities.get(0).getId());
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(2, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(role.getId())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getRole().equals(subRole.getId())));
// Delete log
syncLogService.delete(log);
syncConfigService.delete(config);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method testInvalidateAndCreateAnotherContractWithAutomaticRoles.
@Test
public void testInvalidateAndCreateAnotherContractWithAutomaticRoles() {
SysSystemDto system = initData();
SysSystemDto systemProvisioning = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
contractService.delete(getHelper().getPrimeContract(identity));
//
// create first contract with validity and automatic role
String positionCode = getHelper().createName();
IdmTreeNodeDto node = getHelper().createTreeNode();
IdmRoleDto role = getHelper().createRole();
helper.createRoleSystem(role, systemProvisioning);
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.setIdentity(identity.getId());
Assert.assertEquals(1, contractService.find(contractFilter, null).getTotalElements());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.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 - invalid
TestContractResource invalidContractResource = new TestContractResource();
invalidContractResource.setId(positionCode);
invalidContractResource.setName(positionCode);
invalidContractResource.setOwner(identity.getUsername());
invalidContractResource.setMain(Boolean.TRUE.toString());
invalidContractResource.setWorkposition(node.getId().toString());
invalidContractResource.setDescription(positionCode);
invalidContractResource.setValidTill(LocalDate.now().minusDays(1));
this.getBean().createContractData(invalidContractResource);
//
String validPositionCode = getHelper().createName();
TestContractResource validContractResource = new TestContractResource();
validContractResource.setId(validPositionCode);
validContractResource.setName(validPositionCode);
validContractResource.setOwner(identity.getUsername());
validContractResource.setMain(Boolean.FALSE.toString());
validContractResource.setWorkposition(node.getId().toString());
validContractResource.setDescription(validPositionCode);
this.getBean().createContractData(validContractResource);
//
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK_AND_UPDATE_ENTITY, 1);
checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1);
UUID transactionId = log.getTransactionId();
Assert.assertFalse(log.isRunning());
List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().allMatch(c -> c.getTransactionId().equals(transactionId)));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.isValid()));
Assert.assertTrue(contracts.stream().anyMatch(c -> !c.isValid()));
assignedRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Assert.assertEquals(1, assignedRoles.size());
Assert.assertNull(assignedRoles.get(0).getValidFrom());
Assert.assertNull(assignedRoles.get(0).getValidTill());
Assert.assertEquals(transactionId, assignedRoles.get(0).getTransactionId());
// find provisioning archive => prevent drop and create => update only in this transaction id
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(systemProvisioning.getId());
filter.setTransactionId(transactionId);
List<SysProvisioningArchiveDto> executedOperations = provisioningArchiveService.find(filter, null).getContent();
Assert.assertFalse(executedOperations.isEmpty());
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getOperationType() != ProvisioningEventType.DELETE));
Assert.assertTrue(executedOperations.stream().allMatch(o -> o.getResultState() == OperationState.EXECUTED));
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleWorkflowAdSyncTest method n91_testSyncWithWfSituationMissingResolveMember.
@Test
public void n91_testSyncWithWfSituationMissingResolveMember() {
String valueOfMemberAtt = getHelper().createName();
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));
IdmIdentityDto identity = this.getHelper().createIdentity();
IdmFormAttributeDto attribute = helper.createEavAttribute(nameOfEav, IdmIdentity.class, PersistentType.SHORTTEXT);
helper.setEavValue(identity, attribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
SysSystemDto system = initData();
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();
Assert.assertEquals(0, roles.size());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(0, content.size());
Assert.assertNotNull(system);
SysSyncRoleConfigDto config = doCreateSyncConfig(system);
config.setLinkedActionWfKey(wfExampleKey);
config.setMissingAccountActionWfKey(wfExampleKey);
config.setMissingEntityActionWfKey(wfExampleKey);
config.setUnlinkedActionWfKey(wfExampleKey);
config = (SysSyncRoleConfigDto) syncConfigService.save(config);
// Start sync
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.MISSING_ENTITY, 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");
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityRoleControllerRestTest method testFindByRoleComposition.
@Test
public void testFindByRoleComposition() {
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmRoleDto roleThree = getHelper().createRole();
//
IdmRoleCompositionDto roleCompositionOne = getHelper().createRoleComposition(roleOne, roleTwo);
getHelper().createRoleComposition(roleTwo, roleThree);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityRoleDto directRole = getHelper().createIdentityRole(identity, roleOne);
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
filter.setRoleCompositionId(roleCompositionOne.getId());
List<IdmIdentityRoleDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertTrue(results.stream().anyMatch(ir -> ir.getDirectRole().equals(directRole.getId()) && ir.getRole().equals(roleTwo.getId())));
}
Aggregations