Skip to content

Commit 38bc906

Browse files
committed
Replaced process, process step and action in errors with a unique coding for every type of error. Also removed exception messages from errors to prevent leaking any potentially critical information
1 parent b779b09 commit 38bc906

32 files changed

+1355
-702
lines changed

src/main/java/dev/dsf/bpe/CodeSystem.java

Lines changed: 350 additions & 88 deletions
Large diffs are not rendered by default.

src/main/java/dev/dsf/bpe/ExecutionVariables.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ public enum ExecutionVariables
99
downloadResourceReference,
1010
statusCode,
1111
error,
12+
errorLocal,
13+
errorRemote,
1214
errors,
15+
errorsRemote,
1316
downloadedBytes,
1417
downloadedDuration,
1518
targetEndpointIdentifier,
1619
uploadedBytes,
1720
uploadedDuration,
1821
resourceDownloadError,
22+
resourceDownloadErrorRemote,
1923
resourceUploadError,
24+
resourceUploadErrorRemote,
2025
pingTaskId;
2126

2227
public String correlatedValue(String correlationKey)

src/main/java/dev/dsf/bpe/PingProcessPluginDefinition.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public Map<String, List<String>> getFhirResourcesByProcessId()
5252

5353
var cPing = "fhir/CodeSystem/dsf-ping.xml";
5454
var cPingStatus = "fhir/CodeSystem/dsf-ping-status.xml";
55-
var cPingProcesses = "fhir/CodeSystem/dsf-ping-processes.xml";
56-
var cPingProcessSteps = "fhir/CodeSystem/dsf-ping-process-steps.xml";
55+
var cPingError = "fhir/CodeSystem/dsf-ping-error.xml";
5756

5857
var sPingStatus = "fhir/StructureDefinition/dsf-extension-ping-status.xml";
5958
var sPing = "fhir/StructureDefinition/dsf-task-ping.xml";
@@ -72,18 +71,14 @@ public Map<String, List<String>> getFhirResourcesByProcessId()
7271
var vPingUnits = "fhir/ValueSet/dsf-network-speed-units.xml";
7372
var vPingStatus = "fhir/ValueSet/dsf-ping-status.xml";
7473
var vPongStatus = "fhir/ValueSet/dsf-pong-status.xml";
75-
var vPingProcesses = "fhir/ValueSet/dsf-ping-processes.xml";
76-
var vPingProcessSteps = "fhir/ValueSet/dsf-ping-process-steps.xml";
7774

78-
return Map.of(
79-
ConstantsPing.PROCESS_NAME_FULL_PING, Arrays.asList(aPing, cPing, cPingStatus, cPingProcesses,
80-
cPingProcessSteps, sErrorExtension, sPingStatus, sStartPing, sPong, sCleanupPong, tStartPing,
81-
vPing, vPingStatus, vPingUnits, vPingProcesses, vPingProcessSteps),
75+
return Map.of(ConstantsPing.PROCESS_NAME_FULL_PING,
76+
Arrays.asList(aPing, cPing, cPingStatus, cPingError, sErrorExtension, sPingStatus, sStartPing, sPong,
77+
sCleanupPong, tStartPing, vPing, vPingStatus, vPingUnits),
8278
ConstantsPing.PROCESS_NAME_FULL_PING_AUTOSTART,
8379
Arrays.asList(aPingAutostart, cPing, sStartPingAutostart, sStopPingAutostart, tStartPingAutoStart,
8480
tStopPingAutoStart, vPing),
85-
ConstantsPing.PROCESS_NAME_FULL_PONG,
86-
Arrays.asList(aPong, cPing, cPingStatus, cPingProcesses, cPingProcessSteps, sErrorExtension,
87-
sPingStatus, sPing, vPing, vPongStatus, vPingUnits, vPingProcesses, vPingProcessSteps));
81+
ConstantsPing.PROCESS_NAME_FULL_PONG, Arrays.asList(aPong, cPing, cPingStatus, cPingError,
82+
sErrorExtension, sPingStatus, sPing, vPing, vPongStatus, vPingUnits));
8883
}
8984
}

src/main/java/dev/dsf/bpe/ProcessError.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,43 @@
1212
import org.hl7.fhir.r4.model.Task;
1313
import org.hl7.fhir.r4.model.UrlType;
1414

