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
Added role check to health and info endpoints (Closes #335)
Rich Turnerff83b42f337b
diff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.javaindex cd00d8e22..d0fbaf6f9 100644--- a/model/src/main/java/org/openremote/model/Constants.java+++ b/model/src/main/java/org/openremote/model/Constants.java@@ -34,7 +34,6 @@ public interface Constants {String READ_MAP_ROLE = "read:map";String READ_ASSETS_ROLE = "read:assets";String READ_RULES_ROLE = "read:rules";- String READ_APPS_ROLE = "read:apps";String WRITE_USER_ROLE = "write:user";String WRITE_ADMIN_ROLE = "write:admin";String WRITE_LOGS_ROLE = "write:logs";diff --git a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.javaindex c7a674ba1..7d952b9dd 100644--- a/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java+++ b/model/src/main/java/org/openremote/model/apps/ConsoleAppResource.java@@ -38,7 +38,7 @@ public interface ConsoleAppResource {*/@GET@Produces(APPLICATION_JSON)- @RolesAllowed({Constants.READ_APPS_ROLE})+ @RolesAllowed({Constants.READ_ADMIN_ROLE})String[] getInstalledApps(@BeanParam RequestParams requestParams);@GETdiff --git a/model/src/main/java/org/openremote/model/security/ClientRole.java b/model/src/main/java/org/openremote/model/security/ClientRole.javaindex 1629438ab..c99eafeb0 100644--- a/model/src/main/java/org/openremote/model/security/ClientRole.java+++ b/model/src/main/java/org/openremote/model/security/ClientRole.java@@ -39,7 +39,6 @@ public enum ClientRole {READ_MAP(Constants.READ_MAP_ROLE, "View map"),READ_ASSETS(Constants.READ_ASSETS_ROLE, "Read asset data"),READ_RULES(Constants.READ_RULES_ROLE, "Read rulesets"),- READ_APPS(Constants.READ_APPS_ROLE, "Read installed applications"),WRITE_USER(Constants.WRITE_USER_ROLE, "Write data of the authenticated user"),WRITE_ADMIN(Constants.WRITE_ADMIN_ROLE, "Write system settings, tenants, and users"),@@ -54,8 +53,7 @@ public enum ClientRole {READ_USERS,READ_MAP,READ_ASSETS,- READ_RULES,- READ_APPS+ READ_RULES}),WRITE("write", "Write all data", new ClientRole[]{@@ -65,7 +63,6 @@ public enum ClientRole {READ_MAP,READ_ASSETS,READ_RULES,- READ_APPS,WRITE_USER,WRITE_ADMIN,WRITE_LOGS,diff --git a/model/src/main/java/org/openremote/model/system/StatusResource.java b/model/src/main/java/org/openremote/model/system/StatusResource.javaindex 941082634..db96a755b 100644--- a/model/src/main/java/org/openremote/model/system/StatusResource.java+++ b/model/src/main/java/org/openremote/model/system/StatusResource.java@@ -21,7 +21,9 @@ package org.openremote.model.system;import com.fasterxml.jackson.databind.node.ObjectNode;import io.swagger.v3.oas.annotations.tags.Tag;+import org.openremote.model.Constants;+import javax.annotation.security.RolesAllowed;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;@@ -35,10 +37,12 @@ public interface StatusResource {@Path("health")@GET@Produces(APPLICATION_JSON)+ @RolesAllowed({Constants.READ_ADMIN_ROLE})ObjectNode getHealthStatus();@Path("info")@GET@Produces(APPLICATION_JSON)+ @RolesAllowed({Constants.READ_ADMIN_ROLE})ObjectNode getInfo();}diff --git a/test/src/test/groovy/org/openremote/test/users/UserResourceTest.groovy b/test/src/test/groovy/org/openremote/test/users/UserResourceTest.groovyindex 433f72082..482dedd6e 100644--- a/test/src/test/groovy/org/openremote/test/users/UserResourceTest.groovy+++ b/test/src/test/groovy/org/openremote/test/users/UserResourceTest.groovy@@ -107,7 +107,7 @@ class UserResourceTest extends Specification implements ManagerContainerTrait {false, // Value is ignored on update[roles.find {it.name == ClientRole.READ_LOGS.value}.id,- roles.find {it.name == ClientRole.READ_APPS.value}.id+ roles.find {it.name == ClientRole.READ_MAP.value}.id] as String[]).setDescription("This is a test"))adminUserResource.updateRoles(null, keycloakTestSetup.tenantBuilding.realm, updatedRoles as Role[])@@ -119,7 +119,7 @@ class UserResourceTest extends Specification implements ManagerContainerTrait {testRole.description == "This is a test"testRole.compositeRoleIds.length == 2testRole.compositeRoleIds.contains(roles.find {it.name == ClientRole.READ_LOGS.value}.id)- testRole.compositeRoleIds.contains(roles.find {it.name == ClientRole.READ_APPS.value}.id)+ testRole.compositeRoleIds.contains(roles.find {it.name == ClientRole.READ_MAP.value}.id)when: "an existing composite role is updated by the admin user"def writeRole = roles.find {it.name == ClientRole.WRITE.value}