Search in sources :

Example 51 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractReadDtoService method toDtos.

/**
 * Converts list of entities to list of DTOs.
 * Method check returned value from method {@link AbstractReadDtoService#supportsToDtoWithFilter()}.
 * If the method {@link AbstractReadDtoService#supportsToDtoWithFilter()} return true
 * the method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto, BaseFilter)} will be called.
 * Otherwise will be called method {@link AbstractReadDtoService#toDto(BaseEntity, BaseDto)}.
 *
 * @param entities
 * @param trimmed
 * @param filter
 * @return
 */
protected List<DTO> toDtos(List<E> entities, boolean trimmed, F filter) {
    if (entities == null) {
        return null;
    }
    List<DTO> dtos = new ArrayList<>();
    entities.forEach(entity -> {
        try {
            DTO newDto = this.getDtoClass(entity).getDeclaredConstructor().newInstance();
            if (newDto instanceof AbstractDto) {
                ((AbstractDto) newDto).setTrimmed(trimmed);
            }
            DTO dto = null;
            // Check if service support filter mapping and use it for transform entity to DTO
            if (supportsToDtoWithFilter()) {
                dto = this.toDto(entity, newDto, filter);
            } else {
                dto = this.toDto(entity, newDto);
            }
            dtos.add(dto);
        } catch (ReflectiveOperationException ex) {
            throw new CoreException(ex);
        }
    });
    return dtos;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ArrayList(java.util.ArrayList)

Example 52 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class RequestApprovalProcessor method process.

@SuppressWarnings("unchecked")
@Override
public EventResult<IdmRequestDto> process(EntityEvent<IdmRequestDto> event) {
    IdmRequestDto dto = event.getContent();
    boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
    // 
    String ownerTyp = dto.getOwnerType();
    Assert.notNull(ownerTyp, "Owner type is rquired for start approval process!");
    Class<Requestable> ownerClass = null;
    try {
        ownerClass = (Class<Requestable>) Class.forName(ownerTyp);
    } catch (ClassNotFoundException e) {
        throw new CoreException(e);
    }
    String wfDefinition = requestConfiguration.getRequestApprovalProcessKey(ownerClass);
    if (Strings.isNullOrEmpty(wfDefinition)) {
        throw new ResultCodeException(CoreResultCode.REQUEST_NO_WF_DEF_FOUND, ImmutableMap.of("entityType", dto.getOwnerType()));
    }
    boolean approved = manager.startApprovalProcess(dto, checkRight, event, wfDefinition);
    DefaultEventResult<IdmRequestDto> result = new DefaultEventResult<>(event, this);
    result.setSuspended(!approved);
    return result;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)

Example 53 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManager method getTask.

/**
 * Returns task by given key
 *
 * @param jobKey
 * @return task dto
 */
@SuppressWarnings("unchecked")
private Task getTask(JobKey jobKey) {
    try {
        JobDetail jobDetail = scheduler.getJobDetail(jobKey);
        if (jobDetail == null) {
            // job does not exists
            return null;
        }
        Task task = new Task();
        // task setting
        task.setId(jobKey.getName());
        // app context is needed here
        SchedulableTaskExecutor<?> taskExecutor = (SchedulableTaskExecutor<?>) context.getAutowireCapableBeanFactory().createBean(jobDetail.getJobClass());
        task.setTaskType((Class<? extends SchedulableTaskExecutor<?>>) AutowireHelper.getTargetClass(taskExecutor));
        task.setDescription(jobDetail.getDescription());
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        task.setInstanceId(jobDataMap.getString(SchedulableTaskExecutor.PARAMETER_INSTANCE_ID));
        task.setModified((ZonedDateTime) jobDataMap.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
        task.setTriggers(new ArrayList<>());
        // task properties
        for (Entry<String, Object> entry : jobDataMap.entrySet()) {
            task.getParameters().put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString());
        }
        task.setDisabled(taskExecutor.isDisabled());
        if (!task.isDisabled()) {
            task.setSupportsDryRun(taskExecutor.supportsDryRun());
            task.setFormDefinition(taskExecutor.getFormDefinition());
            task.setRecoverable(taskExecutor.isRecoverable());
        } else {
            LOG.warn("Task [{}] is disabled and cannot be executed, remove schedule for this task to hide this warning.", task.getTaskType().getSimpleName());
        }
        // scheduled triggers - native
        for (Trigger trigger : scheduler.getTriggersOfJob(jobKey)) {
            TriggerState state = scheduler.getTriggerState(trigger.getKey());
            if (trigger instanceof CronTrigger) {
                task.getTriggers().add(new CronTaskTrigger(task.getId(), (CronTrigger) trigger, TaskTriggerState.convert(state)));
            } else if (trigger instanceof SimpleTrigger) {
                task.getTriggers().add(new SimpleTaskTrigger(task.getId(), (SimpleTrigger) trigger, TaskTriggerState.convert(state)));
            } else {
                LOG.warn("Job '{}' ({}) has registered trigger of unsupported type {}", jobKey, jobDetail.getJobClass(), trigger);
            }
        }
        // dependent tasks
        dependentTaskTriggerRepository.findByDependentTaskId(jobKey.getName()).forEach(dependentTask -> {
            task.getTriggers().add(new DependentTaskTrigger(task.getId(), dependentTask.getId(), dependentTask.getInitiatorTaskId()));
        });
        return task;
    } catch (org.quartz.SchedulerException ex) {
        if (ex.getCause() instanceof ClassNotFoundException) {
            deleteTask(jobKey.getName());
            LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
            return null;
        }
        throw new CoreException(ex);
    } catch (BeansException | IllegalArgumentException ex) {
        deleteTask(jobKey.getName());
        LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
        return null;
    }
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) JobDataMap(org.quartz.JobDataMap) CronTrigger(org.quartz.CronTrigger) TaskTriggerState(eu.bcvsolutions.idm.core.scheduler.api.dto.TaskTriggerState) TriggerState(org.quartz.Trigger.TriggerState) JobDetail(org.quartz.JobDetail) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) CronTrigger(org.quartz.CronTrigger) AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) SimpleTrigger(org.quartz.SimpleTrigger) SchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulableTaskExecutor) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) BeansException(org.springframework.beans.BeansException)

