Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

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.java
index 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, ClientEventProtoco
public 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, ClientEventProtoco
return 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.java
index 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, Agen
String 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
);