From d650e86e00adbc0fe42c5ff3a05cff294b23ab8c Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 27 Jul 2016 14:45:31 +0530 Subject: [PATCH] few changes in real time analytics --- .../android_sense_publisher.xml | 2 +- .../temperature_publisher.xml | 2 +- .../pom.xml | 11 ++++++++- .../adapter/ui/config/Authenticator.java | 2 +- .../output/adapter/ui/config/Authorizer.java | 2 +- .../adapter/ui/config/WebsocketConfig.java | 3 --- .../ui/config/WebsocketValidationConfigs.java | 7 +++--- .../ui/util/UIEventAdapterConstants.java | 2 +- .../impl/VirtualFireAlarmServiceImpl.java | 9 ++++++-- .../analytics-view.js | 23 ++++++++++++++----- 10 files changed, 42 insertions(+), 21 deletions(-) diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml index f2da5e909b..1e16ab1789 100644 --- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml +++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.analytics/src/main/resources/carbonapps/androidsense/android_sense_publisher/android_sense_publisher.xml @@ -20,6 +20,6 @@ - + diff --git a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml index 3ab9a7d3f3..328268e7aa 100644 --- a/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml +++ b/components/iot-plugins/iot-analytics/org.wso2.carbon.device.mgt.iot.analytics/src/main/resources/carbonapps/temperature_sensor/temperature_publisher/temperature_publisher.xml @@ -20,6 +20,6 @@ - + diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml index 69181134b4..e8e7d3a9d3 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/pom.xml @@ -135,8 +135,17 @@ org.wso2.carbon.databridge.commons, org.wso2.carbon.event.stream.core, org.wso2.carbon.event.stream.core.exception, - org.wso2.carbon.utils + org.wso2.carbon.utils, + javax.xml.bind, + javax.xml.bind.annotation, + javax.xml.parsers; version=0.0.0, + org.w3c.dom, + org.wso2.carbon.identity.oauth2.stub, + org.wso2.carbon.identity.oauth2.stub.dto, + org.wso2.carbon.user.api, + org.wso2.carbon.utils.multitenancy + * diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authenticator.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authenticator.java index c6e7436663..8c064f3af2 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authenticator.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authenticator.java @@ -34,7 +34,7 @@ import javax.xml.bind.annotation.XmlType; }) public class Authenticator { - @XmlElement(name = "Properties", required = true) + @XmlElement(name = "Properties", required = false) protected Properties properties; @XmlAttribute(name = "class") protected String clazz; diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authorizer.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authorizer.java index 5f3de13451..881ef8a6b2 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authorizer.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/Authorizer.java @@ -34,7 +34,7 @@ import javax.xml.bind.annotation.XmlType; }) public class Authorizer { - @XmlElement(name = "Properties", required = true) + @XmlElement(name = "Properties", required = false) protected Properties properties; @XmlAttribute(name = "class") protected String clazz; diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketConfig.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketConfig.java index faf2d789b6..81b978a155 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketConfig.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketConfig.java @@ -38,9 +38,6 @@ public class WebsocketConfig { Unmarshaller unmarshaller = ctx.createUnmarshaller(); //unmarshaller.setSchema(getSchema()); websocketValidationConfigs = (WebsocketValidationConfigs) unmarshaller.unmarshal(doc); - if (websocketValidationConfigs != null) { - - } } catch (JAXBException e) { throw new WebsocketValidationConfigurationFailedException("Error occurred while un-marshalling Websocket" + " Config", e); diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketValidationConfigs.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketValidationConfigs.java index 08bdab872c..dc1e6457a5 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketValidationConfigs.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/config/WebsocketValidationConfigs.java @@ -4,6 +4,7 @@ package org.wso2.carbon.device.mgt.iot.output.adapter.ui.config; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; @@ -27,11 +28,9 @@ import javax.xml.bind.annotation.XmlType; * * */ + +@XmlRootElement(name = "WebsocketValidationConfigs") @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "WebsocketValidationConfigs", propOrder = { - "authenticator", - "authorizer" -}) public class WebsocketValidationConfigs { @XmlElement(name = "Authenticator", required = true) diff --git a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java index 8fdea199cb..fe175b76f8 100644 --- a/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java +++ b/components/iot-plugins/iot-base-plugin/org.wso2.carbon.device.mgt.iot.output.adapter.ui/src/main/java/org/wso2/carbon/device/mgt/iot/output/adapter/ui/util/UIEventAdapterConstants.java @@ -27,7 +27,7 @@ public class UIEventAdapterConstants { private UIEventAdapterConstants() { } - public static final String ADAPTER_TYPE_UI = "iot-ui"; + public static final String ADAPTER_TYPE_UI = "secured-ui"; public static final String ADAPTER_USAGE_TIPS_PREFIX = "ui.usage.tips_prefix"; public static final String ADAPTER_USAGE_TIPS_POSTFIX = "ui.usage.tips_postfix"; public static final String ADAPTER_UI_DEFAULT_OUTPUT_STREAM_VERSION = "1.0.0"; diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java index 315cdb37d1..d67f1f300f 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -82,6 +83,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { private static final String MQTT_PROTOCOL = "MQTT"; private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; + private static final String DEVICE_MGT_SCOPE_IDENTIFIER = "device-mgt"; private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class); @POST @@ -309,10 +311,13 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { VirtualFireAlarmConstants.DEVICE_TYPE, tags, KEY_TYPE, applicationUsername, true); } JWTClient jwtClient = APIUtil.getJWTClientManagerService().getJWTClient(); - String scopes = "cdmf/" + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; + String device = "{ \"scope\":\"mqtt-publisher mqtt-subscriber\", \"deviceIdentifiers\":[{\"id\":\""+deviceId+"\", " + + "\"type\":\""+VirtualFireAlarmConstants.DEVICE_TYPE+"\"}]}"; + Map params = new HashMap(); + params.put("device", Base64.encodeBase64String(device.getBytes())); AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(apiApplicationKey.getConsumerKey(), apiApplicationKey.getConsumerSecret(), owner, - scopes); + null, params); String accessToken = accessTokenInfo.getAccessToken(); String refreshToken = accessTokenInfo.getRefreshToken(); XmppAccount newXmppAccount = new XmppAccount(); diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js index c2f41383e2..e223a3dd15 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.realtime.analytics-view/analytics-view.js @@ -22,12 +22,23 @@ function onRequest(context) { var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var constants = require("/app/modules/constants.js"); var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss"); - var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); - var token = ""; - if (tokenPair) { - token = tokenPair.accessToken; + var jwtService = carbon.server.osgiService('org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); + var jwtClient = jwtService.getJWTClient(); + var encodedClientKeys = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER); + if (encodedClientKeys) { + var tokenUtil = require("/app/modules/util.js").util; + var resp = tokenUtil.decode(encodedClientKeys).split(","); + var user = session.get(constants.USER_SESSION_KEY); + var deviceParam = "{\"scope\":\"stats\",\"deviceIdentifiers\":[{\"id\":\""+device.deviceIdentifier+" \", \"type\":\""+device.type+"\"}]}"; + var encodedScope = tokenUtil.encode(deviceParam); + var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], user.username, null, + "{\"device\": \"" +encodedScope+"\"}"); + var token = ""; + if (tokenPair) { + token = tokenPair.accessToken; + } + websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.devices.temperature/1.0.0?" + + "token=" + token + "&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; } - websocketEndpoint = websocketEndpoint + "/secured-outputui/org.wso2.iot.devices.temperature/1.0.0?" + - "token="+ token +"&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; return {"device": device, "websocketEndpoint" : websocketEndpoint}; } \ No newline at end of file