Skip to content

Commit 4bd2816

Browse files
committed
Add a flag for registering the database table REST resources
The management/tables REST resources expose the raw content of the database tables. They are now only registered when the flowable.rest.table-management.enabled property is set to true, which is disabled by default. (cherry picked from commit 6c72a38)
1 parent 25b004e commit 4bd2816

12 files changed

Lines changed: 128 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9467,6 +9467,9 @@ The response body contains the binary value of the variable. When the variable i
94679467

94689468
## Database tables
94699469

9470+
The database table resources expose the raw content of the Flowable database tables and are therefore not available by default.
9471+
They are only registered when the `flowable.rest.table-management.enabled` property is set to `true`.
9472+
94709473
### List of tables
94719474

94729475
GET management/tables

‎modules/flowable-app-rest/src/main/resources/flowable-default.properties‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ flowable.rest.app.authentication-mode=verify-privilege
5656
# Enable/disable Java serializable objects to be passed as variables in the REST API.
5757
rest.variables.allow.serializable=true
5858

59+
# Enable/disable the database table REST resources (management/tables). These expose the raw content of the database tables.
60+
flowable.rest.table-management.enabled=false
61+
5962
# Enable/disable whether the docs are available on /docs
6063
flowable.rest.app.swagger-docs-enabled=true
6164

‎modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/TableCollectionResource.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
import org.flowable.engine.ManagementService;
1919
import org.flowable.rest.service.api.BpmnRestApiInterceptor;
2020
import org.flowable.rest.service.api.RestResponseFactory;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.springframework.beans.factory.InitializingBean;
2124
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.context.annotation.Conditional;
2226
import org.springframework.web.bind.annotation.GetMapping;
2327
import org.springframework.web.bind.annotation.RestController;
2428

