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 the possibility to set secret to a MetaItemDescriptor in order to hide the content in the UI
Michael Rademaker3fe5408a1fd1
diff --git a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent/protocol/Protocol.javaindex 82d0fd82e..3ee4b5e1e 100644--- a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java@@ -199,6 +199,7 @@ public interface Protocol extends ContainerService {PROTOCOL_NAMESPACE + ":password",ACCESS_PRIVATE,false,+ true,REGEXP_PATTERN_STRING_NON_EMPTY,PatternFailure.STRING_EMPTY);diff --git a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.javaindex 024e52cdc..5b71e71fb 100644--- a/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java+++ b/agent/src/main/java/org/openremote/agent/protocol/timer/TimerProtocol.java@@ -82,7 +82,7 @@ public class TimerProtocol extends AbstractProtocol {null,null,null,- false, null, null, null)+ false, null, null, null, false));protected static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Collections.singletonList(diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.javaindex eb6ddf00d..b95fb4a23 100644--- a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java@@ -400,7 +400,7 @@ public abstract class AbstractAssetActivity<Vif (valueHolder instanceof MetaItem) {// TODO Should use meta item descriptors from serverreturn Arrays.stream(MetaItemType.values())- .filter(assetMeta -> assetMeta.getUrn().equals(((MetaItem) valueHolder).getName()))+ .filter(assetMeta -> assetMeta.getUrn().equals(((MetaItem) valueHolder).getName().orElse("NotFound"))).map(MetaItemType::isValueFixed).findFirst().orElse(false);}@@ -446,6 +446,7 @@ public abstract class AbstractAssetActivity<VonValueModified,timestamp,isReadOnly,+ false,getEditorStyleName(valueType, style),environment.getWidgetStyle(),environment.getMessages()diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.javaindex 209cc64c8..3e7d984ed 100644--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java@@ -21,6 +21,7 @@ package org.openremote.app.client.assets.asset;import com.google.gwt.user.client.ui.IsWidget;import org.openremote.app.client.Environment;+import org.openremote.app.client.app.AppControllerImpl;import org.openremote.app.client.assets.*;import org.openremote.app.client.assets.attributes.*;import org.openremote.app.client.assets.browser.AssetBrowser;@@ -59,6 +60,7 @@ import org.openremote.model.value.Values;import javax.inject.Inject;import java.util.*;import java.util.function.Predicate;+import java.util.logging.Logger;import java.util.stream.Collectors;import static org.openremote.model.asset.AssetAttribute.attributesFromJson;@@ -73,6 +75,8 @@ public class AssetEditActivityextends AbstractAssetActivity<AssetEdit.Presenter, AssetEdit, AssetEditPlace>implements AssetEdit.Presenter {+ private static final Logger LOG = Logger.getLogger(AssetEditActivity.class.getName());+protected final AssetBrowser assetBrowser;protected final AssetResource assetResource;protected final AgentResource agentResource;@@ -434,13 +438,13 @@ public class AssetEditActivityString assetWatermark = environment.getMessages().selectAgent();String attributeWatermark = environment.getMessages().selectProtocolConfiguration();return new AttributeRefEditor(- valueHolder.getValue().flatMap(AttributeRef::fromValue).orElse(null),- attrRef -> onValueModified.accept(attrRef != null ? attrRef.toArrayValue() : null),- isReadOnly,- assetAttributeConsumer -> getLinkableAssetsAndAttributes(valueHolder, assetAttributeConsumer),- assetWatermark,- attributeWatermark,- style.agentLinkEditor()+ valueHolder.getValue().flatMap(AttributeRef::fromValue).orElse(null),+ attrRef -> onValueModified.accept(attrRef != null ? attrRef.toArrayValue() : null),+ isReadOnly,+ assetAttributeConsumer -> getLinkableAssetsAndAttributes(valueHolder, assetAttributeConsumer),+ assetWatermark,+ attributeWatermark,+ style.agentLinkEditor());}}@@ -452,21 +456,45 @@ public class AssetEditActivityString assetWatermark = environment.getMessages().selectAsset();String attributeWatermark = environment.getMessages().selectAttribute();return new AttributeLinkEditor(- environment,- style,- parentView,- this::createValueEditor,- this::showValidationError,- valueHolder.getValue().map(Value::toJson).map(attributeLinkMapper::read).orElse(null),- attrLink -> {- Value attrLinkObj = attrLink != null ? Values.parse(attributeLinkMapper.write(attrLink)).orElse(null) : null;- onValueModified.accept(attrLinkObj);- },- isReadOnly,- assetAttributeConsumer -> getLinkableAssetsAndAttributes(valueHolder, assetAttributeConsumer),- assetWatermark,- attributeWatermark,- style.agentLinkEditor()+ environment,+ style,+ parentView,+ this::createValueEditor,+ this::showValidationError,+ valueHolder.getValue().map(Value::toJson).map(attributeLinkMapper::read).orElse(null),+ attrLink -> {+ Value attrLinkObj = attrLink != null ? Values.parse(attributeLinkMapper.write(attrLink)).orElse(null) : null;+ onValueModified.accept(attrLinkObj);+ },+ isReadOnly,+ assetAttributeConsumer -> getLinkableAssetsAndAttributes(valueHolder, assetAttributeConsumer),+ assetWatermark,+ attributeWatermark,+ style.agentLinkEditor()+ );+ }+ }+ case STRING:+ if (valueHolder instanceof MetaItem) {+ if (metaItemDescriptors.stream()+ .filter(assetMeta -> assetMeta.getUrn().equals(((MetaItem) valueHolder).getName().orElse("NotFound")))+ .map(MetaItemDescriptor::isSecret)+ .findFirst().orElse(false)) {+++ boolean isReadOnly = isValueReadOnly(valueHolder);+ Optional<Long> timestamp = getTimestamp(valueHolder);++ return ValueEditors.createValueEditor(+ valueHolder.getValue().orElse(null),+ valueType,+ onValueModified,+ timestamp,+ isReadOnly,+ true,+ getEditorStyleName(valueType, style),+ environment.getWidgetStyle(),+ environment.getMessages());}}diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.javaindex 07e7dacb4..55b96c3d8 100644--- a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java@@ -516,6 +516,7 @@ public class NotificationEditorImpl implements NotificationEditor {onValueModified,Optional.empty(),false,+ false,null,widgetStyle,managerMessagesdiff --git a/client/src/main/java/org/openremote/app/client/widget/FormInputText.java b/client/src/main/java/org/openremote/app/client/widget/FormInputText.javaindex 01ed2df9e..840debaac 100644--- a/client/src/main/java/org/openremote/app/client/widget/FormInputText.java+++ b/client/src/main/java/org/openremote/app/client/widget/FormInputText.java@@ -24,6 +24,7 @@ import com.google.gwt.user.client.ui.TextBox;public class FormInputText extends TextBox {String placeholder = "";+ boolean isSecret = false;boolean autofocus;@@ -46,6 +47,15 @@ public class FormInputText extends TextBox {getElement().setPropertyString("placeholder", placeholder);}+ public void setSecret(boolean isSecret) {+ this.isSecret = isSecret;+ if (this.isSecret) {+ getElement().setAttribute("type", "password");+ } else {+ getElement().setAttribute("type", "text");+ }+ }+public boolean isAutofocus() {return autofocus;}diff --git a/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java b/client/src/main/java/org/openremote/app/client/widget/ValueEditors.javaindex 4e33194c0..f045f4701 100644--- a/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java+++ b/client/src/main/java/org/openremote/app/client/widget/ValueEditors.java@@ -61,6 +61,7 @@ public final class ValueEditors {Consumer<Value> onValueModified,Optional<Long> timestamp,boolean readOnly,+ boolean isSecret,String styleName,WidgetStyle widgetStyle,ManagerMessages managerMessages) {@@ -104,7 +105,8 @@ public final class ValueEditors {onValueModified::accept,timestamp,readOnly,- styleName+ styleName,+ isSecret);case NUMBER:NumberValue currentValueNumber = Values.getNumber(currentValue).map(Values::create).orElse(null);@@ -133,14 +135,15 @@ public final class ValueEditors {Consumer<StringValue> onValueModified,Optional<Long> timestamp,boolean readOnly,- String styleName) {+ String styleName,+ boolean isSecret) {Consumer<String> updateConsumer = readOnly ? null : str ->onValueModified.accept(isNullOrEmpty(str) ? null : Values.create(str));FlowPanel panel = new FlowPanel();panel.setStyleName("flex layout horizontal center or-ValueEditor or-StringValueEditor");- IsWidget widget = ValueEditors.createStringEditorWidget(styleName, readOnly, currentValue != null ? currentValue.getString() : null, updateConsumer);+ IsWidget widget = ValueEditors.createStringEditorWidget(styleName, readOnly, currentValue != null ? currentValue.getString() : null, isSecret, updateConsumer);FlowPanel widgetWrapper = new FlowPanel();widgetWrapper.setStyleName("flex layout horizontal center");widgetWrapper.add(widget);@@ -171,7 +174,7 @@ public final class ValueEditors {FlowPanel panel = new FlowPanel();panel.setStyleName("flex layout horizontal center or-ValueEditor or-NumberValueEditor");- IsWidget widget = createStringEditorWidget(styleName, readOnly, currentValue != null ? currentValue.asString() : null, updateConsumer);+ IsWidget widget = createStringEditorWidget(styleName, readOnly, currentValue != null ? currentValue.asString() : null, false, updateConsumer);FlowPanel widgetWrapper = new FlowPanel();widgetWrapper.setStyleName("flex layout horizontal center");widgetWrapper.add(widget);@@ -282,6 +285,7 @@ public final class ValueEditors {private static IsWidget createStringEditorWidget(String styleName,boolean readOnly,String value,+ boolean isSecret,Consumer<String> updateConsumer) {FormInputText input = new FormInputText();if (!TextUtil.isNullOrEmpty(styleName)) {@@ -292,6 +296,7 @@ public final class ValueEditors {} else if (updateConsumer == null) {input.setValue("-");}+ input.setSecret(isSecret);if (updateConsumer != null && !readOnly) {// Both keyup and change (e.g. after pasting) must be usedinput.addKeyUpHandler(event ->diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.javaindex 82d32a415..dd8d7a81f 100644--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java@@ -203,4 +203,10 @@ public interface MetaItemDescriptor extends HasUniqueResourceName {* validation. If defined this takes priority over all other value checks.*/Optional<Function<Value, Optional<ValidationFailure>>> getValidator();++ /**+ * Indicates if the value should be obfuscated in the view, so the contents can't be read+ */+ @JsonProperty+ boolean isSecret();}diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.javaindex e96bed0a6..65cb83841 100644--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java@@ -47,6 +47,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {protected final Value[] allowedValues;protected final boolean valueFixed;protected final String patternFailureMessage;+ protected final boolean isSecret;@JsConstructor@JsonCreator@@ -61,7 +62,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {@JsonProperty("valueFixed") boolean valueFixed,@JsonProperty("allowedMin")Value allowedMin,@JsonProperty("allowedMax")Value allowedMax,- @JsonProperty("allowedValues")Value[] allowedValues) {+ @JsonProperty("allowedValues")Value[] allowedValues,+ @JsonProperty("isSecret") boolean isSecret) {this.urn = urn;this.valueType = valueType;this.access = access;@@ -74,6 +76,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {this.allowedMin = allowedMin;this.allowedMax = allowedMax;this.allowedValues = allowedValues;+ this.isSecret = isSecret;}@JsIgnore@@ -90,7 +93,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {metaItemDescriptor.getPatternFailureMessage(),metaItemDescriptor.getMaxPerAttribute(),initialValue,- metaItemDescriptor.isValueFixed(), null, null, null);+ metaItemDescriptor.isValueFixed(), null, null, null, metaItemDescriptor.isSecret());}@JsIgnore@@ -105,7 +108,23 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {Value allowedMin,Value allowedMax,Value[] allowedValues) {- this(urn, valueType, Access.ACCESS_PRIVATE, required, pattern, patternFailureMessage, maxPerAttribute, initialValue, valueFixed, allowedMin, allowedMax, allowedValues);+ this(urn, valueType, Access.ACCESS_PRIVATE, required, pattern, patternFailureMessage, maxPerAttribute, initialValue, valueFixed, allowedMin, allowedMax, allowedValues, false);+ }++ @JsIgnore+ public MetaItemDescriptorImpl(String urn,+ ValueType valueType,+ boolean required,+ String pattern,+ String patternFailureMessage,+ Integer maxPerAttribute,+ Value initialValue,+ boolean valueFixed,+ Value allowedMin,+ Value allowedMax,+ Value[] allowedValues,+ boolean isSecret) {+ this(urn, valueType, Access.ACCESS_PRIVATE, required, pattern, patternFailureMessage, maxPerAttribute, initialValue, valueFixed, allowedMin, allowedMax, allowedValues, isSecret);}@Override@@ -174,6 +193,11 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {return Optional.empty();}+ @Override+ public boolean isSecret() {+ return isSecret;+ }+@Overridepublic String toString() {return getClass().getSimpleName() + "{" +@@ -188,6 +212,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {", allowedMax=" + allowedMax +", allowedValues=" + (allowedValues != null ? Arrays.toString(allowedValues) : "null") +", valueFixed=" + valueFixed ++ ", isSecret=" + isSecret +", patternFailureMessage='" + patternFailureMessage + '\'' +'}';}@@ -206,7 +231,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {true,null,null,- null);+ null,+ false);}@JsIgnore@@ -225,7 +251,13 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- allowedValues != null ? Arrays.stream(allowedValues).map(Values::create).toArray(Value[]::new) : null);+ allowedValues != null ? Arrays.stream(allowedValues).map(Values::create).toArray(Value[]::new) : null,+ false);+ }++ @JsIgnore+ public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, boolean isSecret, String patternRegex, PatternFailure failureMessage) {+ return metaItemString(urn, access, required, isSecret, patternRegex, failureMessage.name());}@JsIgnore@@ -234,7 +266,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {}@JsIgnore- public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, String patternRegex, String patternFailureMessage) {+ public static MetaItemDescriptor metaItemString(String urn, Access access, boolean required, boolean isSecret, String patternRegex, String patternFailureMessage) {return new MetaItemDescriptorImpl(urn,ValueType.STRING,@@ -247,9 +279,11 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- null);+ null,+ isSecret);}+@JsIgnorepublic static MetaItemDescriptor metaItemInteger(String urn, Access access, boolean required, Integer minValue, Integer maxValue) {return new MetaItemDescriptorImpl(@@ -264,7 +298,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,minValue != null ? Values.create(minValue) : null,maxValue != null ? Values.create(maxValue) : null,- null);+ null,+ false);}@JsIgnore@@ -283,7 +318,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- values);+ values,+ false);}@JsIgnore@@ -300,7 +336,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- null);+ null,+ false);}@JsIgnore@@ -317,7 +354,8 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- null);+ null,+ false);}@JsIgnore@@ -340,6 +378,7 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {false,null,null,- null);+ null,+ false);}}diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemType.java b/model/src/main/java/org/openremote/model/attribute/MetaItemType.javaindex d91735f8e..b03d4f3fa 100644--- a/model/src/main/java/org/openremote/model/attribute/MetaItemType.java+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemType.java@@ -68,6 +68,7 @@ public enum MetaItemType implements MetaItemDescriptor {null,null,false,+ false,null,null,null,@@ -90,6 +91,7 @@ public enum MetaItemType implements MetaItemDescriptor {null,null,false,+ false,null,null,null,@@ -303,6 +305,7 @@ public enum MetaItemType implements MetaItemDescriptor {PatternFailure.INTEGER_POSITIVE_NON_ZERO.name(),null,false,+ false,Values.create(1d),null,null,@@ -407,6 +410,7 @@ public enum MetaItemType implements MetaItemDescriptor {protected final Value allowedMax;protected final Value[] allowedValues;final protected boolean valueFixed;+ final protected boolean isSecret;final protected Integer maxPerAttribute = 1; // All asset meta so far are single instancefinal protected boolean required = false; // All asset meta so far are not mandatoryfinal protected String pattern;@@ -415,7 +419,11 @@ public enum MetaItemType implements MetaItemDescriptor {final protected Function<Value, Optional<ValidationFailure>> validator;MetaItemType(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed) {- this(urn, access, valueType, pattern, patternFailureMessage, initialValue, valueFixed, null, null, null, null);+ this(urn, access, valueType, pattern, patternFailureMessage, initialValue, valueFixed, false, null, null, null, null);+ }++ MetaItemType(String urn, Access access, ValueType valueType, String pattern, String patternFailureMessage, Value initialValue, boolean valueFixed, boolean isSecret) {+ this(urn, access, valueType, pattern, patternFailureMessage, initialValue, valueFixed, isSecret, null, null, null, null);}MetaItemType(String urn,@@ -425,7 +433,11 @@ public enum MetaItemType implements MetaItemDescriptor {String patternFailureMessage,Value initialValue,boolean valueFixed,- Value allowedMin, Value allowedMax, Value[] allowedValues, Function<Value, Optional<ValidationFailure>> validator) {+ boolean isSecret,+ Value allowedMin,+ Value allowedMax,+ Value[] allowedValues,+ Function<Value, Optional<ValidationFailure>> validator) {if (initialValue != null && initialValue.getType() != valueType) {throw new IllegalStateException("Initial asset meta value must be of the same type as the asset meta");@@ -441,6 +453,7 @@ public enum MetaItemType implements MetaItemDescriptor {this.allowedMin = allowedMin;this.allowedMax = allowedMax;this.allowedValues = allowedValues;+ this.isSecret = isSecret;}@@ -484,6 +497,11 @@ public enum MetaItemType implements MetaItemDescriptor {return Optional.ofNullable(validator);}+ @Override+ public boolean isSecret() {+ return isSecret;+ }+@Overridepublic Value getInitialValue() {return initialValue;