15-
//todo: remove process and processStep + CodeSystems, make message never contain e.getMessage() becaus security
16-
// ping status codesystem should extend old ping status codesystem, map every possible error to a unique name in a new codesystem
17-
// that repaces process + processStep, display values should contain the exact text that is now contained in action
18-
// remove equals method
19-
public record ProcessError(CodeSystem.DsfPingProcesses.Code process, CodeSystem.DsfPingProcessSteps.Code processStep,
20-
String action, String potentialFixUrl, String message) implements Serializable
15+
public record ProcessError(String process, CodeSystem.DsfPingError.Concept concept, String potentialFixUrl)
16+
implements Serializable
2117
{
2218
public static Extension toExtension(ProcessError error)
2319
{
2420
Objects.requireNonNull(error);
25-
Objects.requireNonNull(error.action());
21+
Objects.requireNonNull(error.concept());
2622
Objects.requireNonNull(error.process());
27-
Objects.requireNonNull(error.message());
28-
Objects.requireNonNull(error.processStep());
2923

3024
Extension extension = new Extension();
3125
extension.setUrl(ConstantsPing.STRUCTURE_DEFINITION_URL_EXTENSION_ERROR);
3226

33-
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_PROCESS)
34-
.setValue(new Coding(CodeSystem.DsfPingProcesses.URL, error.process().getValue(), null));
35-
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_PROCESS_STEP)
36-
.setValue(new Coding(CodeSystem.DsfPingProcessSteps.URL, error.process().getValue(), null));
37-
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_ACTION).setValue(new StringType(error.action()));
27+
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_ERROR)
28+
.setValue(new Coding().setSystem(CodeSystem.DsfPingError.URL).setCode(error.concept.getCode())
29+
.setDisplay(error.concept.getDisplay()));
3830
if (Objects.nonNull(error.potentialFixUrl))
3931
{
4032
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_POTENTIAL_FIX)
4133
.setValue(new UrlType(error.potentialFixUrl()));
4234
}
43-
extension.addExtension().setUrl(ConstantsPing.EXTENSION_URL_MESSAGE).setValue(new StringType(error.message()));
4435

4536
return extension;
4637
}
4738

48-
public static ProcessError toError(Extension extension)
39+
public static ProcessError toError(Extension extension, String process)
4940
{
50-
Extension processExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_PROCESS);
51-
Objects.requireNonNull(processExtension);
52-
String process = ((Coding) processExtension.getValue()).getCode();
53-
54-
55-
Extension processStepExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_PROCESS_STEP);
56-
Objects.requireNonNull(processStepExtension);
57-
String processStep = ((Coding) processStepExtension.getValue()).getCode();
58-
59-
Extension actionExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_ACTION);
60-
Objects.requireNonNull(actionExtension);
61-
String action = ((StringType) actionExtension.getValue()).getValue();
41+
Extension errorExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_ERROR);
42+
Objects.requireNonNull(errorExtension);
43+
CodeSystem.DsfPingError.Concept error = CodeSystem.DsfPingError.Concept
44+
.fromCode(((Coding) errorExtension.getValue()).getCode());
6245

6346
Extension potentalFixUrlExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_POTENTIAL_FIX);
6447
String potentialFixUrl = Objects.nonNull(potentalFixUrlExtension)
6548
? ((UrlType) potentalFixUrlExtension.getValue()).getValue()
6649
: null;
6750

68-
Extension messageExtension = extension.getExtensionByUrl(ConstantsPing.EXTENSION_URL_MESSAGE);
69-
Objects.requireNonNull(messageExtension);
70-
String message = ((StringType) messageExtension.getValue()).getValue();
71-
72-
CodeSystem.DsfPingProcesses.Code processCode = CodeSystem.DsfPingProcesses.Code.ofValue(process);
73-
CodeSystem.DsfPingProcessSteps.Code stepCode = CodeSystem.DsfPingProcessSteps.Code.ofValue(processStep);
74-
75-
return new ProcessError(processCode, stepCode, action, potentialFixUrl, message);
51+
return new ProcessError(process, error, potentialFixUrl);
7652
}
7753

7854
public static List<Task.TaskOutputComponent> toTaskOutput(List<ProcessError> errors)

src/main/java/dev/dsf/bpe/mail/AggregateErrorMailService.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.slf4j.LoggerFactory;
1010
import org.springframework.beans.factory.InitializingBean;
1111

12-
import dev.dsf.bpe.CodeSystem;
12+
import dev.dsf.bpe.ConstantsPing;
1313
import dev.dsf.bpe.ProcessError;
1414
import dev.dsf.bpe.v1.ProcessPluginApi;
1515
import dev.dsf.bpe.v1.variables.Target;
@@ -72,7 +72,7 @@ protected String createMessage(Target target, ProcessError error)
7272