@@ -32,8 +36,11 @@
3236
* @author Frederik Heremans
3337
*/
3438
@RestController
39+
@Conditional(TableManagementEnabledCondition.class)
3540
@Api(tags = { "Database tables" }, authorizations = { @Authorization(value = "basicAuth") })
36-
public class TableCollectionResource {
41+
public class TableCollectionResource implements InitializingBean {
42+
43+
protected static final Logger LOGGER = LoggerFactory.getLogger(TableCollectionResource.class);
3744

3845
@Autowired
3946
protected RestResponseFactory restResponseFactory;
@@ -44,6 +51,13 @@ public class TableCollectionResource {
4451
@Autowired(required=false)
4552
protected BpmnRestApiInterceptor restApiInterceptor;
4653

54+
@Override
55+
public void afterPropertiesSet() {
56+
LOGGER.warn("The database table REST resources (management/tables) are enabled through '{}'. "
57+
+ "They expose the raw content of the Flowable database tables and should only be enabled when needed, with access restricted to administrators.",
58+
TableManagementEnabledCondition.PROPERTY_NAME);
59+
}
60+
4761
@ApiOperation(value = " List tables", tags = { "Database tables" }, nickname = "listTables")
4862
@ApiResponses(value = {
4963
@ApiResponse(code = 200, message = "Indicates the request was successful.")

‎modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/TableColumnsResource.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.flowable.engine.ManagementService;
1919
import org.flowable.rest.service.api.BpmnRestApiInterceptor;
2020
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.context.annotation.Conditional;
2122
import org.springframework.web.bind.annotation.GetMapping;
2223
import org.springframework.web.bind.annotation.PathVariable;
2324
import org.springframework.web.bind.annotation.RestController;
@@ -33,6 +34,7 @@
3334
* @author Frederik Heremans
3435
*/
3536
@RestController
37+
@Conditional(TableManagementEnabledCondition.class)
3638
@Api(tags = { "Database tables" }, authorizations = { @Authorization(value = "basicAuth") })
3739
public class TableColumnsResource {
3840

‎modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/TableDataResource.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.flowable.rest.service.api.BpmnRestApiInterceptor;
2626
import org.flowable.rest.service.api.RestResponseFactory;
2727
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.context.annotation.Conditional;
2829
import org.springframework.web.bind.annotation.GetMapping;
2930
import org.springframework.web.bind.annotation.PathVariable;
3031
import org.springframework.web.bind.annotation.RequestParam;
@@ -43,6 +44,7 @@
4344
* @author Frederik Heremans
4445
*/
4546
@RestController
47+
@Conditional(TableManagementEnabledCondition.class)
4648
@Api(tags = { "Database tables" }, authorizations = { @Authorization(value = "basicAuth") })
4749
public class TableDataResource {
4850

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
14+
package org.flowable.rest.service.api.management;
15+
16+
import org.springframework.context.annotation.Condition;
17+
import org.springframework.context.annotation.ConditionContext;
18+
import org.springframework.core.type.AnnotatedTypeMetadata;
19+
20+
/**
21+
* Condition for registering the database table REST resources ({@code management/tables}).
22+
* These resources expose the raw content of the database tables, therefore they are only registered
23+
* when the {@value #PROPERTY_NAME} property is explicitly set to {@code true}.
24+
*
25+
* @author Filip Hrisafov
26+
*/
27+
public class TableManagementEnabledCondition implements Condition {
28+
29+
public static final String PROPERTY_NAME = "flowable.rest.table-management.enabled";
30+
31+
@Override
32+
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
33+
return context.getEnvironment().getProperty(PROPERTY_NAME, Boolean.class, false);
34+
}
35+
}

‎modules/flowable-rest/src/main/java/org/flowable/rest/service/api/management/TableResource.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.flowable.rest.service.api.BpmnRestApiInterceptor;
2222
import org.flowable.rest.service.api.RestResponseFactory;
2323
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.context.annotation.Conditional;
2425
import org.springframework.web.bind.annotation.GetMapping;
2526
import org.springframework.web.bind.annotation.PathVariable;
2627
import org.springframework.web.bind.annotation.RestController;
@@ -36,6 +37,7 @@
3637
* @author Frederik Heremans
3738
*/
3839
@RestController
40+
@Conditional(TableManagementEnabledCondition.class)
3941
@Api(tags = { "Database tables" }, authorizations = { @Authorization(value = "basicAuth") })
4042
public class TableResource {
4143

‎modules/flowable-rest/src/test/java/org/flowable/rest/service/api/management/TableColumnsResourceTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.flowable.rest.service.BaseSpringRestTestCase;
2222
import org.flowable.rest.service.api.RestUrls;
2323
import org.junit.jupiter.api.Test;
24+
import org.springframework.test.context.TestPropertySource;
2425

2526
import com.fasterxml.jackson.databind.JsonNode;
2627
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -30,6 +31,7 @@
3031
*
3132
* @author Frederik Heremans
3233
*/
34+
@TestPropertySource(properties = "flowable.rest.table-management.enabled=true")
3335
public class TableColumnsResourceTest extends BaseSpringRestTestCase {
3436

3537
/**

‎modules/flowable-rest/src/test/java/org/flowable/rest/service/api/management/TableDataResourceTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.flowable.task.api.Task;
2727
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
2828
import org.junit.jupiter.api.Test;
29+
import org.springframework.test.context.TestPropertySource;
2930

3031
import com.fasterxml.jackson.databind.JsonNode;
3132

@@ -36,6 +37,7 @@
3637
*
3738
* @author Frederik Heremans
3839
*/
40+
@TestPropertySource(properties = "flowable.rest.table-management.enabled=true")
3941
public class TableDataResourceTest extends BaseSpringRestTestCase {
4042

4143
/**
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
14+
package org.flowable.rest.service.api.management;
15+
16+
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
17+
18+
import org.apache.http.HttpStatus;
19+
import org.apache.http.client.methods.CloseableHttpResponse;
20+
import org.apache.http.client.methods.HttpGet;
21+
import org.flowable.rest.service.BaseSpringRestTestCase;
22+
import org.flowable.rest.service.api.RestUrls;
23+
import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;
24+
import org.junit.jupiter.api.Test;
25+
26+
import com.fasterxml.jackson.databind.JsonNode;
27+
28+
/**
29+
* @author Filip Hrisafov
30+
*/
31+
public class TableManagementDisabledTest extends BaseSpringRestTestCase {
32+
33+
@Test
34+
public void tableResourcesAreNotRegisteredByDefault() throws Exception {
35+
String tableName = managementService.getTableName(VariableInstanceEntity.class);
36+
37+
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLES_COLLECTION)),
38+
HttpStatus.SC_NOT_FOUND);
39+
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
40+
closeResponse(response);
41+
assertThatJson(responseNode)
42+
.isEqualTo("{"
43+
+ " message: 'Not Found',"
44+
+ " exception: 'No endpoint GET /service/management/tables.'"
45+
+ "}");
46+
47+
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE, tableName)),
48+
HttpStatus.SC_NOT_FOUND));
49+
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE_COLUMNS, tableName)),
50+
HttpStatus.SC_NOT_FOUND));
51+
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE_DATA, tableName)),
52+
HttpStatus.SC_NOT_FOUND));
53+
}
54+
}

0 commit comments

Comments
 (0)