-
Notifications
You must be signed in to change notification settings - Fork 0
Add MSP configuration parser for Hayward OmniLogic local binding #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
| import com.thoughtworks.xstream.annotations.XStreamImplicit; | ||
|
|
||
| /** | ||
| * Representation of the Backyard element within the MSP configuration. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Backyard") | ||
| public class BackyardConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamImplicit(itemFieldName = "BodyOfWater") | ||
| private final List<BodyOfWaterConfig> bodiesOfWater = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Pump") | ||
| private final List<PumpConfig> pumps = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Filter") | ||
| private final List<FilterConfig> filters = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Heater") | ||
| private final List<HeaterConfig> heaters = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "VirtualHeater") | ||
| private final List<VirtualHeaterConfig> virtualHeaters = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Chlorinator") | ||
| private final List<ChlorinatorConfig> chlorinators = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "ColorLogic-Light") | ||
| private final List<ColorLogicLightConfig> colorLogicLights = new ArrayList<>(); | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Relay") | ||
| private final List<RelayConfig> relays = new ArrayList<>(); | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public List<BodyOfWaterConfig> getBodiesOfWater() { | ||
| return bodiesOfWater; | ||
| } | ||
|
|
||
| public List<PumpConfig> getPumps() { | ||
| return pumps; | ||
| } | ||
|
|
||
| public List<FilterConfig> getFilters() { | ||
| return filters; | ||
| } | ||
|
|
||
| public List<HeaterConfig> getHeaters() { | ||
| return heaters; | ||
| } | ||
|
|
||
| public List<VirtualHeaterConfig> getVirtualHeaters() { | ||
| return virtualHeaters; | ||
| } | ||
|
|
||
| public List<ChlorinatorConfig> getChlorinators() { | ||
| return chlorinators; | ||
| } | ||
|
|
||
| public List<ColorLogicLightConfig> getColorLogicLights() { | ||
| return colorLogicLights; | ||
| } | ||
|
|
||
| public List<RelayConfig> getRelays() { | ||
| return relays; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a BodyOfWater element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("BodyOfWater") | ||
| public class BodyOfWaterConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a Chlorinator element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Chlorinator") | ||
| public class ChlorinatorConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a ColorLogic light element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("ColorLogic-Light") | ||
| public class ColorLogicLightConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
|
||
| import com.thoughtworks.xstream.XStream; | ||
| import com.thoughtworks.xstream.io.xml.StaxDriver; | ||
| import com.thoughtworks.xstream.security.AnyTypePermission; | ||
|
|
||
| /** | ||
| * Utility for parsing MSP configuration XML using XStream. | ||
| */ | ||
| @NonNullByDefault | ||
| public final class ConfigParser { | ||
| private static final XStream XSTREAM = new XStream(new StaxDriver()); | ||
|
|
||
| static { | ||
| XSTREAM.ignoreUnknownElements(); | ||
| XSTREAM.addPermission(AnyTypePermission.ANY); | ||
| XSTREAM.processAnnotations(MspConfig.class); | ||
| } | ||
|
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Register annotations for nested MSP config types The parser only calls Useful? React with 👍 / 👎. |
||
|
|
||
| private ConfigParser() { | ||
| } | ||
|
|
||
| public static MspConfig parse(String xml) { | ||
| return (MspConfig) XSTREAM.fromXML(xml); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a Filter element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Filter") | ||
| public class FilterConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamAsAttribute | ||
| @XStreamAlias("pumpId") | ||
| private @Nullable String pumpId; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public @Nullable String getPumpId() { | ||
| return pumpId; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a Heater element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Heater") | ||
| public class HeaterConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamAsAttribute | ||
| private @Nullable String type; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public @Nullable String getType() { | ||
| return type; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamImplicit; | ||
|
|
||
| /** | ||
| * Representation of the MSP configuration root element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("MspConfig") | ||
| public class MspConfig { | ||
| @XStreamImplicit(itemFieldName = "System") | ||
| private final List<SystemConfig> systems = new ArrayList<>(); | ||
|
|
||
| public List<SystemConfig> getSystems() { | ||
| return systems; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a Pump element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Pump") | ||
| public class PumpConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamAsAttribute | ||
| private @Nullable String name; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public @Nullable String getName() { | ||
| return name; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a Relay element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("Relay") | ||
| public class RelayConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamAsAttribute | ||
| private @Nullable String name; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public @Nullable String getName() { | ||
| return name; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
| import com.thoughtworks.xstream.annotations.XStreamImplicit; | ||
|
|
||
| /** | ||
| * Representation of the System element within the MSP configuration. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("System") | ||
| public class SystemConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| @XStreamImplicit(itemFieldName = "Backyard") | ||
| private final List<BackyardConfig> backyards = new ArrayList<>(); | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
|
|
||
| public List<BackyardConfig> getBackyards() { | ||
| return backyards; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.openhab.binding.haywardomnilogiclocal.internal.config; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNullByDefault; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| import com.thoughtworks.xstream.annotations.XStreamAlias; | ||
| import com.thoughtworks.xstream.annotations.XStreamAsAttribute; | ||
|
|
||
| /** | ||
| * Representation of a VirtualHeater element. | ||
| */ | ||
| @NonNullByDefault | ||
| @XStreamAlias("VirtualHeater") | ||
| public class VirtualHeaterConfig { | ||
| @XStreamAsAttribute | ||
| @XStreamAlias("systemId") | ||
| private @Nullable String systemId; | ||
|
|
||
| public @Nullable String getSystemId() { | ||
| return systemId; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Remove unrestricted XStream
AnyTypePermissionGranting
AnyTypePermission.ANYdisables XStream’s security model and allows deserialization of arbitrary classes. If the MSP configuration XML ever comes from a compromised device or from the network, this creates an RCE surface in the binding. Restrict the allowed types to the concrete config classes instead of granting global permission.Useful? React with 👍 / 👎.