From 48c89b06b941b937cc4853b86f9531254cb9153e Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 14 Aug 2019 08:52:49 +0530 Subject: [PATCH 1/7] Add test case for newly added method on DeviceManagementProviderService --- .../mocks/DeviceManagementProviderServiceMock.java | 8 ++++++++ .../mocks/DeviceManagementProviderServiceMock.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 40bbfbb033..3ab0fa16a8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -20,6 +20,7 @@ package org.wso2.carbon.mdm.services.android.mocks; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -617,4 +618,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv public boolean updateEnrollment(String owner, List deviceIdentifiers) { return false; } + + @Override + public DeviceConfiguration getDevicesConfiguration(Map map) + throws DeviceManagementException, DeviceNotFoundException, InvalidArgumentException, + UnauthorizedDeviceAccessException { + return null; + } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 40bbfbb033..3ab0fa16a8 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -20,6 +20,7 @@ package org.wso2.carbon.mdm.services.android.mocks; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -617,4 +618,11 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv public boolean updateEnrollment(String owner, List deviceIdentifiers) { return false; } + + @Override + public DeviceConfiguration getDevicesConfiguration(Map map) + throws DeviceManagementException, DeviceNotFoundException, InvalidArgumentException, + UnauthorizedDeviceAccessException { + return null; + } } From bc38a4a6d6bccace2e4891204b6be5b2a9956f53 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 27 Aug 2019 23:37:22 +0530 Subject: [PATCH 2/7] Fix test fail due to not overriding getDeviceConfiguration method --- .../android/mocks/DeviceManagementProviderServiceMock.java | 7 ++++--- .../android/mocks/DeviceManagementProviderServiceMock.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 3ab0fa16a8..414f232b67 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -19,6 +19,7 @@ package org.wso2.carbon.mdm.services.android.mocks; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; @@ -620,9 +621,9 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } @Override - public DeviceConfiguration getDevicesConfiguration(Map map) - throws DeviceManagementException, DeviceNotFoundException, InvalidArgumentException, - UnauthorizedDeviceAccessException { + public DeviceConfiguration getDeviceConfiguration(Map propertyMap) + throws DeviceManagementException, DeviceNotFoundException, UnauthorizedDeviceAccessException, + AmbiguousConfigurationException{ return null; } } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 3ab0fa16a8..414f232b67 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.v09.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -19,6 +19,7 @@ package org.wso2.carbon.mdm.services.android.mocks; import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; @@ -620,9 +621,9 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } @Override - public DeviceConfiguration getDevicesConfiguration(Map map) - throws DeviceManagementException, DeviceNotFoundException, InvalidArgumentException, - UnauthorizedDeviceAccessException { + public DeviceConfiguration getDeviceConfiguration(Map propertyMap) + throws DeviceManagementException, DeviceNotFoundException, UnauthorizedDeviceAccessException, + AmbiguousConfigurationException{ return null; } } From ba24c1a03e10343e5f8b7c5f6d34934ece7e45bd Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 28 Aug 2019 13:06:22 +0530 Subject: [PATCH 3/7] Fix ent.app install issue when installing via roles --- .../mdm/osgiconnector/ApplicationOperationsImpl.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java index 25dbe42421..5977deeb3d 100644 --- a/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java +++ b/components/extensions/appm-connector/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java @@ -109,8 +109,13 @@ public class ApplicationOperationsImpl implements ApplicationOperations { .getDeviceManagementService(applicationOperationAction.getTenantId()). getAllDevicesOfRole(userRole); for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { - if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) { - deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + if (MDMAppConstants.WEBAPP.equals(applicationOperationAction.getApp().getPlatform()) + || applicationOperationAction.getApp().getPlatform() + .equalsIgnoreCase(device.getType())) { + if (MDMAppConstants.ACTIVE + .equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) { + deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + } } } } From d4f3e87c3bb46900ba1a453c2ed4526eadcb9f23 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Fri, 30 Aug 2019 10:00:53 +0530 Subject: [PATCH 4/7] CDM version change to 3.2.9-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a150b6b4cd..b5091ea9c4 100644 --- a/pom.xml +++ b/pom.xml @@ -1242,7 +1242,7 @@ 1.1.1 - 3.2.8 + 3.2.9-SNAPSHOT [3.1.0, 4.0.0) From e0113824c0bf395d3f8f54d9a6452e79570bb903 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 6 Sep 2019 19:14:11 +0530 Subject: [PATCH 5/7] Fix build failure --- .../config/AuthorizationConfiguration.java | 1 - .../src/test/resources/sql/h2.sql | 66 +++++++++++++++---- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/config/AuthorizationConfiguration.java b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/config/AuthorizationConfiguration.java index 547f74ff70..c54e57c1f1 100644 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/config/AuthorizationConfiguration.java +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/config/AuthorizationConfiguration.java @@ -31,7 +31,6 @@ import org.apache.commons.logging.LogFactory; import org.jaxen.JaxenException; import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.exception.AuthorizationException; import org.wso2.carbon.utils.CarbonUtils; -import org.wso2.carbon.utils.ServerConstants; import org.wso2.securevault.SecretResolver; import org.wso2.securevault.SecretResolverFactory; diff --git a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql index 686d0a6b3b..dd09806684 100644 --- a/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql +++ b/components/extensions/siddhi-extensions/org.wso2.extension.siddhi.device/src/test/resources/sql/h2.sql @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, - OWNER VARCHAR(45) DEFAULT NULL, + OWNER VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); @@ -50,6 +50,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID) ); +CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES ( + GROUP_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (GROUP_ID, PROPERTY_NAME, TENANT_ID) +); + CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER DEFAULT NULL, @@ -109,7 +117,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, - OWNER VARCHAR(50) NOT NULL, + OWNER VARCHAR(255) NOT NULL, OWNERSHIP VARCHAR(45) DEFAULT NULL, STATUS VARCHAR(50) NULL, DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL, @@ -301,7 +309,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( POLICY_CRITERION_ID INT NOT NULL, PROP_KEY VARCHAR(45) NULL, PROP_VALUE VARCHAR(100) NULL, - CONTENT BLOB NULL COMMENT 'This is used to ', + CONTENT BLOB NULL, PRIMARY KEY (ID), CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES FOREIGN KEY (POLICY_CRITERION_ID) @@ -366,13 +374,28 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, APPLICATION_ID INTEGER NOT NULL, + APP_PROPERTIES BLOB NULL, + MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID), - CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES - DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES - DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + CONSTRAINT fk_dm_device + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT fk_dm_application + FOREIGN KEY (APPLICATION_ID) + REFERENCES DM_APPLICATION (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_APP_MAP_DM_ENROL + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION ); -- POLICY RELATED TABLES FINISHED -- @@ -381,34 +404,40 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, - OPERATION_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NULL, TENANT_ID INTEGER NOT NULL, STATUS VARCHAR(10) NULL, DESCRIPTION VARCHAR(1000) NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PRIMARY KEY (NOTIFICATION_ID), CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES - DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES - DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -- NOTIFICATION TABLE END -- CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INT NULL, + ENROLMENT_ID INT NOT NULL, KEY_FIELD VARCHAR(45) NULL, - VALUE_FIELD VARCHAR(100) NULL, + VALUE_FIELD VARCHAR(1000) NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION ON UPDATE NO ACTION ); CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INT NULL, + ENROLMENT_ID INT NOT NULL, LATITUDE DOUBLE NULL, LONGITUDE DOUBLE NULL, STREET1 VARCHAR(255) NULL, @@ -417,18 +446,26 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + GEO_HASH VARCHAR(45) NULL, UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC); CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, + ENROLMENT_ID INT NOT NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, OS_VERSION VARCHAR(45) NULL, @@ -450,6 +487,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION ON UPDATE NO ACTION ); From 35a302e306ac5e1d2b486547bb2464a0c48b0207 Mon Sep 17 00:00:00 2001 From: Turcy Date: Mon, 9 Sep 2019 22:46:41 +0530 Subject: [PATCH 6/7] Fix websocket event stream validation --- .../websocket/WebsocketEventAdapter.java | 49 ++++++++++++++----- .../constants/WebsocketConstants.java | 2 + 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java index ac76d66c8b..cbc61acbea 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.json.JSONObject; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.databridge.commons.Attribute; import org.wso2.carbon.databridge.commons.StreamDefinition; import org.wso2.carbon.device.mgt.output.adapter.websocket.constants.WebsocketConstants; import org.wso2.carbon.device.mgt.output.adapter.websocket.internal.WebsocketEventAdaptorServiceDataHolder; @@ -39,7 +38,6 @@ import org.wso2.carbon.event.stream.core.EventStreamService; import org.wso2.carbon.event.stream.core.exception.EventStreamConfigurationException; import java.io.IOException; -import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -50,7 +48,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /** - * Contains the life cycle of executions regarding the UI Adapter + * Contains the life cycle of executions regarding the UI Adapter. */ public class WebsocketEventAdapter implements OutputEventAdapter { @@ -137,8 +135,8 @@ public class WebsocketEventAdapter implements OutputEventAdapter { String adapterName = streamSpecifAdapterMap.get(streamId); if (adapterName != null) { - throw new OutputEventAdapterException(("An Output websocket event adapter \"" + adapterName + "\" is already" + - " exist for stream id \"" + streamId + "\"")); + throw new OutputEventAdapterException(("An Output websocket event adapter \"" + adapterName + "\" is " + + "already exist for stream id \"" + streamId + "\"")); } else { streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); @@ -287,17 +285,46 @@ public class WebsocketEventAdapter implements OutputEventAdapter { return validSessions; } - private boolean validateJsonMessageAgainstEventFilters(String eventString, WebSocketSessionRequest webSocketSessionRequest) { + private boolean validateJsonMessageAgainstEventFilters(String eventString, + WebSocketSessionRequest webSocketSessionRequest) { Map queryParamValuePairs = webSocketSessionRequest.getQueryParamValuePairs(); String deviceId = queryParamValuePairs.get(WebsocketConstants.DEVICE_ID); String deviceType = queryParamValuePairs.get(WebsocketConstants.DEVICE_TYPE); - JSONObject eventObj = new JSONObject(eventString); - if (deviceId != null && !deviceId.equals(eventObj.getString(WebsocketConstants.DEVICE_ID))) { - return false; + JSONObject rootObj = new JSONObject(eventString); + if (deviceId == null && deviceType == null) { + return true; } - if (deviceType != null && !deviceType.equals(eventObj.getString(WebsocketConstants.DEVICE_TYPE))) { - return false; + + if (deviceType != null) { + if (rootObj.has(WebsocketConstants.DEVICE_TYPE)) { + if (!deviceType.equals(rootObj.getString(WebsocketConstants.DEVICE_TYPE))) { + return false; + } + } else if (rootObj.has(WebsocketConstants.EVENT)) { + JSONObject eventObj = (JSONObject) rootObj.get(WebsocketConstants.EVENT); + if (eventObj.has(WebsocketConstants.META_DATA)) { + JSONObject metaDataObj = (JSONObject) eventObj.get(WebsocketConstants.META_DATA); + if (metaDataObj.has(WebsocketConstants.DEVICE_TYPE) + && !deviceType.equals(metaDataObj.getString(WebsocketConstants.DEVICE_TYPE))) { + return false; + } + } + } } + + if (deviceId != null) { + if (rootObj.has(WebsocketConstants.DEVICE_ID)) { + return deviceId.equals(rootObj.getString(WebsocketConstants.DEVICE_ID)); + } else if (rootObj.has(WebsocketConstants.EVENT)) { + JSONObject eventObj = (JSONObject) rootObj.get(WebsocketConstants.EVENT); + if (eventObj.has(WebsocketConstants.META_DATA)) { + JSONObject metaDataObj = (JSONObject) eventObj.get(WebsocketConstants.META_DATA); + return !metaDataObj.has(WebsocketConstants.DEVICE_ID) + || deviceId.equals(metaDataObj.getString(WebsocketConstants.DEVICE_ID)); + } + } + } + return true; } diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java index 3af5ca044a..bc87ef0030 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java @@ -35,4 +35,6 @@ public class WebsocketConstants { public static final String PASSWORD = "password"; public static final String DEVICE_ID = "deviceId"; public static final String DEVICE_TYPE = "deviceType"; + public static final String EVENT = "event"; + public static final String META_DATA = "metaData"; } From 326b09b000a2da9b030808489c2db650b85e59cb Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 11 Sep 2019 18:48:34 +0530 Subject: [PATCH 7/7] Bump app manger version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b5091ea9c4..3cf3e9c0b2 100644 --- a/pom.xml +++ b/pom.xml @@ -1246,7 +1246,7 @@ [3.1.0, 4.0.0) - 1.5.5 + 1.5.6-SNAPSHOT 4.2.9-SNAPSHOT