From 8b4649b4e53261352069c52619e79da87f208028 Mon Sep 17 00:00:00 2001 From: amalhub Date: Mon, 3 Oct 2016 11:39:03 +0530 Subject: [PATCH 1/2] Fixing issue: EMM-1537 --- .../jaggeryapps/devicemgt/api/operation-api.jag | 7 ++++++- .../oauth/token-protected-service-invokers.js | 14 ++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag index 7465f21649a..ac30769bb47 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag @@ -51,7 +51,12 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) { } else { response["status"] = restAPIResponse["status"]; if (restAPIResponse["responseText"]) { - response["content"] = parse(restAPIResponse["responseText"]); + var responseText = ""; + try { + response["content"] = parse(restAPIResponse["responseText"]); + } catch (e) { + responseText = restAPIResponse["responseText"]; + } } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 16006187757..673c3e199f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -45,12 +45,13 @@ var invokers = function () { * If the token pair is not set in the session, this will return null. */ privateMethods.getAccessToken = function () { - var tokenPair = session.get(constants["TOKEN_PAIR"]); - if (tokenPair) { - return parse(tokenPair)["accessToken"]; - } else { - return null; + if (session) { + var tokenPair = session.get(constants["TOKEN_PAIR"]); + if (tokenPair) { + return parse(tokenPair)["accessToken"]; + } } + return null; }; /** @@ -80,9 +81,10 @@ var invokers = function () { if (devicemgtProps["isOAuthEnabled"]) { var accessToken = privateMethods.getAccessToken(); - if (!accessToken) { + if (accessToken == null) { userModule.logout(function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); + return responseCallback({"status": 401, "responseText" : "Session expired!"}); }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], From c87c5a83221f27c16bed7ee4742901342455b2d0 Mon Sep 17 00:00:00 2001 From: amalhub Date: Tue, 4 Oct 2016 11:14:39 +0530 Subject: [PATCH 2/2] Fixing issue: EMM-1537 --- .../app/modules/oauth/token-protected-service-invokers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 673c3e199f7..b79e7c6a070 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -84,7 +84,6 @@ var invokers = function () { if (accessToken == null) { userModule.logout(function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); - return responseCallback({"status": 401, "responseText" : "Session expired!"}); }); } else { xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"],