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
Make READ_ONLY meta item only relevant for UI purposes
Rich Turner668398ada73b
diff --git a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.javaindex 36e8ebe7b..cacc7fb69 100644--- a/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/AbstractProtocol.java@@ -117,10 +117,6 @@ public abstract class AbstractProtocol<T extends Agent<T, ?, U>, U extends AgentLOG.info("Attempt to write to attribute that is not actually linked to this protocol '" + AbstractProtocol.this + "': " + linkedAttribute);return;}- if (linkedAttribute.getMetaValue(MetaItemType.READ_ONLY).orElse(false)) {- LOG.info("Attempt to write to readonly attribute: " + linkedAttribute);- return;- }processLinkedAttributeWrite(event);});diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.javaindex a9971dfc0..bbc44f9ce 100644--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java@@ -301,10 +301,6 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerif (!oldAttribute.hasMeta(MetaItemType.ACCESS_PUBLIC_WRITE)) {throw new AssetProcessingException(INSUFFICIENT_ACCESS);}- // Check read-only- if (oldAttribute.getMetaValue(MetaItemType.READ_ONLY).orElse(false)) {- throw new AssetProcessingException(INSUFFICIENT_ACCESS);- }} else {// Check realm, must be accessibleif (!identityService.getIdentityProvider().isTenantActiveAndAccessible(authContext,@@ -312,11 +308,6 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSerthrow new AssetProcessingException(INSUFFICIENT_ACCESS);}- // Check read-only- if (oldAttribute.getMetaValue(MetaItemType.READ_ONLY).orElse(false) && !authContext.isSuperUser()) {- throw new AssetProcessingException(INSUFFICIENT_ACCESS);- }-// Regular user must have write attributes roleif (!authContext.hasResourceRoleOrIsSuperUser(ClientRole.WRITE_ATTRIBUTES.getValue(),authContext.getClientId())) {diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java b/manager/src/main/java/org/openremote/manager/notification/NotificationService.javaindex 6f7b03918..a60410ab9 100644--- a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java@@ -333,8 +333,8 @@ public class NotificationService extends RouteBuilder implements ContainerServicStringBuilder builder = new StringBuilder();builder.append("select n from SentNotification n where 1=1");List<Object> parameters = new ArrayList<>();- processCriteria(builder, parameters, ids, types, fromTimestamp, toTimestamp, tenantIds, userIds, assetIds);-+ processCriteria(builder, parameters, ids, types, fromTimestamp, toTimestamp, tenantIds, userIds, assetIds, false);+ builder.append(" order by n.sentOn asc");return persistenceService.doReturningTransaction(entityManager -> {TypedQuery<SentNotification> query = entityManager.createQuery(builder.toString(), SentNotification.class);IntStream.range(0, parameters.size())@@ -356,7 +356,7 @@ public class NotificationService extends RouteBuilder implements ContainerServicStringBuilder builder = new StringBuilder();builder.append("delete from SentNotification n where 1=1");List<Object> parameters = new ArrayList<>();- processCriteria(builder, parameters, ids, types, fromTimestamp, toTimestamp, tenantIds, userIds, assetIds);+ processCriteria(builder, parameters, ids, types, fromTimestamp, toTimestamp, tenantIds, userIds, assetIds, true);persistenceService.doTransaction(entityManager -> {Query query = entityManager.createQuery(builder.toString());@@ -366,7 +366,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic});}- protected void processCriteria(StringBuilder builder, List<Object> parameters, List<Long> ids, List<String> types, Long fromTimestamp, Long toTimestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds) {+ protected void processCriteria(StringBuilder builder, List<Object> parameters, List<Long> ids, List<String> types, Long fromTimestamp, Long toTimestamp, List<String> tenantIds, List<String> userIds, List<String> assetIds, boolean isRemove) {boolean hasIds = ids != null && !ids.isEmpty();boolean hasTypes = types != null && !types.isEmpty();boolean hasTenants = tenantIds != null && !tenantIds.isEmpty();@@ -390,7 +390,7 @@ public class NotificationService extends RouteBuilder implements ContainerServiccounter++;}- if (fromTimestamp == null && toTimestamp == null && counter == 0) {+ if (isRemove && fromTimestamp == null && toTimestamp == null && counter == 0) {LOG.info("No filters set for remove notifications request so not allowed");throw new IllegalArgumentException("No criteria specified");}diff --git a/model/src/main/java/org/openremote/model/value/MetaItemType.java b/model/src/main/java/org/openremote/model/value/MetaItemType.javaindex 7bcaf200e..5e41c328a 100644--- a/model/src/main/java/org/openremote/model/value/MetaItemType.java+++ b/model/src/main/java/org/openremote/model/value/MetaItemType.java@@ -76,9 +76,7 @@ public final class MetaItemType {public static final MetaItemDescriptor<Boolean> ACCESS_RESTRICTED_WRITE = new MetaItemDescriptor<>("accessRestrictedWrite", ValueType.BOOLEAN);/**- * Marks the attribute as read-only for non-superuser clients. South-bound {@link AttributeEvent}s by regular or- * restricted users are ignored. North-bound {@link AttributeEvent}s made by protocols and rules engine are- * possible.+ * Marks the attribute as read-only for UI purposes only; this does not offer any authorisation/security.*/public static final MetaItemDescriptor<Boolean> READ_ONLY = new MetaItemDescriptor<>("readOnly", ValueType.BOOLEAN);diff --git a/test/src/test/groovy/org/openremote/test/mqtt/MqttBrokerTest.groovy b/test/src/test/groovy/org/openremote/test/mqtt/MqttBrokerTest.groovyindex 05ee0032b..273fe3270 100644--- a/test/src/test/groovy/org/openremote/test/mqtt/MqttBrokerTest.groovy+++ b/test/src/test/groovy/org/openremote/test/mqtt/MqttBrokerTest.groovy@@ -161,11 +161,17 @@ class MqttBrokerTest extends Specification implements ManagerContainerTrait {def payload = ValueUtil.asJSON(new AttributeEvent(managerTestSetup.apartment1HallwayId, "motionSensor", 70)).get()client.sendMessage(new MQTTMessage<String>(topic, payload))- then: "The value of the attribute shouldn't be updated"+ then: "The value of the attribute should be updated and the client should have received the event"new PollingConditions(initialDelay: 1, timeout: 10, delay: 1).eventually {def asset = assetStorageService.find(managerTestSetup.apartment1HallwayId)- assert asset.getAttribute("motionSensor").get().value.orElse(0) == 50d+ assert asset.getAttribute("motionSensor").get().value.orElse(0) == 70d+ assert receivedEvents.size() == 1+ assert receivedEvents.get(0) instanceof AttributeEvent+ assert (receivedEvents.get(0) as AttributeEvent).assetId == managerTestSetup.apartment1HallwayId+ assert (receivedEvents.get(0) as AttributeEvent).attributeName == "motionSensor"+ assert (receivedEvents.get(0) as AttributeEvent).value.orElse(0) == 70d}+ receivedEvents.clear()when: "a mqtt client publishes to an asset attribute which is not readonly"payload = ValueUtil.asJSON(new AttributeEvent(managerTestSetup.apartment1HallwayId, "lights", false)).get()