From df5031737d8a5547e747c665cb35a6622f3caf6a Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Sat, 11 Apr 2020 13:01:22 +0300 Subject: [PATCH] Bug 562012 license is not recognized when USB disk is plugged - implement a fast inplace fix, yet to be redone in 0.9 with possible change of license/model formats Signed-off-by: elena.parovyshnaya --- .../lic/internal/oshi/OshiHardwareInspector.java | 4 +--- .../lic/internal/oshi/OshiPermissionEmitter.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiHardwareInspector.java b/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiHardwareInspector.java index d06f45863..b43a49fa1 100644 --- a/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiHardwareInspector.java +++ b/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiHardwareInspector.java @@ -42,8 +42,6 @@ public class OshiHardwareInspector implements HardwareInspector { private final Map hardwareProperties = new LinkedHashMap<>(); - private SystemInfo systemInfo; - private LicensingReporter licensingReporter = SystemReporter.INSTANCE; @Activate @@ -53,7 +51,7 @@ public void activate() { private void initHardwareProperties() { try { - systemInfo = new SystemInfo(); + SystemInfo systemInfo = new SystemInfo(); OperatingSystem os = systemInfo.getOperatingSystem(); hardwareProperties.put(HardwareInspector.PROPERTY_OS_MANUFACTURER, os.getManufacturer()); hardwareProperties.put(HardwareInspector.PROPERTY_OS_FAMILY, os.getFamily()); diff --git a/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiPermissionEmitter.java b/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiPermissionEmitter.java index a43762553..6166f6999 100644 --- a/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiPermissionEmitter.java +++ b/bundles/org.eclipse.passage.lic.oshi/src/org/eclipse/passage/lic/internal/oshi/OshiPermissionEmitter.java @@ -16,6 +16,8 @@ import static org.eclipse.passage.lic.base.LicensingProperties.LICENSING_CONDITION_TYPE_ID; import static org.eclipse.passage.lic.base.LicensingProperties.LICENSING_CONDITION_TYPE_NAME; +import java.util.Arrays; + import org.eclipse.passage.lic.api.access.PermissionEmitter; import org.eclipse.passage.lic.api.inspector.HardwareInspector; import org.eclipse.passage.lic.base.access.BasePermissionEmitter; @@ -24,6 +26,8 @@ import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import oshi.SystemInfo; + @Component(property = { LICENSING_CONDITION_TYPE_ID + '=' + OshiHal.CONDITION_TYPE_HARDWARE, LICENSING_CONDITION_TYPE_NAME + '=' + "Hardware", LICENSING_CONDITION_TYPE_DESCRIPTION + '=' + "Evaluates node-locked conditions using runtime hardware information" }) @@ -47,6 +51,12 @@ public void unbindHardwareInspector(HardwareInspector inspector) { @Override protected boolean evaluateSegment(String key, String expected) { + // FIXME: EP: fast hack for 562012, + // to be solved properly with formats alternations in 0.9 + if (key.equals(HardwareInspector.PROPERTY_HWDISK_SERIAL)) { + return Arrays.stream(new SystemInfo().getHardware().getDiskStores()) // + .anyMatch(disk -> LicensingConditions.evaluateSegmentValue(expected, disk.getSerial())); + } String actual = hardwareInspector.inspectProperty(key); return LicensingConditions.evaluateSegmentValue(expected, actual); }