Skip to content

Commit 64d6490

Browse files
committed
Follow-ups for disabling serializable variables by default
- The REST variable data endpoints validate the type of the variable before resolving its value. With the default configuration (serializable variables disabled in the engine and not allowed in the REST API) they return a 415 response instead of a 500 response, and no serializable variable is deserialized before the request is rejected. - A variable with a JSON object or array as value and no type is rejected with a 400 response in the REST API, since such a value could only be stored using Java serialization. The json type needs to be used instead. This does not apply to transient variables. - The old value of a variable is only read when a logging session is enabled. This allows overwriting an existing serializable variable with a value of another type when serializable variables are disabled. The logging session no longer reads the value of a serializable variable that cannot be read, such a variable is logged without its value. - The Drools based business rule task logs a warning when its result is only stored as a transient variable. - Restore the API responses documentation of the historic process and case instance variable data endpoints. - Add tests for the serializable variable type mode in the CMMN and v5 engines, for the default configuration of the REST API, for the string only filter of the JPA entity list variable type and for float variables in the CMMN and v5 engines.
1 parent 72184e1 commit 64d6490

44 files changed

Lines changed: 1306 additions & 59 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/docusaurus/docs/bpmn/ch04-API.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Instead of using Java serialization:
197197

198198
The behavior of the *serializable* variable type can be configured through the `serializableVariableTypeMode` property of the engine configuration:
199199

200-
- `DISABLED` (default): serializable variables can neither be written nor read. Existing serializable variables can still be deleted, but reading their value fails.
200+
- `DISABLED` (default): serializable variables can neither be written nor read. Existing serializable variables can still be deleted or overwritten with a value of another type, but reading their value fails.
201201

202202
- `READ_ONLY`: existing serializable variables can be read (and overwritten with a value of another type), but no new serializable values can be stored. Use this mode to migrate existing data away from Java serialization.
203203

‎docs/docusaurus/docs/bpmn/ch14-REST.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ It’s possible to support additional variable-types with a custom JSON represen
463463

