Skip to content

Commit 5597385

Browse files
Add limitation in the array of events for the publish endpoint genera… (#299)
Add limitation in the array of events for the publish endpoint generateAndPublish
1 parent adb1584 commit 5597385

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/controller/ProducerController.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public class ProducerController {
7878
@Value("${activedirectory.publish.enabled}")
7979
private boolean isAuthenticationEnabled;
8080

81+
@Value("${maxSizeOfInputArray:250}")
82+
private int maxSizeOfInputArray;
83+
8184
private RestTemplate restTemplate = new RestTemplate();
8285

8386
private JsonParser parser = new JsonParser();
@@ -153,6 +156,14 @@ public ResponseEntity send(final String msgProtocol, final String userDomain, fi
153156
return new ResponseEntity(e.getMessage(), HttpStatus.NOT_FOUND);
154157
}
155158
}
159+
160+
//here add check for limitation for events in array is fetched from REMReM property and checked during publishing.
161+
if (body.isJsonArray() && (body.getAsJsonArray().size() > maxSizeOfInputArray)) {
162+
return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS,
163+
"The number of events in the input array is too high: " + body.getAsJsonArray().size() + " > "
164+
+ maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it.");
165+
166+
}
156167
synchronized (this) {
157168
SendResult result = messageService.send(body, msgService, userDomain, tag, routingKey);
158169
log.info("HTTP Status: {}", messageService.getHttpStatus().value());
@@ -303,7 +314,14 @@ public ResponseEntity generateAndPublish(final String msgProtocol, final String
303314
if (bodyJson.isJsonObject()) {
304315
events.add(getAsJsonObject(bodyJson));
305316
} else if (bodyJson.isJsonArray()) {
306-
for (JsonElement element : bodyJson.getAsJsonArray()) {
317+
JsonArray bodyJsonArray = bodyJson.getAsJsonArray();
318+
//here add check for limitation for events in array is fetched from REMReM property and checked during publishing.
319+
if (bodyJsonArray.size() > maxSizeOfInputArray) {
320+
return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS,
321+
"The number of events in the input array is too high: " + bodyJsonArray.size() + " > "
322+
+ maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it.");
323+
}
324+
for (JsonElement element : bodyJsonArray) {
307325
if (element.isJsonObject()) {
308326
events.add(getAsJsonObject(element));
309327
} else {

publish-service/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ activedirectory.connectionTimeOut:
4444

4545
spring.mvc.pathmatch.matching-strategy: ANT_PATH_MATCHER
4646

47+
#Maximum number of templates in array passed to generateAndPublish endpoint
48+
maxSizeOfInputArray: 250
4749

4850

0 commit comments

Comments
 (0)