Browse Source

Added validation for deviceName/attribute key contains only spaces situation

pull/3698/head
zbeacon 6 years ago
committed by Andrew Shvayka
parent
commit
92ba5907b0
  1. 5
      application/src/main/java/org/thingsboard/server/controller/TelemetryController.java
  2. 2
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

5
application/src/main/java/org/thingsboard/server/controller/TelemetryController.java

@ -393,6 +393,11 @@ public class TelemetryController extends BaseController {
if (attributes.isEmpty()) {
return getImmediateDeferredResult("No attributes data found in request body!", HttpStatus.BAD_REQUEST);
}
for (AttributeKvEntry attributeKvEntry: attributes) {
if (attributeKvEntry.getKey().isEmpty() || attributeKvEntry.getKey().trim().length() == 0) {
return getImmediateDeferredResult("Key cannot be empty or contains only spaces", HttpStatus.BAD_REQUEST);
}
}
SecurityUser user = getCurrentUser();
return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.WRITE_ATTRIBUTES, entityIdSrc, (result, tenantId, entityId) -> {
tsSubService.saveAndNotify(tenantId, entityId, scope, attributes, new FutureCallback<Void>() {

2
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -388,7 +388,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
if (StringUtils.isEmpty(device.getType())) {
throw new DataValidationException("Device type should be specified!");
}
if (StringUtils.isEmpty(device.getName())) {
if (StringUtils.isEmpty(device.getName()) || device.getName().trim().length() == 0) {
throw new DataValidationException("Device name should be specified!");
}
if (device.getTenantId() == null) {

Loading…
Cancel
Save