From 8e5aa7735d80aeadb5df0ba1c7da0b8729245f94 Mon Sep 17 00:00:00 2001 From: lasantha Date: Sat, 24 Feb 2018 05:45:34 +0530 Subject: [PATCH] Add device remote controlling for tenants The remote control feature didn't work for tenants and this commit fixes that issue. The root cause of this issue is that the server doesn't connect to the WebSocket in the tenant mode. In order to connect to the WebSocket, it is required to provide valid access token. When getting access token, in the tenant mode it is required to pass tenant domain along with the context of the username. --- .../device-view.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index 338320b3f..719f881f4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -189,14 +189,19 @@ function onRequest(context) { var jwtService = carbonServer.osgiService('org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService'); var jwtClient = jwtService.getJWTClient(); var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"]); + var tokenPair = null; var token = ""; if (encodedClientKeys) { var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"]; var resp = tokenUtil.decode(encodedClientKeys).split(":"); - var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {}); + if (context.user.domain == "carbon.super") { + tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {}); + } else { + tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + context.user.domain,"default", {}); + } if (tokenPair) { token = tokenPair.accessToken; - } + } } remoteSessionEndpoint = remoteSessionEndpoint + "/remote/session/clients/" + deviceType + "/" + deviceId + "?websocketToken=" + token