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
Bug fix for restricted user read-assets to ensure response only contains assets that are linked to the user
Rich Turnerd07df61cef1d
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.javaindex 1b24d0eeb..91e362f58 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java@@ -389,6 +389,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServicnew AssetQuery().ids(assetId).select(new Select().excludePath(false).excludeParentInfo(true))+ .userIds(access == PROTECTED ? authContext.getUserId() : null).access(access));if (asset != null) {@@ -435,6 +436,10 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic// Set access requirementsquery.access(access);+ if (access == PROTECTED) {+ query.userIds(authContext.getUserId());+ }+List<Asset<?>> assets = findAll(query);String messageId = exchange.getIn().getHeader(ClientEventService.HEADER_REQUEST_RESPONSE_MESSAGE_ID, String.class);diff --git a/test/src/main/java/org/openremote/test/setup/ManagerTestSetup.java b/test/src/main/java/org/openremote/test/setup/ManagerTestSetup.javaindex 7d5bd0e83..edcfdcd58 100644--- a/test/src/main/java/org/openremote/test/setup/ManagerTestSetup.java+++ b/test/src/main/java/org/openremote/test/setup/ManagerTestSetup.java@@ -557,22 +557,13 @@ public class ManagerTestSetup extends ManagerSetup {assetStorageService.storeUserAssetLinks(Arrays.asList(new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),keycloakTestSetup.buildingUserId,- apartment1Id),- new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),- keycloakTestSetup.buildingUserId,- apartment1LivingroomId),- new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),- keycloakTestSetup.buildingUserId,- apartment1KitchenId),- new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),- keycloakTestSetup.buildingUserId,- apartment1Bedroom1Id),+ apartment2Id),new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),keycloakTestSetup.buildingUserId,- apartment1BathroomId),+ apartment2LivingroomId),new UserAssetLink(keycloakTestSetup.tenantBuilding.getRealm(),keycloakTestSetup.buildingUserId,- apartment1HallwayId)));+ apartment2BathroomId)));// ################################ Make users restricted ###################################diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovyindex b0f8072b0..8c1bda00b 100644--- a/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy+++ b/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy@@ -61,11 +61,11 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiidentityService.getIdentityProvider().isRestrictedUser(testUser3Token)when: "all user assets are retrieved of a realm"- def userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, null, null)+ def userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, null, null)then: "result should match"- userAssets.length == 12- userAssets.any {+ userAssetLinks.length == 12+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1Id &&@@ -73,7 +73,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiit.parentAssetName == "Smart building" &&it.userFullName == "testuser3 (DemoA3 DemoLast)"}- userAssets.any {+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1LivingroomId &&@@ -81,7 +81,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiit.parentAssetName == "Apartment 1" &&it.userFullName == "testuser3 (DemoA3 DemoLast)"}- userAssets.any {+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1KitchenId &&@@ -89,7 +89,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiit.parentAssetName == "Apartment 1" &&it.userFullName == "testuser3 (DemoA3 DemoLast)"}- userAssets.any {+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1HallwayId &&@@ -97,7 +97,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiit.parentAssetName == "Apartment 1" &&it.userFullName == "testuser3 (DemoA3 DemoLast)"}- userAssets.any {+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1Bedroom1Id &&@@ -105,7 +105,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiit.parentAssetName == "Apartment 1" &&it.userFullName == "testuser3 (DemoA3 DemoLast)"}- userAssets.any {+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1BathroomId &&@@ -115,10 +115,10 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai}when: "all user assets are retrieved of a realm and user"- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser3Id, null)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser3Id, null)then: "result should match"- userAssets.length == 6+ userAssetLinks.length == 6when: "the realm and user don't match"assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantCity.realm, keycloakTestSetup.testuser3Id, null)@@ -135,11 +135,11 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiex.response.status == 400when: "all user assets are retrieved of a realm and user"- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, null, managerTestSetup.apartment1Id)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, null, managerTestSetup.apartment1Id)then: "result should match"- userAssets.length == 2- userAssets.any {+ userAssetLinks.length == 1+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1Id &&@@ -149,11 +149,11 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai}when: "all user assets are retrieved of a realm and user and asset"- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser3Id, managerTestSetup.apartment1Id)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser3Id, managerTestSetup.apartment1Id)then: "result should match"- userAssets.length == 1- userAssets.any {+ userAssetLinks.length == 1+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser3Id &&it.id.assetId == managerTestSetup.apartment1Id &&@@ -163,21 +163,21 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai}when: "all user assets are retrieved of a realm and user and asset"- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, managerTestSetup.apartment1Id)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, managerTestSetup.apartment1Id)then: "result should match"- userAssets.length == 0+ userAssetLinks.length == 0/* ############################################## WRITE ####################################### */when: "an asset is linked to a user"UserAssetLink userAssetLink = new UserAssetLink(keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, managerTestSetup.apartment2Id)assetResource.createUserAssetLinks(null, [userAssetLink])- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, null)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, null)then: "result should match"- userAssets.length == 1- userAssets.any {+ userAssetLinks.length == 1+ userAssetLinks.any {it.id.realm == keycloakTestSetup.tenantBuilding.realm &&it.id.userId == keycloakTestSetup.testuser2Id &&it.id.assetId == managerTestSetup.apartment2Id &&@@ -189,10 +189,9 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTraiwhen: "an asset link is deleted"assetResource.deleteUserAssetLink(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, managerTestSetup.apartment2Id)- userAssets = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, null)+ userAssetLinks = assetResource.getUserAssetLinks(null, keycloakTestSetup.tenantBuilding.realm, keycloakTestSetup.testuser2Id, null)then: "result should match"- userAssets.length == 0+ userAssetLinks.length == 0}-}