Search in sources :

Example 91 with ResultCodeException

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

the class DefaultCryptService method initCipher.

/**
 * Method init {@link Cipher} by encrypt mode {@link Cipher}.
 * Cipher is not thread safe and is not reusable, has to be constructed for all requests.
 *
 * @param encryptMode
 * @param key
 * @throws InvalidKeyException
 */
private Cipher initCipher(int encryptMode, SecretKey key) throws InvalidKeyException {
    if (key == null) {
        return null;
    }
    // 
    Cipher cipher = null;
    try {
        cipher = Cipher.getInstance(ALGORITHM + "/" + ALGORITHM_MODE + "/" + ALGORITHM_PADDING);
        cipher.init(encryptMode, key, new IvParameterSpec(IV));
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
        LOG.error("Cipher can't be initialized!");
        throw new ResultCodeException(CoreResultCode.CRYPT_INITIALIZATION_PROBLEM, ImmutableMap.of("algorithm", ALGORITHM), e);
    }
    return cipher;
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 92 with ResultCodeException

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

the class WorkflowDefinitionController method getDiagram.

/**
 * Generate process definition diagram image
 *
 * @param definitionKey
 * @return
 */
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.WORKFLOW_DEFINITION_READ + "')")
@ApiOperation(value = "Workflow definition diagram", nickname = "getWorkflowDefinitionDiagram", tags = { WorkflowDefinitionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.WORKFLOW_DEFINITION_READ, description = "") }) }, notes = "Returns input stream to definition's diagram.")
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Workflow definition key.", required = true) @PathVariable String backendId) {
    // check rights
    WorkflowProcessDefinitionDto result = definitionService.getByName(backendId);
    if (result == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    InputStream is = definitionService.getDiagramByKey(backendId);
    try {
        return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 93 with ResultCodeException

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

the class WorkflowHistoricProcessInstanceController method getDiagram.

/**
 * Generate process instance diagram image
 *
 * @param historicProcessInstanceId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/diagram", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@ApiOperation(value = "Historic process instance diagram", nickname = "getHistoricProcessInstanceDiagram", response = WorkflowHistoricProcessInstanceDto.class, tags = { WorkflowHistoricProcessInstanceController.TAG })
public ResponseEntity<InputStreamResource> getDiagram(@ApiParam(value = "Historic process instance id.", required = true) @PathVariable @NotNull String backendId) {
    // check rights
    WorkflowHistoricProcessInstanceDto result = workflowHistoricProcessInstanceService.get(backendId);
    if (result == null) {
        throw new ResultCodeException(CoreResultCode.FORBIDDEN);
    }
    InputStream is = workflowHistoricProcessInstanceService.getDiagram(backendId);
    try {
        return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.IMAGE_PNG).body(new InputStreamResource(is));
    } catch (IOException e) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 94 with ResultCodeException

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

the class DefaultWorkflowProcessInstanceService method delete.

@Override
public WorkflowProcessInstanceDto delete(String processInstanceId, String deleteReason) {
    if (processInstanceId == null) {
        return null;
    }
    if (deleteReason == null) {
        deleteReason = "Deleted by " + securityService.getUsername();
    }
    WorkflowFilterDto filter = new WorkflowFilterDto();
    filter.setProcessInstanceId(processInstanceId);
    Collection<WorkflowProcessInstanceDto> resources = this.searchInternal(filter, false).getResources();
    WorkflowProcessInstanceDto processInstanceToDelete = null;
    if (!resources.isEmpty()) {
        processInstanceToDelete = resources.iterator().next();
    }
    if (processInstanceToDelete == null) {
        throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for delete process instance with ID: %s !", ImmutableMap.of("processInstanceId", processInstanceId));
    }
    runtimeService.deleteProcessInstance(processInstanceToDelete.getProcessInstanceId(), deleteReason);
    return processInstanceToDelete;
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Example 95 with ResultCodeException

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

the class IdmEntityEventController method toFilter.

@Override
protected IdmEntityEventFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmEntityEventFilter filter = new IdmEntityEventFilter(parameters);
    filter.setCreatedFrom(getParameterConverter().toDateTime(parameters, "createdFrom"));
    filter.setCreatedTill(getParameterConverter().toDateTime(parameters, "createdTill"));
    filter.setOwnerType(getParameterConverter().toString(parameters, "ownerType"));
    // 
    String ownerId = getParameterConverter().toString(parameters, "ownerId");
    if (StringUtils.isNotEmpty(filter.getOwnerType()) && StringUtils.isNotEmpty(ownerId)) {
        // try to find entity owner by Codeable identifier
        AbstractDto owner = manager.findOwner(filter.getOwnerType(), ownerId);
        if (owner != null) {
            filter.setOwnerId(owner.getId());
        } else {
            throw new ResultCodeException(CoreResultCode.BAD_VALUE, "Entity type [%s] with identifier [%s] does not found", ImmutableMap.of("entityClass", filter.getOwnerType(), "identifier", ownerId));
        }
    } else {
        filter.setOwnerId(getParameterConverter().toUuid(parameters, "ownerId"));
    }
    filter.setStates(getParameterConverter().toEnums(parameters, "states", OperationState.class));
    return filter;
}
Also used : AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmEntityEventFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityEventFilter) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)162 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 ApiOperation (io.swagger.annotations.ApiOperation)47 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)47 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Test (org.junit.Test)31 ResponseEntity (org.springframework.http.ResponseEntity)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)14 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)12 IOException (java.io.IOException)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10