Search in sources :

Example 26 with AccAccountFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.

the class ChangesOnSystemReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    // get system related configuration
    MultiValueMap<String, UUID> configuration = parseAttributeConfig(report);
    SysSystemDto systemDto = getSystemById(configuration.getFirst(PARAMETER_SYSTEM));
    SysSystemMappingDto systemMapping = getSystemMappingById(configuration.getFirst(PARAMETER_SYSTEM_MAPPING));
    List<SysSystemAttributeMappingDto> attributes = getAttributesById(configuration.get(PARAMETER_MAPPING_ATTRIBUTES), systemMapping);
    List<String> selectedAttributeNames = getSelectedAttributeNames(attributes).stream().sorted().collect(Collectors.toList());
    // list of identities to report
    Set<UUID> identities = getReportedIdentities(report);
    boolean skipUnchangedMultivalue = getSkipUnchangedValues(report);
    AccAccountFilter filterAccount = new AccAccountFilter();
    filterAccount.setSystemId(systemDto.getId());
    filterAccount.setEntityType(SystemEntityType.IDENTITY);
    File temp = getAttachmentManager().createTempFile();
    try (FileOutputStream outputStream = new FileOutputStream(temp)) {
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // start of root object
            jGenerator.writeStartObject();
            // write attribute names
            jGenerator.writeFieldName(ATTRIBUTE_NAME_JSON_KEY);
            getMapper().writeValue(jGenerator, selectedAttributeNames);
            // create and write records
            jGenerator.writeFieldName(RECORDS_JSON_KEY);
            jGenerator.writeStartArray();
            createReportData(jGenerator, filterAccount, identities, systemDto.getId(), selectedAttributeNames, skipUnchangedMultivalue);
            jGenerator.writeEndArray();
            // end of root object
            jGenerator.writeEndObject();
        } finally {
            jGenerator.close();
        }
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException e) {
        throw new ReportGenerateException(report.getName(), e);
    } finally {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) FileInputStream(java.io.FileInputStream) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UUID(java.util.UUID) File(java.io.File)

Example 27 with AccAccountFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.

the class SystemDeleteBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    IdmBulkActionDto action = getAction();
    List<UUID> entities = getEntities(action, new StringBuilder());
    ResultModels result = new ResultModels();
    Map<ResultModel, Long> models = new HashMap<>();
    entities.forEach(systemId -> {
        AccAccountFilter accountFilter = new AccAccountFilter();
        accountFilter.setSystemId(systemId);
        SysSystemDto system = getService().get(systemId);
        long count = accountService.count(accountFilter);
        if (count > 0) {
            models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_ACCOUNTS, ImmutableMap.of("system", system.getCode(), "count", count)), count);
        }
        SysProvisioningOperationFilter operationFilter = new SysProvisioningOperationFilter();
        operationFilter.setSystemId(system.getId());
        long countEntities = provisioningOperationService.count(operationFilter);
        if (countEntities > 0) {
            models.put(new DefaultResultModel(AccResultCode.SYSTEM_DELETE_BULK_ACTION_NUMBER_OF_PROVISIONINGS, ImmutableMap.of("system", system.getCode(), "count", countEntities)), countEntities);
        }
    });
    // Sort by count
    List<Entry<ResultModel, Long>> collect = // 
    models.entrySet().stream().sorted(// 
    Collections.reverseOrder(Map.Entry.comparingByValue())).collect(// 
    Collectors.toList());
    collect.forEach(entry -> {
        result.addInfo(entry.getKey());
    });
    return result;
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Entry(java.util.Map.Entry) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) UUID(java.util.UUID)

Example 28 with AccAccountFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.

the class RoleSynchronizationExecutor method assignMissingIdentityRoles.

/**
 * Assign missing identity roles.
 */