464464
Variables of type *serializable* (Java serialized objects) are disabled by default. Uploading a serialized object (`application/x-java-serialized-object`) or downloading the data of a *serializable* variable returns a `415` response. To allow it, set the `rest.variables.allow.serializable` property to `true`. The `serializableVariableTypeMode` of the engine needs to allow it as well, see [Serializable variables](bpmn/ch04-API.md#serializable-variables). Only enable this when the REST API is used by fully trusted clients, since deserializing Java objects from a request is a security risk.
465465

466+
A variable with a JSON object or array as value needs to have the `json` type. Without a type such a value could only be stored using Java serialization, therefore the request is rejected with a `400` response. This does not apply to transient variables.
467+
466468
## Deployment
467469

468470
**When using Tomcat, please read [Usage in Tomcat](#usage-In-tomcat).**

‎docs/docusaurus/docs/cmmn/ch08-REST.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ It’s possible to support additional variable-types with a custom JSON represen
453453

454454
Variables of type *serializable* (Java serialized objects) are disabled by default. Uploading a serialized object (`application/x-java-serialized-object`) or downloading the data of a *serializable* variable returns a `415` response. To allow it, set the `rest.variables.allow.serializable` property to `true`. The `serializableVariableTypeMode` of the engine needs to allow it as well, see [Serializable variables](bpmn/ch04-API.md#serializable-variables). Only enable this when the REST API is used by fully trusted clients, since deserializing Java objects from a request is a security risk.
455455

456+
A variable with a JSON object or array as value needs to have the `json` type. Without a type such a value could only be stored using Java serialization, therefore the request is rejected with a `400` response. This does not apply to transient variables.
457+
456458
## Deployment
457459

458460
**When using Tomcat, please read [Usage in Tomcat](#usage-in-tomcat).**

‎modules/flowable-app-engine/src/main/java/org/flowable/app/engine/AppEngineConfiguration.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
import org.flowable.variable.service.impl.types.DateType;
9191
import org.flowable.variable.service.impl.types.DefaultVariableTypes;
9292
import org.flowable.variable.service.impl.types.DoubleType;
93-
import org.flowable.variable.service.impl.types.FloatType;
9493
import org.flowable.variable.service.impl.types.EmptyCollectionType;
94+
import org.flowable.variable.service.impl.types.FloatType;
9595
import org.flowable.variable.service.impl.types.InstantType;
9696
import org.flowable.variable.service.impl.types.IntegerType;
9797
import org.flowable.variable.service.impl.types.JodaDateTimeType;

‎modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/CmmnEngineConfiguration.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@
323323
import org.flowable.variable.service.impl.types.DateType;
324324
import org.flowable.variable.service.impl.types.DefaultVariableTypes;
325325
import org.flowable.variable.service.impl.types.DoubleType;
326-
import org.flowable.variable.service.impl.types.FloatType;
327326
import org.flowable.variable.service.impl.types.EmptyCollectionType;
327+
import org.flowable.variable.service.impl.types.FloatType;
328328
import org.flowable.variable.service.impl.types.InstantType;
329329
import org.flowable.variable.service.impl.types.IntegerType;
330330
import org.flowable.variable.service.impl.types.JodaDateTimeType;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.cmmn.test.runtime;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.assertj.core.api.Assertions.entry;
17+
18+
import org.flowable.cmmn.api.runtime.CaseInstance;
19+
import org.flowable.cmmn.engine.test.CmmnDeployment;
20+
import org.flowable.cmmn.test.FlowableCmmnTestCase;
21+
import org.flowable.variable.api.history.HistoricVariableInstance;
22+
import org.flowable.variable.api.persistence.entity.VariableInstance;
23+
import org.flowable.variable.service.impl.types.FloatType;
24+
import org.junit.jupiter.api.Test;
25+
26+
/**
27+
* @author Filip Hrisafov
28+
*/
29+
class FloatVariableTest extends FlowableCmmnTestCase {
30+
31+
@Test
32+
@CmmnDeployment(resources = "org/flowable/cmmn/test/one-human-task-model.cmmn")
33+
void testFloatVariable() {
34+
CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
35+
.caseDefinitionKey("oneTaskCase")
36+
.variable("floatVar", 1.1f)
37+
.variable("maxFloatVar", Float.MAX_VALUE)
38+
.start();
39+
40+
VariableInstance variableInstance = cmmnRuntimeService.getVariableInstance(caseInstance.getId(), "floatVar");
41+
assertThat(variableInstance.getTypeName()).isEqualTo(FloatType.TYPE_NAME);
42+
assertThat(variableInstance.getValue()).isEqualTo(1.1f);
43+
44+
assertThat(cmmnRuntimeService.getVariables(caseInstance.getId()))
45+
.containsOnly(
46+
entry("floatVar", 1.1f),
47+
entry("maxFloatVar", Float.MAX_VALUE)
48+
);
49+
50+
assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueEquals("floatVar", 1.1f).list())
51+
.extracting(CaseInstance::getId)
52+
.containsExactly(caseInstance.getId());
53+
assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueGreaterThan("floatVar", 1.0f).count()).isEqualTo(1);
54+
assertThat(cmmnRuntimeService.createCaseInstanceQuery().variableValueEquals("floatVar", 1.2f).count()).isZero();
55+
56+
cmmnRuntimeService.setVariable(caseInstance.getId(), "floatVar", 2.5f);
57+
assertThat(cmmnRuntimeService.getVariable(caseInstance.getId(), "floatVar")).isEqualTo(2.5f);
58+
59+
HistoricVariableInstance historicVariableInstance = cmmnHistoryService.createHistoricVariableInstanceQuery()
60+
.caseInstanceId(caseInstance.getId())
61+
.variableName("floatVar")
62+
.singleResult();
63+
assertThat(historicVariableInstance.getVariableTypeName()).isEqualTo(FloatType.TYPE_NAME);
64+
assertThat(historicVariableInstance.getValue()).isEqualTo(2.5f);
65+
}
66+
}

0 commit comments

Comments
 (0)