Search in sources :

Example 61 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel 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 62 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class RoleAccountManagementBulkAction 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(roleId -> {
        IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
        identityRoleFilter.setRoleId(roleId);
        IdmRoleDto role = getService().get(roleId);
        long count = identityRoleService.find(identityRoleFilter, PageRequest.of(0, 1)).getTotalElements();
        if (count > 0) {
            models.put(new DefaultResultModel(AccResultCode.ROLE_ACM_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
        }
    });
    boolean someIdentitiesFound = // 
    models.values().stream().filter(// 
    count -> count > 0).findFirst().isPresent();
    if (!someIdentitiesFound) {
        result.addInfo(new DefaultResultModel(AccResultCode.ROLE_ACM_BULK_ACTION_NONE_IDENTITIES));
    } else {
        // Sort by count
        List<Entry<ResultModel, Long>> collect = // 
        models.entrySet().stream().sorted(// 
        Collections.reverseOrder(Map.Entry.comparingByValue())).limit(// 
        5).collect(// 
        Collectors.toList());
        collect.forEach(entry -> {
            result.addInfo(entry.getKey());
        });
    }
    return result;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Entry(java.util.Map.Entry) UUID(java.util.UUID)

Example 63 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class DefaultUniformPasswordManager method generateUniformPassword.

@Override
@Transactional
public GuardedString generateUniformPassword(UUID entityIdentifier, Class<? extends AbstractDto> entityType, UUID transactionId) {
    Assert.notNull(transactionId, "Transaction cannot be null!");
    Assert.notNull(entityIdentifier, "Entity identifier cannot be null!");
    Assert.notNull(entityType, "Entity type cannot be null!");
    IdmEntityStateDto entityStateDto = this.getEntityState(entityIdentifier, entityType, transactionId);
    if (entityStateDto != null) {
        GuardedString password = getPassword(entityStateDto);
        if (password == null || password.getValue().length == 0) {
            // TODO: how to generate password for all system policies.
            password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
            confidentialStorage.saveGuardedString(entityStateDto, UNIFORM_PASSWORD_KEY, password);
        }
        // The uniform password was used, we need to mark it.
        Map<String, Object> parameters = entityStateDto.getResult().getModel().getParameters();
        HashMap<String, Object> newParameters = Maps.newHashMap(parameters);
        newParameters.put(PASSWORD_USED, Boolean.TRUE);
        entityStateDto.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
        entityStateManager.saveState(null, entityStateDto);
        return password;
    }
    return null;
}
Also used : IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class AbstractExportBulkAction method addAttachmentMetadata.

/**
 * Adds attachment metadata to the operation result (for download attachment
 * directly from bulk action modal dialog).
 *
 * @param result
 */
private void addAttachmentMetadata(OperationResult result) {
    IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId());
    OperationResult taskResult = task.getResult();
    if (OperationState.EXECUTED == taskResult.getState()) {
        ResultModel model = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD, // 
        ImmutableMap.of(AttachableEntity.PARAMETER_DOWNLOAD_URL, MessageFormat.format("export-imports/{0}/download", batch.getId()), // 
        AttachableEntity.PARAMETER_OWNER_ID, // 
        batch.getId(), // 
        AttachableEntity.PARAMETER_OWNER_TYPE, // 
        batch.getClass().getName()));
        // 
        taskResult.setModel(model);
        getLongRunningTaskService().save(task);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel)

Example 65 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class AbstractBulkAction method createPermissionFailedLog.

/**
 * Create failed log for given dto with exception for insufficient permission
 *
 * @param dto
 */
protected void createPermissionFailedLog(DTO dto) {
    String entityCode = "";
    if (dto instanceof Codeable) {
        entityCode = ((Codeable) dto).getCode();
    }
    DefaultResultModel model = new DefaultResultModel(CoreResultCode.BULK_ACTION_INSUFFICIENT_PERMISSION, ImmutableMap.of("bulkAction", this.getAction().getName(), "entityId", dto.getId(), "entityCode", entityCode));
    // 
    this.logItemProcessed(dto, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)104 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)52 UUID (java.util.UUID)48 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)40 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)35 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)25 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)24 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 HashMap (java.util.HashMap)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)16 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)15 List (java.util.List)15 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13