Search in sources :

Example 1 with AssignedRoleDto

use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto in project CzechIdMng by bcvsolutions.

the class IdentityProvisioningTest method testConvertToAssignedRoleDto.

@Test
public void testConvertToAssignedRoleDto() {
    IdmRoleDto role = helper.createRole();
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role, LocalDate.now(), LocalDate.now().plusDays(1));
    AssignedRoleDto result = IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole);
    assertNotNull(result);
    assertEquals(identityRole.getId(), result.getId());
    assertEquals(identityRole.getValidFrom(), result.getValidFrom());
    assertEquals(identityRole.getValidTill(), result.getValidTill());
    assertEquals(identityRole.getIdentityContract(), result.getIdentityContract().getId());
    assertEquals(identityRole.getRole(), result.getRole().getId());
    assertEquals(identityRole.getDirectRole(), identityRole.getDirectRole() != null ? result.getDirectRole().getId() : null);
    assertEquals(identityRole.getContractPosition(), identityRole.getContractPosition() != null ? result.getContractPosition().getId() : null);
    assertEquals(identityRole.getRoleComposition(), identityRole.getRoleComposition() != null ? result.getRoleComposition().getId() : null);
    assertEquals(identityRole.getAutomaticRole(), identityRole.getAutomaticRole() != null ? result.getRoleTreeNode().getId() : null);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AssignedRoleDto(eu.bcvsolutions.idm.acc.domain.AssignedRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with AssignedRoleDto

use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto 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);
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) ArrayList(java.util.ArrayList) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AssignedRoleDto(eu.bcvsolutions.idm.acc.domain.AssignedRoleDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 3 with AssignedRoleDto

use of eu.bcvsolutions.idm.acc.domain.AssignedRoleDto in project CzechIdMng by bcvsolutions.

the class IdentityProvisioningExecutor method convertToAssignedRoleDto.

public static AssignedRoleDto convertToAssignedRoleDto(IdmIdentityRoleDto identityRole) {
    if (identityRole == null) {
        return null;
    }
    AssignedRoleDto dto = new AssignedRoleDto();
    dto.setId(identityRole.getId());
    dto.setExternalId(identityRole.getExternalId());
    dto.setValidFrom(identityRole.getValidFrom());
    dto.setValidTill(identityRole.getValidTill());
    dto.setRole(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.role, IdmRoleDto.class, null));
    dto.setIdentityContract(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.identityContract, IdmIdentityContractDto.class, null));
    dto.setContractPosition(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.contractPosition, IdmContractPositionDto.class, null));
    dto.setDirectRole(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.directRole, IdmIdentityRoleDto.class, null));
    dto.setRoleTreeNode(DtoUtils.getEmbedded(identityRole, IdmIdentityRoleDto.PROPERTY_ROLE_TREE_NODE, AbstractIdmAutomaticRoleDto.class, null));
    dto.setRoleComposition(DtoUtils.getEmbedded(identityRole, IdmIdentityRole_.roleComposition, IdmRoleCompositionDto.class, null));
    UUID definition = dto.getRole().getIdentityRoleAttributeDefinition();
    if (definition != null) {
        // Definition for role attributes exists
        IdmFormInstanceDto formInstanceDto = // 
        identityRole.getEavs().stream().filter(// 
        formInstance -> definition.equals(formInstance.getFormDefinition().getId())).findFirst().orElse(null);
        if (formInstanceDto != null) {
            List<IdmFormValueDto> values = formInstanceDto.getValues();
            // Search all attributes
            values.stream().map(// 
            IdmFormValueDto::getFormAttribute).distinct().forEach(attribute -> {
                List<IdmFormValueDto> formValues = // Search all values for one attribute
                values.stream().filter(// 
                value -> attribute.equals(value.getFormAttribute())).collect(// 
                Collectors.toList());
                IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(formValues.get(0), IdmFormValue_.formAttribute, IdmFormAttributeDto.class);
                dto.getAttributes().put(formAttributeDto.getCode(), // 
                formValues.stream().map(// Value is always list
                IdmFormValueDto::getValue).collect(// 
                Collectors.toList()));
            });
        }
    }
    return dto;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) ProvisioningExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningExecutor) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) AccIdentityAccount_(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount_) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Sort(org.springframework.data.domain.Sort) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) CollectionUtils(org.springframework.util.CollectionUtils) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttribute_(eu.bcvsolutions.idm.acc.entity.SysRoleSystemAttribute_) ArrayList(java.util.ArrayList) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) AssignedRoleDto(eu.bcvsolutions.idm.acc.domain.AssignedRoleDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) IdmFormValue_(eu.bcvsolutions.idm.core.eav.entity.IdmFormValue_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Assert(org.springframework.util.Assert) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) AssignedRoleDto(eu.bcvsolutions.idm.acc.domain.AssignedRoleDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Aggregations

AssignedRoleDto (eu.bcvsolutions.idm.acc.domain.AssignedRoleDto)3 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)3 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)2 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)2 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)2 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)2 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)2 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)2 Lists (com.google.common.collect.Lists)1 AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)1 AttributeMappingStrategyType (eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType)1 MappingContext (eu.bcvsolutions.idm.acc.domain.MappingContext)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 EntityAccountDto (eu.bcvsolutions.idm.acc.dto.EntityAccountDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1