100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Validate parent and realm match when asset is stored
Christian Bauercc8ffbc488aa
diff --git a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.javaindex 48f044cc6..1a14d9907 100644--- a/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java+++ b/manager/server/src/main/java/org/openremote/manager/server/asset/AssetStorageService.java@@ -331,13 +331,15 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicif (parent.pathContains(asset.getId()))throw new IllegalStateException("Invalid parent");- // ... and if we don't have a realm identifier, use the parent's- if (asset.getRealmId() == null)+ // .. the parent should be in the same realm+ if (asset.getRealmId() != null && !parent.getRealmId().equals(asset.getRealmId())) {+ throw new IllegalStateException("Parent not in same realm as asset: " + asset.getRealmId());+ } else if (asset.getRealmId() == null) {+ // ... and if we don't have a realm identifier, use the parent'sasset.setRealmId(parent.getRealmId());+ }}- //TODO if parent and realm are provided, they should match!-// Validate realmif (!managerIdentityService.getIdentityProvider().isActiveTenant(asset.getRealmId())) {throw new IllegalStateException("Realm not found/active: " + asset.getRealmId());diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovyindex fe1ec86cd..0a915e58d 100644--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy@@ -131,6 +131,15 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTraitex = thrown()ex.response.status == 400+ when: "an asset is updated with a parent in a different realm"+ testAsset = assetResource.get(null, testAsset.getId())+ testAsset.setParentId(managerDemoSetup.smartHomeId)+ assetResource.update(null, testAsset.id, testAsset)++ then: "the request should be bad"+ ex = thrown()+ ex.response.status == 400+when: "an asset is deleted but has children"assetResource.delete(null, managerDemoSetup.apartment1Id)