diff --git a/src/main/java/org/folio/rest/camunda/controller/advice/WorkflowControllerAdvice.java b/src/main/java/org/folio/rest/camunda/controller/advice/WorkflowControllerAdvice.java index 37311fef..f733c284 100644 --- a/src/main/java/org/folio/rest/camunda/controller/advice/WorkflowControllerAdvice.java +++ b/src/main/java/org/folio/rest/camunda/controller/advice/WorkflowControllerAdvice.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; import org.folio.rest.camunda.exception.WorkflowAlreadyActiveException; +import org.folio.rest.workflow.exception.SecureOperationException; import org.folio.spring.web.model.response.ResponseErrors; import org.folio.spring.web.utility.ErrorUtility; import org.springframework.http.HttpStatus; @@ -19,4 +20,12 @@ public ResponseErrors handleWorkflowAlreadyActiveException(WorkflowAlreadyActive log.debug(exception.getMessage(), exception); return ErrorUtility.buildError(exception, HttpStatus.BAD_REQUEST); } + + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(SecureOperationException.class) + public ResponseErrors handleSecureOperationException(SecureOperationException exception) { + log.error(exception.getMessage(), exception); + return ErrorUtility.buildError(exception, HttpStatus.INTERNAL_SERVER_ERROR); + } + } diff --git a/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java b/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java index f3d656db..44801f5e 100644 --- a/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java +++ b/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.persistence.Convert; import org.apache.commons.lang3.reflect.FieldUtils; import org.camunda.bpm.engine.delegate.Expression; import org.camunda.bpm.model.bpmn.Bpmn; @@ -53,6 +54,7 @@ import org.folio.rest.workflow.model.components.Navigation; import org.folio.rest.workflow.model.components.Task; import org.folio.rest.workflow.model.components.Wait; +import org.folio.rest.workflow.model.converter.CryptoConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -77,6 +79,9 @@ public class BpmnModelFactory { @Autowired private ObjectMapper objectMapper; + @Autowired + private CryptoConverter cryptoConverter; + @Autowired private List workflowDelegates; @@ -104,6 +109,7 @@ public BpmnModelInstance fromWorkflow(Workflow workflow) throws ScriptTaskDeseri setup(model, workflow); expressions(model, workflow.getNodes()); + return model; } @@ -415,7 +421,14 @@ private void expressions(BpmnModelInstance model, List nodes) { if (Objects.nonNull(value)) { CamundaField field = model.newInstance(CamundaField.class); field.setCamundaName(f.getName()); - field.setCamundaStringValue(serialize(value)); + + Convert convert = f.getAnnotation(Convert.class); + if (convert != null && CryptoConverter.class.isAssignableFrom(convert.converter()) && String.class.isAssignableFrom(value.getClass())) { + field.setCamundaExpression(String.format("${cryptoConverter.decrypt(\"%s\")}", cryptoConverter.encrypt(serialize(value)))); + } else { + field.setCamundaStringValue(serialize(value)); + } + extensions.addChildElement(field); } } catch (JsonProcessingException | IllegalArgumentException | IllegalAccessException e) {