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
Add read/write boolean attributes to ClientEventAgent instead of ClientRole[]
Rich Turner07c5e2e4ca1f
diff --git a/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventAgent.java b/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventAgent.javaindex 5d1308023..0496092a8 100644--- a/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventAgent.java+++ b/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventAgent.java@@ -36,7 +36,8 @@ public class ClientEventAgent extends Agent<ClientEventAgent, ClientEventProtocopublic static final ValueDescriptor<ClientRole> VALUE_CLIENT_ROLE = new ValueDescriptor<>("clientRole", ClientRole.class);public static final AttributeDescriptor<String> CLIENT_SECRET = new AttributeDescriptor<>("clientSecret", ValueType.TEXT);- public static final AttributeDescriptor<ClientRole[]> CLIENT_ROLES = new AttributeDescriptor<>("clientRoles", VALUE_CLIENT_ROLE.asArray());+ public static final AttributeDescriptor<Boolean> WRITE = new AttributeDescriptor<>("write", ValueType.BOOLEAN);+ public static final AttributeDescriptor<Boolean> READ = new AttributeDescriptor<>("read", ValueType.BOOLEAN);public static final AgentDescriptor<ClientEventAgent, ClientEventProtocol, AgentLink.Default> DESCRIPTOR =new AgentDescriptor<>(ClientEventAgent.class, ClientEventProtocol.class, AgentLink.Default.class@@ -62,7 +63,26 @@ public class ClientEventAgent extends Agent<ClientEventAgent, ClientEventProtocoreturn getAttributes().getValue(CLIENT_SECRET);}- public Optional<ClientRole[]> getClientRoles() {- return getAttributes().getValue(CLIENT_ROLES);+ public ClientEventAgent setClientSecret(String value) {+ getAttributes().getOrCreate(CLIENT_SECRET).setValue(value);+ return this;+ }++ public Optional<Boolean> isRead() {+ return getAttributes().getValue(READ);+ }++ public ClientEventAgent setRead(Boolean value) {+ getAttributes().getOrCreate(READ).setValue(value);+ return this;+ }++ public Optional<Boolean> isWrite() {+ return getAttributes().getValue(WRITE);+ }++ public ClientEventAgent setWrite(Boolean value) {+ getAttributes().getOrCreate(WRITE).setValue(value);+ return this;}}diff --git a/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventProtocol.javaindex 31413932a..f485888f8 100644--- a/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/event/ClientEventProtocol.java@@ -32,6 +32,8 @@ import org.openremote.model.attribute.AttributeState;import org.openremote.model.security.ClientRole;import org.openremote.model.syslog.SyslogCategory;+import java.util.ArrayList;+import java.util.List;import java.util.Objects;import java.util.UUID;import java.util.logging.Logger;@@ -67,12 +69,19 @@ public class ClientEventProtocol extends AbstractProtocol<ClientEventAgent, AgenString clientId = CLIENT_ID_PREFIX + agent.getId().substring(12);String clientSecret = agent.getClientSecret().orElse(UUID.randomUUID().toString());- ClientRole[] roles = agent.getClientRoles().orElse(null);+ List<ClientRole> roles = new ArrayList<>();++ if (agent.isRead().orElse(false)) {+ roles.add(ClientRole.READ_ASSETS);+ }+ if (agent.isWrite().orElse(false)) {+ roles.add(ClientRole.READ_ASSETS);+ }ProtocolClientEventService.ClientCredentials clientCredentials =new ProtocolClientEventService.ClientCredentials(agent.getRealm(),- roles,+ roles.toArray(new ClientRole[0]),clientId,clientSecret);