From 9cef6f0d8cbc19532e3409452736973e9a8104ca Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Mon, 26 Sep 2016 11:18:22 +0530 Subject: [PATCH] Few Fixes to the virtual firealarm analytics view. --- .../analytics-view.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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 e4b0e14b0..64d5a078c 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 @@ -18,27 +18,31 @@ function onRequest(context) { var log = new Log("stats.js"); + var carbonServer = require("carbon").server; var device = context.unit.params.device; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); + var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss"); - var jwtService = carbon.server.osgiService('org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); + var jwtService = carbonServer.osgiService( + 'org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); var jwtClient = jwtService.getJWTClient(); - var encodedClientKeys = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER); + var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); 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 tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"]; + var resp = tokenUtil.decode(encodedClientKeys).split(":"); + log.error(resp); + 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 tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username, + "{\"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; + "token=" + token + "&deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type; } - return {"device": device, "websocketEndpoint" : websocketEndpoint}; + return {"device": device, "websocketEndpoint": websocketEndpoint}; } \ No newline at end of file