Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #257]: Encrypt passwords in BPMN, decrypt with expression #261

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -77,6 +79,9 @@ public class BpmnModelFactory {
@Autowired
private ObjectMapper objectMapper;

@Autowired
private CryptoConverter cryptoConverter;

@Autowired
private List<AbstractWorkflowDelegate> workflowDelegates;

Expand Down Expand Up @@ -104,6 +109,7 @@ public BpmnModelInstance fromWorkflow(Workflow workflow) throws ScriptTaskDeseri

setup(model, workflow);
expressions(model, workflow.getNodes());

return model;
}

Expand Down Expand Up @@ -415,7 +421,14 @@ private void expressions(BpmnModelInstance model, List<Node> 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) {
Expand Down