7373
if (error != null && error.process() != null)
7474
{
75-
if (CodeSystem.DsfPingProcesses.Code.PING.equals(error.process()))
75+
if (ConstantsPing.PROCESS_NAME_PING.equals(error.process()))
7676
{
7777
b.append(api.getOrganizationProvider().getLocalOrganizationIdentifierValue().orElse("?"));
7878
b.append('/');
@@ -101,13 +101,7 @@ protected String createMessage(Target target, ProcessError error)
101101
b.append(": ");
102102
}
103103
b.append("\n\t");
104-
b.append("Process: ").append(error.process());
105-
b.append("\n\t");
106-
b.append("Process step: ").append(error.processStep());
107-
b.append("\n\t");
108-
b.append("Action: ").append(error.action());
109-
b.append("\n\t");
110-
b.append("Message: ").append(error.message());
104+
b.append("Description: ").append(error.concept().getDisplay());
111105
}
112106
else
113107
{

src/main/java/dev/dsf/bpe/message/CleanupPongMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.slf4j.LoggerFactory;
1010

1111
import dev.dsf.bpe.CodeSystem;
12+
import dev.dsf.bpe.ConstantsPing;
1213
import dev.dsf.bpe.ExecutionVariables;
1314
import dev.dsf.bpe.ProcessError;
1415
import dev.dsf.bpe.util.task.SendTaskErrorConverter;
@@ -54,13 +55,12 @@ protected void handleSendTaskError(DelegateExecution execution, Variables variab
5455
String errorMessage)
5556
{
5657
Target target = variables.getTarget();
57-
ProcessError error = SendTaskErrorConverter.convert(exception,
58-
"Sending cleanup message to " + target.getEndpointUrl());
58+
ProcessError error = SendTaskErrorConverter.convertLocal(exception, false, ConstantsPing.PROCESS_NAME_PING);
5959

6060
execution.setVariableLocal(ExecutionVariables.error.name(), new ProcessErrorValueImpl(error));
6161
execution.setVariableLocal(ExecutionVariables.statusCode.name(), CodeSystem.DsfPing.Code.ERROR.getValue());
6262

63-
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.message());
63+
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.concept().getDisplay());
6464
}
6565

6666
@Override

src/main/java/dev/dsf/bpe/message/SendPingMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.slf4j.LoggerFactory;
1414

1515
import dev.dsf.bpe.CodeSystem;
16+
import dev.dsf.bpe.ConstantsPing;
1617
import dev.dsf.bpe.ExecutionVariables;
1718
import dev.dsf.bpe.ProcessError;
1819
import dev.dsf.bpe.util.task.SendTaskErrorConverter;
@@ -78,13 +79,12 @@ protected void handleSendTaskError(DelegateExecution execution, Variables variab
7879
String errorMessage)
7980
{
8081
Target target = variables.getTarget();
81-
ProcessError error = SendTaskErrorConverter.convert(exception,
82-
"Sending ping message to " + target.getEndpointUrl());
82+
ProcessError error = SendTaskErrorConverter.convertLocal(exception, true, ConstantsPing.PROCESS_NAME_PING);
8383

8484
execution.setVariableLocal(ExecutionVariables.error.name(), new ProcessErrorValueImpl(error));
8585
execution.setVariableLocal(ExecutionVariables.statusCode.name(), CodeSystem.DsfPing.Code.ERROR.getValue());
8686

87-
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.message());
87+
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.concept().getDisplay());
8888
}
8989

9090
@Override

src/main/java/dev/dsf/bpe/message/SendPongMessage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.slf4j.LoggerFactory;
1111

1212
import dev.dsf.bpe.CodeSystem;
13+
import dev.dsf.bpe.ConstantsPing;
1314
import dev.dsf.bpe.ExecutionVariables;
1415
import dev.dsf.bpe.ProcessError;
1516
import dev.dsf.bpe.ProcessErrors;
@@ -51,7 +52,7 @@ public void afterPropertiesSet() throws Exception
5152
protected Stream<Task.ParameterComponent> getAdditionalInputParameters(DelegateExecution execution,
5253
Variables variables)
5354
{
54-
ProcessErrors errorList = ErrorListUtils.getErrorList(execution);
55+
ProcessErrors errorListRemote = ErrorListUtils.getErrorListRemote(execution);
5556
long downloadResourceSizeBytes = variables.getLong(ExecutionVariables.downloadResourceSizeBytes.name());
5657
if (downloadResourceSizeBytes >= 0)
5758
{
@@ -72,12 +73,12 @@ protected Stream<Task.ParameterComponent> getAdditionalInputParameters(DelegateE
7273

7374
return Stream
7475
.of(downloadedBytesParameter, downloadedDurationParameter, downloadedResourceReferenceParameter,
75-
ErrorInputComponentGenerator.create(errorList.getEntries()).stream())
76+
ErrorInputComponentGenerator.create(errorListRemote.getEntries()).stream())
7677
.flatMap(stream -> stream);
7778
}
7879
else
7980
{
80-
return ErrorInputComponentGenerator.create(errorList.getEntries()).stream();
81+
return ErrorInputComponentGenerator.create(errorListRemote.getEntries()).stream();
8182
}
8283
}
8384