Example 54 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemAttributeMappingService method resolveFormValue.

/**
 * Resolve form value
 *
 * @param formValue
 * @return
 */
private Object resolveFormValue(IdmFormValueDto formValue) {
    if (formValue == null) {
        return null;
    }
    Serializable value = formValue.getValue();
    // IdmAttachmentWithDataDto.
    if (PersistentType.ATTACHMENT == formValue.getPersistentType() && value instanceof UUID) {
        IdmAttachmentDto attachmentDto = attachmentManager.get((UUID) value);
        // Convert attachment to attachment with data
        IdmAttachmentWithDataDto attachmentWithDataDto = this.convertAttachment(attachmentDto);
        try (InputStream inputStream = attachmentManager.getAttachmentData((UUID) value)) {
            if (inputStream != null) {
                byte[] bytes = IOUtils.toByteArray(inputStream);
                attachmentWithDataDto.setData(bytes);
            }
        } catch (IOException e) {
            throw new CoreException(e);
        }
        return attachmentWithDataDto;
    }
    return value;
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) Serializable(java.io.Serializable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) InputStream(java.io.InputStream) IOException(java.io.IOException) UUID(java.util.UUID) IdmAttachmentWithDataDto(eu.bcvsolutions.idm.acc.domain.IdmAttachmentWithDataDto)

Example 55 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method replaceGuardedStrings.

/**
 * Replaces GuardedStrings as ConfidentialStrings in given {@link ProvisioningContext}.
 *
 * TODO: don't update accountObject in provisioningOperation (needs attribute defensive clone)
 *
 * @param context
 * @return Returns values (key / value) to store in confidential storage.
 */
protected Map<String, Serializable> replaceGuardedStrings(ProvisioningContext context) {
    try {
        Map<String, Serializable> confidentialValues = new HashMap<>();
        if (context == null) {
            return confidentialValues;
        }
        // 
        Map<ProvisioningAttributeDto, Object> accountObject = context.getAccountObject();
        if (accountObject != null) {
            for (Entry<ProvisioningAttributeDto, Object> entry : accountObject.entrySet()) {
                if (entry.getValue() == null) {
                    continue;
                }
                Object idmValue = entry.getValue();
                // single value
                if (idmValue instanceof GuardedString) {
                    GuardedString guardedString = (GuardedString) entry.getValue();
                    // save value into confidential storage
                    String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), 0);
                    confidentialValues.put(confidentialStorageKey, guardedString.asString());
                    accountObject.put(entry.getKey(), new ConfidentialString(confidentialStorageKey));
                } else // array
                if (idmValue.getClass().isArray()) {
                    if (!idmValue.getClass().getComponentType().isPrimitive()) {
                        // objects only, we dont want pto proces byte, boolean etc.
                        Object[] idmValues = (Object[]) idmValue;
                        List<ConfidentialString> processedValues = new ArrayList<>();
                        for (int j = 0; j < idmValues.length; j++) {
                            Object singleValue = idmValues[j];
                            if (singleValue instanceof GuardedString) {
                                GuardedString guardedString = (GuardedString) singleValue;
                                // save value into confidential storage
                                String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), j);
                                confidentialValues.put(confidentialStorageKey, guardedString.asString());
                                processedValues.add(new ConfidentialString(confidentialStorageKey));
                            }
                        }
                        if (!processedValues.isEmpty()) {
                            accountObject.put(entry.getKey(), processedValues.toArray(new ConfidentialString[processedValues.size()]));
                        }
                    }
                } else // collection
                if (idmValue instanceof Collection) {
                    Collection<?> idmValues = (Collection<?>) idmValue;
                    List<ConfidentialString> processedValues = new ArrayList<>();
                    idmValues.forEach(singleValue -> {
                        if (singleValue instanceof GuardedString) {
                            GuardedString guardedString = (GuardedString) singleValue;
                            // save value into confidential storage
                            String confidentialStorageKey = createAccountObjectPropertyKey(entry.getKey().getKey(), processedValues.size());
                            confidentialValues.put(confidentialStorageKey, guardedString.asString());
                            processedValues.add(new ConfidentialString(confidentialStorageKey));
                        }
                    });
                    if (!processedValues.isEmpty()) {
                        accountObject.put(entry.getKey(), processedValues);
                    }
                }
            }
        }
        // 
        IcConnectorObject connectorObject = context.getConnectorObject();
        if (connectorObject != null) {
            for (IcAttribute attribute : connectorObject.getAttributes()) {
                if (attribute.getValues() != null) {
                    for (int j = 0; j < attribute.getValues().size(); j++) {
                        Object attributeValue = attribute.getValues().get(j);
                        if (attributeValue instanceof GuardedString) {
                            GuardedString guardedString = (GuardedString) attributeValue;
                            String confidentialStorageKey = createConnectorObjectPropertyKey(attribute, j);
                            confidentialValues.put(confidentialStorageKey, guardedString.asString());
                            attribute.getValues().set(j, new ConfidentialString(confidentialStorageKey));
                        }
                    }
                }
            }
        }
        // 
        return confidentialValues;
    } catch (Exception ex) {
        throw new CoreException("Replace guarded strings for provisioning operation failed.", ex);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ConfidentialString(eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Collection(java.util.Collection) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6