private void assignMissingIdentityRoles(IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, List<IdmIdentityRoleDto> existsIdentityRoleDtos, Set<UUID> membersContractIds, SysSystemDto userSystemDto, int[] count, String uid, SynchronizationContext context) {
    // On every 20th item will be hibernate flushed and check if sync was not ended.
    if (count[0] % 20 == 0 && count[0] > 0) {
        if (!checkForCancelAndFlush(config)) {
            return;
        }
    }
    count[0]++;
    // Need to find account using SysSystemEntityDto uid, because uid of AccAccountDto can be different.
    SysSystemEntityFilter entityFilter = new SysSystemEntityFilter();
    entityFilter.setEntityType(SystemEntityType.IDENTITY);
    entityFilter.setSystemId(userSystemDto.getId());
    entityFilter.setUid(uid);
    SysSystemEntityDto systemEntity = systemEntityService.find(entityFilter, null).stream().findFirst().orElse(null);
    if (systemEntity == null) {
        return;
    }
    AccAccountFilter accAccountFilter = new AccAccountFilter();
    accAccountFilter.setSystemEntityId(systemEntity.getId());
    final UUID accAccountId = accountService.findIds(accAccountFilter, null).stream().findFirst().orElse(null);
    if (accAccountId == null) {
        return;
    }
    AccIdentityAccountFilter identityAccountWithoutRelationFilter = new AccIdentityAccountFilter();
    identityAccountWithoutRelationFilter.setAccountId(accAccountId);
    AccIdentityAccountDto identityAccountDto = identityAccountService.find(identityAccountWithoutRelationFilter, null).getContent().stream().findFirst().orElse(null);
    if (identityAccountDto == null) {
        return;
    }
    UUID identityId = identityAccountDto.getIdentity();
    IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identityId);
    if (primeContract == null) {
        addToItemLog(logItem, MessageFormat.format("!!Role was not assigned to the user [{0}], because primary contract was not found!!", uid));
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, context.getLog(), context.getActionLogs());
        return;
    }
    membersContractIds.add(primeContract.getId());
    IdmIdentityRoleDto existIdentityRoleDto = existsIdentityRoleDtos.stream().filter(identityRole -> primeContract.getId().equals(identityRole.getIdentityContract())).findFirst().orElse(null);
    if (existIdentityRoleDto != null) {
        // Identity already has the role.
        return;
    }
    addToItemLog(logItem, MessageFormat.format("Role is not assigned for user [{0}] and contract [{1}]. Role request for add role will be created.", uid, primeContract.getId()));
    // Get cache with role-requests by identity-contract.
    Map<UUID, UUID> roleRequestCache = getRoleRequestCache();
    // Get role-request for the primary contract from a cache. If no request is present, then create one.
    initRoleRequest(primeContract, roleRequestCache, config);
    UUID roleRequestId = roleRequestCache.get(primeContract.getId());
    IdmRoleRequestDto mockRoleRequest = new IdmRoleRequestDto();
    mockRoleRequest.setId(roleRequestId);
    // Create a concept for assign a role to primary contract.
    roleRequestService.createConcept(mockRoleRequest, primeContract, null, roleDto.getId(), ConceptRoleRequestOperation.ADD);
}
Also used : AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 29 with AccAccountFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemEntityService method deleteInternal.

@Override
@Transactional
public void deleteInternal(SysSystemEntityDto systemEntity) {
    Assert.notNull(systemEntity, "System entity is required.");
    // 
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemId(systemEntity.getSystem());
    filter.setEntityType(systemEntity.getEntityType());
    filter.setSystemEntity(systemEntity.getId());
    // TODO: transform this behavior to events
    if (provisioningOperationService.count(filter) > 0) {
        SysSystemDto system = DtoUtils.getEmbedded(systemEntity, SysSystemEntity_.system);
        throw new ResultCodeException(AccResultCode.SYSTEM_ENTITY_DELETE_FAILED_HAS_OPERATIONS, ImmutableMap.of("uid", systemEntity.getUid(), "system", system.getName()));
    }
    // 
    // clear accounts - only link, can be rebuild
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setSystemEntityId(systemEntity.getId());
    accountService.find(accountFilter, null).forEach(account -> {
        account.setSystemEntity(null);
        accountService.save(account);
    });
    // 
    // clear batches
    SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
    if (batch != null) {
        batchService.delete(batch);
    }
    // 
    super.deleteInternal(systemEntity);
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with AccAccountFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.

the class AbstractPasswordFilterIntegrationTest method getAccount.

protected AccAccountDto getAccount(IdmIdentityDto identity, SysSystemDto system) {
    AccAccountFilter accountFilter = new AccAccountFilter();
    accountFilter.setIdentityId(identity.getId());
    accountFilter.setSystemId(system.getId());
    accountFilter.setIncludeEcho(Boolean.TRUE);
    List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
    if (CollectionUtils.isEmpty(accounts)) {
        return null;
    }
    assertEquals(1, accounts.size());
    return accounts.get(0);
}
Also used : AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto)

Aggregations

AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)45 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)33 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)21 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)18 Test (org.junit.Test)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)12 UUID (java.util.UUID)11 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)6 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)6 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)6 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4