@@ -98,14 +99,13 @@ protected void handleSendTaskError(DelegateExecution execution, Variables variab
9899
Target target = variables.getTarget();
99100
Task startTask = variables.getStartTask();
100101

101-
ProcessError error = SendTaskErrorConverter.convert(exception,
102-
"Sending pong message to " + target.getEndpointUrl());
102+
ProcessError error = SendTaskErrorConverter.convertLocal(exception, true, ConstantsPing.PROCESS_NAME_PONG);
103103

104104
ErrorListUtils.add(error, execution);
105105
PingStatusGenerator.updatePongStatusOutput(startTask, CodeSystem.DsfPingStatus.Code.ERROR);
106106
variables.setString(ExecutionVariables.statusCode.name(), CodeSystem.DsfPing.Code.ERROR.getValue());
107107
variables.updateTask(startTask);
108108

109-
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.message());
109+
logger.info("Request to {} resulted in error: {}", target.getEndpointUrl(), error.concept().getDisplay());
110110
}
111111
}

src/main/java/dev/dsf/bpe/service/Cleanup.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.dsf.bpe.service;
22

33
import java.net.SocketTimeoutException;
4-
import java.util.Objects;
54

65
import org.camunda.bpm.engine.delegate.DelegateExecution;
76
import org.camunda.bpm.engine.delegate.Expression;
@@ -36,8 +35,7 @@ public void doExecute(DelegateExecution delegateExecution, Variables variables)
3635
{
3736
logger.debug("Cleaning up...");
3837

39-
CodeSystem.DsfPingProcesses.Code process = getProcess((String) this.process.getValue(delegateExecution));
40-
Objects.requireNonNull(process);
38+
String process = (String) this.process.getValue(delegateExecution);
4139

4240
String downloadResourceId = new IdType(variables.getString(ExecutionVariables.downloadResourceReference.name()))
4341
.getIdPart();
@@ -55,10 +53,11 @@ public void doExecute(DelegateExecution delegateExecution, Variables variables)
5553
{
5654
if (e.getCause() instanceof SocketTimeoutException)
5755
{
58-
ProcessError error = new ProcessError(process, CodeSystem.DsfPingProcessSteps.Code.CLEANUP,
59-
ConstantsPing.CLEANUP_ERROR_ACTION, ConstantsPing.POTENTIAL_FIX_URL_READ_TIMEOUT,
60-
e.getCause().getMessage());
56+
ProcessError error = new ProcessError(process,
57+
CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_TIMEOUT,
58+
ConstantsPing.POTENTIAL_FIX_URL_READ_TIMEOUT);
6159
ErrorListUtils.add(error, delegateExecution);
60+
logger.error(e.getCause().getMessage());
6261
}
6362
else
6463
{
@@ -67,9 +66,7 @@ public void doExecute(DelegateExecution delegateExecution, Variables variables)
6766
}
6867
catch (WebApplicationException e)
6968
{
70-
ProcessError error = new ProcessError(process, CodeSystem.DsfPingProcessSteps.Code.CLEANUP,
71-
ConstantsPing.CLEANUP_ERROR_ACTION, ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP,
72-
"Response from local DSF FHIR server: " + e.getResponse().getStatus());
69+
ProcessError error = toProcessError(e, process);
7370
ErrorListUtils.add(error, delegateExecution);
7471
}
7572
}
@@ -80,15 +77,29 @@ public void doExecute(DelegateExecution delegateExecution, Variables variables)
8077
logger.debug("Cleanup complete.");
8178
}
8279

83-
public void setProcess(org.camunda.bpm.engine.delegate.Expression process)
80+
private ProcessError toProcessError(WebApplicationException e, String process)
8481
{
85-
this.process = process;
82+
int status = e.getResponse().getStatus();
83+
String message = "Response from local DSF FHIR server: " + status;
84+
logger.error(message, e);
85+
86+
return switch (status)
87+
{
88+
case 401 -> new ProcessError(process, CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_HTTP_401,
89+
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP);
90+
case 403 -> new ProcessError(process, CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_HTTP_403,
91+
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP);
92+
case 500 -> new ProcessError(process, CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_HTTP_500,
93+
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP);
94+
case 502 -> new ProcessError(process, CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_HTTP_502,
95+
ConstantsPing.POTENTIAL_FIX_URL_ERROR_HTTP);
96+
default -> new ProcessError(process, CodeSystem.DsfPingError.Concept.LOCAL_BINARY_DELETE_HTTP_UNEXPECTED,
97+
null);
98+
};
8699
}
87100

88-
private CodeSystem.DsfPingProcesses.Code getProcess(String process)
101+
public void setProcess(Expression process)
89102
{
90-
if (process == null || process.isEmpty())
91-
return null;
92-
return CodeSystem.DsfPingProcesses.Code.ofValue(process);
103+
this.process = process;
93104
}
94105
}

0 commit comments

Comments
 (0)