From d81733a4d6e3c1351044205a5428b96b04f3a817 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 16 Aug 2016 18:01:49 +0530 Subject: [PATCH 01/10] Removed unused class --- .../internal/SCEPManagerServiceComponent.java | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java deleted file mode 100644 index e5d9058bdf..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/SCEPManagerServiceComponent.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.wso2.carbon.device.mgt.core.internal; - -///** -// * @scr.component name="org.wso2.carbon.certificate.mgt.core.scep" immediate="true" -// * @scr.reference name="app.mgt.service" -// * interface="org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService" -// * cardinality="1..1" -// * policy="dynamic" -// * bind="setApplicationManagementProviderService" -// * unbind="unsetApplicationManagementProviderService" -// */ -//public class SCEPManagerServiceComponent { -// -// private static final Log log = LogFactory.getLog(SCEPManagerServiceComponent.class); -// -// protected void activate(ComponentContext componentContext) { -// -// try { -// if (log.isDebugEnabled()) { -// log.debug("Initializing SCEP core bundle"); -// } -// -// BundleContext bundleContext = componentContext.getBundleContext(); -// bundleContext.registerService(SCEPManager.class.getName(), -// new SCEPManagerImpl(), null); -// -// if (log.isDebugEnabled()) { -// log.debug("SCEP core bundle has been successfully initialized"); -// } -// } catch (Throwable e) { -// String msg = "Error occurred while initializing SCEP core bundle"; -// log.error(msg, e); -// } -// } -// -// protected void deactivate(ComponentContext ctx) { -// if (log.isDebugEnabled()) { -// log.debug("Deactivating SCEP core bundle"); -// } -// } -// -// protected void unsetApplicationManagementProviderService(ApplicationManagementProviderService -// applicationManagementProviderService) { -// //do nothing -// } -// -// protected void setApplicationManagementProviderService(ApplicationManagementProviderService -// applicationManagementProviderService) { -// //do nothing -// } -// -//} From 2cb8f0b3139881b0c60a01373b13569affafde7c Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 16 Aug 2016 18:02:30 +0530 Subject: [PATCH 02/10] Fixed EMM-1392 --- .../impl/UserManagementServiceImpl.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index eda434e2f8..9734c9622d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -134,14 +134,14 @@ public class UserManagementServiceImpl implements UserManagementService { public Response updateUser(@PathParam("username") String username, UserInfo userInfo) { try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); - if (!userStoreManager.isExistingUser(userInfo.getUsername())) { + if (!userStoreManager.isExistingUser(username)) { if (log.isDebugEnabled()) { - log.debug("User by username: " + userInfo.getUsername() + - " doesn't exists. Therefore, request made to update user was refused."); + log.debug("User by username: " + username + + " doesn't exists. Therefore, request made to update user was refused."); } return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + - userInfo.getUsername() + " doesn't exist.").build()).build(); + username + " doesn't exist.").build()).build(); } Map defaultUserClaims = @@ -149,11 +149,11 @@ public class UserManagementServiceImpl implements UserManagementService { userInfo.getEmailAddress()); if (StringUtils.isNotEmpty(userInfo.getPassword())) { // Decoding Base64 encoded password - userStoreManager.updateCredentialByAdmin(userInfo.getUsername(), - userInfo.getPassword()); - log.debug("User credential of username: " + userInfo.getUsername() + " has been changed"); + userStoreManager.updateCredentialByAdmin(username, + userInfo.getPassword()); + log.debug("User credential of username: " + username + " has been changed"); } - List currentRoles = this.getFilteredRoles(userStoreManager, userInfo.getUsername()); + List currentRoles = this.getFilteredRoles(userStoreManager, username); List newRoles = Arrays.asList(userInfo.getRoles()); List rolesToAdd = new ArrayList<>(newRoles); @@ -167,19 +167,19 @@ public class UserManagementServiceImpl implements UserManagementService { } } rolesToDelete.remove(ROLE_EVERYONE); - userStoreManager.updateRoleListOfUser(userInfo.getUsername(), - rolesToDelete.toArray(new String[rolesToDelete.size()]), - rolesToAdd.toArray(new String[rolesToAdd.size()])); - userStoreManager.setUserClaimValues(userInfo.getUsername(), defaultUserClaims, null); + userStoreManager.updateRoleListOfUser(username, + rolesToDelete.toArray(new String[rolesToDelete.size()]), + rolesToAdd.toArray(new String[rolesToAdd.size()])); + userStoreManager.setUserClaimValues(username, defaultUserClaims, null); // Outputting debug message upon successful addition of user if (log.isDebugEnabled()) { - log.debug("User by username: " + userInfo.getUsername() + " was successfully updated."); + log.debug("User by username: " + username + " was successfully updated."); } BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username); return Response.ok().entity(updatedUserInfo).build(); } catch (UserStoreException e) { - String msg = "Error occurred while trying to update user '" + userInfo.getUsername() + "'"; + String msg = "Error occurred while trying to update user '" + username + "'"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); From 8eeabcee2cb66206ce2b345e231f3ffcd0c78780 Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 18 Aug 2016 15:21:52 +0530 Subject: [PATCH 03/10] Fix for Jira issue EMM-1418 --- .../devicemgt/app/pages/cdmf.page.user.create/create.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js index 5ba8114a04..a014415bc6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js @@ -31,6 +31,9 @@ function onRequest() { if (response["status"] == "success") { page["roles"] = response["content"]; } + + var userStores = userModule.getSecondaryUserStores(); + page["userStores"] = userStores; page["charLimit"] = devicemgtProps["usernameLength"]; page["usernameJSRegEx"] = devicemgtProps["userValidationConfig"]["usernameJSRegEx"]; page["usernameHelpMsg"] = devicemgtProps["userValidationConfig"]["usernameHelpMsg"]; From 83498b1039a1d69c87d8a56e785f62b4dd1e794b Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 16:23:57 +0530 Subject: [PATCH 04/10] Updating operation APIs --- .../resources/jaggeryapps/devicemgt/api/operation-api.jag | 6 +++--- 1 file changed, 3 insertions(+), 3 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 c6dca89321..7465f21649 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 @@ -32,8 +32,8 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) { var length = request.getParameter("length"); var search = request.getParameter("search[value]"); - var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/" + - deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length; + var restAPIEndpoint = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/devices/" + deviceType + "/" + deviceId + "/operations?offset=" + index + "&limit=" + length; serviceInvokers.XMLHttp.get( restAPIEndpoint, @@ -46,7 +46,7 @@ if (uriMatcher.match("/{context}/api/operation/paginate")) { paginatedResult["recordsFiltered"] = responsePayload["count"]; paginatedResult["data"] = responsePayload["operations"]; - response["status"] = 200; + response["status"] = restAPIResponse["status"]; response["content"] = paginatedResult; } else { response["status"] = restAPIResponse["status"]; From 78b5cf9fb364be97f15dc4f0008ddc7061139370 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 16:27:07 +0530 Subject: [PATCH 05/10] Updating user APIs - UI --- .../src/main/resources/jaggeryapps/devicemgt/api/user-api.jag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag index 212a087539..22d2b74fc7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag @@ -26,11 +26,11 @@ var constants = require("/app/modules/constants.js"); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; -var utility = require("/app/modules/utility.js").utility; +var utility = require("/app/modules/utility.js")["utility"]; var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; var util = require("/app/modules/oauth/token-handler-utils.js")["utils"]; -var responseProcessor = require('utils').response; +var responseProcessor = require("utils").response; var result; From f61b929bfd47a1175c68a57ac0d7e4314a94db27 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 18:11:31 +0530 Subject: [PATCH 06/10] Updating data-tables API - UI --- .../devicemgt/api/data-tables-invoker-api.jag | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag index 05ca19906a..0fb2945cf4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag @@ -35,18 +35,20 @@ function appendQueryParam (url, queryParam , value) { if (uriMatcher.match("/{context}/api/data-tables/invoker")) { var url = request.getParameter("url"); var targetURL = devicemgtProps["httpsURL"] + request.getParameter("url"); + //noinspection JSUnresolvedFunction getAllParameters var allParams = request.getAllParameters(); - for (var key in allParams) { - if (allParams.hasOwnProperty(key)) { - if(key == "limit" || key == "offset"){ - targetURL = appendQueryParam(targetURL, key, allParams[key]); - } - if(key == "filter"){ - if(allParams[key]){ - var searchPayload = JSON.parse(allParams[key]); - for (var key in searchPayload) { - targetURL = appendQueryParam(targetURL, key, searchPayload[key]); + for (var allParamsKey in allParams) { + if (allParams.hasOwnProperty(allParamsKey)) { + if (allParamsKey == "limit" || allParamsKey == "offset") { + targetURL = appendQueryParam(targetURL, allParamsKey, allParams[allParamsKey]); + } else if (allParamsKey == "filter") { + if (allParams[allParamsKey]) { + var searchPayload = JSON.parse(allParams[allParamsKey]); + for (var searchPayloadKey in searchPayload) { + if (searchPayload.hasOwnProperty(searchPayloadKey)) { + targetURL = appendQueryParam(targetURL, searchPayloadKey, searchPayload[searchPayloadKey]); + } } } } From e32c9c0bdb5e2eb85f1063f70ce59782a6690321 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 18:27:24 +0530 Subject: [PATCH 07/10] Updating init.js module - UI --- .../jaggeryapps/devicemgt/app/modules/init.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index d9f442cdd4..1c367b38f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -18,17 +18,20 @@ var carbonModule = require("carbon"); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; +var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; +var utility = require("/app/modules/utility.js")["utility"]; + +//noinspection JSUnresolvedFunction Server var carbonServer = new carbonModule.server.Server({ tenanted: true, url: devicemgtProps["httpsURL"] + "/admin" }); + application.put("carbonServer", carbonServer); -var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; -var utility = require("/app/modules/utility.js")["utility"]; +//var permissions = { +// "/permission/admin/device-mgt/user": ["ui.execute"], +// "/permission/admin/manage/api/subscribe": ["ui.execute"] +//}; -var permissions = { - '/permission/admin/device-mgt/user': ['ui.execute'], - '/permission/admin/manage/api/subscribe': ['ui.execute'] -}; //userModule.addRole("internal/devicemgt-user", ["admin"], permissions); From 0ba6edf36d9a026454c136b90903c63d75d38722 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 18:41:07 +0530 Subject: [PATCH 08/10] Updating utility.js and removing unused config files - UI --- .../jaggeryapps/devicemgt/app/modules/utility.js | 15 --------------- .../jaggeryapps/devicemgt/config/iot-config.json | 3 --- .../devicemgt/config/service-provider.json | 9 --------- 3 files changed, 27 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/iot-config.json delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/service-provider.json diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index f5dd896bc4..3af4f59e6a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -60,21 +60,6 @@ utility = function () { return getOsgiService("org.wso2.carbon.policy.mgt.core.PolicyManagerService"); }; - publicMethods.getIoTServerConfig = function (configName) { - var path = "/config/iot-config.json"; - var file = new File(path); - try { - file.open("r"); - var content = file.readAll(); - } catch (err) { - log.error("Error while reading IoT server config file `" + path + "`: " + err); - } finally { - file.close(); - } - var json = parse(content); - return json[configName]; - }; - publicMethods.getDeviceTypeConfig = function (deviceType) { var unitName = publicMethods.getTenantedDeviceUnitName(deviceType, "type-view"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/iot-config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/iot-config.json deleted file mode 100644 index 708d1eca74..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/iot-config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "IoTMgtHost" : "localhost" -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/service-provider.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/service-provider.json deleted file mode 100644 index b2041d5def..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/config/service-provider.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "grantType": "password urn:ietf:params:oauth:grant-type:saml2-bearer refresh_token", - "saasApp": true, - "tokenScope": "admin", - "requireDynamicClientRegistration": true, - "audience": "https://localhost:9443/oauth2/token", - "assertionConsumerURL": "https://localhost:9443/devicemgt/sso/acs", - "recepientValidationURL": "https://localhost:9443/oauth2/token" -} From 13e2381293d614628fe77958eceb3be9a4535fe8 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 19 Aug 2016 10:50:12 +0530 Subject: [PATCH 09/10] Updating OAuth Utils - UI --- .../app/modules/oauth/token-handler-utils.js | 22 +++++++++---------- .../app/modules/oauth/token-handlers.js | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js index ba7827173b..f31e72622c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js @@ -84,7 +84,7 @@ var utils = function () { if (!username || !jwtToken) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + "based client app credentials. No username or jwt token is found " + - "as input - getTenantBasedClientAppCredentials(x, y)"); + "as input - getTenantBasedClientAppCredentials(x, y)"); return null; } else { //noinspection JSUnresolvedFunction, JSUnresolvedVariable @@ -92,7 +92,7 @@ var utils = function () { if (!tenantDomain) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + "based client application credentials. Unable to obtain a valid tenant domain for provided " + - "username - getTenantBasedClientAppCredentials(x, y)"); + "username - getTenantBasedClientAppCredentials(x, y)"); return null; } else { var cachedTenantBasedClientAppCredentials = privateMethods. @@ -104,7 +104,7 @@ var utils = function () { var applicationName = "webapp_" + tenantDomain; var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] ["apiManagerClientAppRegistrationServiceURL"] + - "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; + "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; var xhr = new XMLHttpRequest(); xhr.open("POST", requestURL, false); @@ -123,7 +123,7 @@ var utils = function () { } else { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + "based client application credentials from API " + - "Manager - getTenantBasedClientAppCredentials(x, y)"); + "Manager - getTenantBasedClientAppCredentials(x, y)"); return null; } } @@ -152,11 +152,11 @@ var utils = function () { } }; - publicMethods["getTokenPairByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) { + publicMethods["getTokenPairAndScopesByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) { if (!username || !password || !encodedClientAppCredentials || !scopes) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " + "grant type. No username, password, encoded client app credentials or scopes are " + - "found - getTokenPairByPasswordGrantType(a, b, c, d)"); + "found - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)"); return null; } else { // calling oauth provider token service endpoint @@ -179,17 +179,17 @@ var utils = function () { return tokenData; } else { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " + - "by password grant type - getTokenPairByPasswordGrantType(a, b, c, d)"); + "by password grant type - getTokenPairAndScopesByPasswordGrantType(a, b, c, d)"); return null; } } }; - publicMethods["getTokenPairBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) { + publicMethods["getTokenPairAndScopesBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) { if (!assertion || !encodedClientAppCredentials || !scopes) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml " + "grant type. No assertion, encoded client app credentials or scopes are " + - "found - getTokenPairBySAMLGrantType(x, y, z)"); + "found - getTokenPairAndScopesBySAMLGrantType(x, y, z)"); return null; } else { var assertionXML = publicMethods.decode(assertion); @@ -205,7 +205,7 @@ var utils = function () { var extractedAssertion; if (assertionStartIndex == -1 || assertionEndIndex == -1) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access " + - "token by saml grant type. Issue in assertion format - getTokenPairBySAMLGrantType(x, y, z)"); + "token by saml grant type. Issue in assertion format - getTokenPairAndScopesBySAMLGrantType(x, y, z)"); return null; } else { extractedAssertion = assertionXML. @@ -232,7 +232,7 @@ var utils = function () { return tokenData; } else { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token " + - "by password grant type - getTokenPairBySAMLGrantType(x, y, z)"); + "by password grant type - getTokenPairAndScopesBySAMLGrantType(x, y, z)"); return null; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index fc1016eb85..8a41429ce6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -53,7 +53,7 @@ var handlers = function () { stringOfScopes += entry + " "; }); tokenData = tokenUtil. - getTokenPairByPasswordGrantType(username, + getTokenPairAndScopesByPasswordGrantType(username, encodeURIComponent(password), encodedClientAppCredentials, stringOfScopes); if (!tokenData) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up " + @@ -90,7 +90,7 @@ var handlers = function () { var tokenData; // accessTokenPair will include current access token as well as current refresh token tokenData = tokenUtil. - getTokenPairBySAMLGrantType(samlToken, encodedClientAppCredentials, "PRODUCTION"); + getTokenPairAndScopesBySAMLGrantType(samlToken, encodedClientAppCredentials, "PRODUCTION"); if (!tokenData) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up token " + "pair by password grant type. Error in token " + From 7bc927fbd0adb993e2833bd1f1f7a11c6182ef19 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 19 Aug 2016 11:52:24 +0530 Subject: [PATCH 10/10] Removing obsolete constants from constants.js - UI --- .../jaggeryapps/devicemgt/api/user-api.jag | 4 ++-- .../app/modules/business-controllers/device.js | 14 ++++++++------ .../app/modules/business-controllers/group.js | 3 ++- .../modules/business-controllers/operation.js | 2 +- .../devicemgt/app/modules/constants.js | 9 --------- .../app/pages/cdmf.page.dashboard/dashboard.js | 16 ++++++++-------- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag index 22d2b74fc7..465e896181 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag @@ -69,9 +69,9 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) { apiWrapperUtil.setupTokenPairByPasswordGrantType(username, password); var permissions = userModule.getUIPermissions(); if (permissions.VIEW_DASHBOARD) { - response.sendRedirect(constants.WEB_APP_CONTEXT); + response.sendRedirect(devicemgtProps["appContext"]); } else { - response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices"); + response.sendRedirect(devicemgtProps["appContext"] + "devices"); } }, function () { response.sendRedirect(devicemgtProps.appContext + "login?#auth-failed"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 21360452c1..4b205346d9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -22,7 +22,7 @@ deviceModule = function () { var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); - var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; // var ArrayList = Packages.java.util.ArrayList; @@ -244,7 +244,7 @@ deviceModule = function () { try { utility.startTenantFlow(carbonUser); //var url = mdmProps["httpsURL"] + "/mdm-admin/devices/view?type=" + deviceType + "&id=" + deviceId; - var url = mdmProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId; + var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId; return serviceInvokers.XMLHttp.get( url, function (backendResponse) { @@ -294,10 +294,11 @@ deviceModule = function () { var uiPermissions = userModule.getUIPermissions(); var url; if (uiPermissions.LIST_DEVICES) { - url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count"; + url = devicemgtProps["httpsURL"] + + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/count"; } else if (uiPermissions.LIST_OWN_DEVICES) { - url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username - + "/count"; + url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/devices/user/" + carbonUser.username + "/count"; } else { log.error("Access denied for user: " + carbonUser.username); return -1; @@ -351,7 +352,8 @@ deviceModule = function () { // }; publicMethods.getDevices = function (userName) { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + userName; + var url = devicemgtProps["httpsURL"] + + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices/user/" + userName; return serviceInvokers.XMLHttp.get( url, function (responsePayload) { for (var i = 0; i < responsePayload.length; i++) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index 02b2198b48..fcbeea8a5a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -26,7 +26,8 @@ var groupModule = {}; var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; - var groupServiceEndpoint = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/groups"; + var groupServiceEndpoint = devicemgtProps["httpsURL"] + + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/groups"; var user = session.get(constants.USER_SESSION_KEY); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index e96ffcdec1..6be734ec27 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -38,7 +38,7 @@ var operationModule = function () { } privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/features/" + deviceType; var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { var features = responsePayload; var featureList = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js index 79aa46e5de..5cafff394d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/constants.js @@ -16,9 +16,6 @@ * under the License. */ -var WEB_APP_TITLE = "WSO2 CDM"; -var WEB_APP_CONTEXT = "/devicemgt"; -var ADMIN_SERVICE_CONTEXT = "/api/device-mgt/v1.0"; var USER_SESSION_KEY = "_UUF_USER"; var UNSPECIFIED = "Unspecified"; var httpURL = "httpURL"; @@ -72,12 +69,6 @@ var HTTP_GET = "GET"; var HTTP_POST = "POST"; var HTTP_PUT = "PUT"; var HTTP_DELETE = "DELETE"; -var REFERER = "referer" - -var GRANT_TYPE_PASSWORD = "password"; -var GRANT_TYPE_SAML = "saml"; - -var MQTT_QUEUE_CONFIG_NAME = "MQTT"; var HTTP_CONFLICT = 409; var HTTP_CREATED = 201; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index ec98554ce1..06ac10ba3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -16,25 +16,25 @@ * under the License. */ -function onRequest(context) { +function onRequest() { var constants = require("/app/modules/constants.js"); - var user = session.get(constants.USER_SESSION_KEY); var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; - var permissions = userModule.getUIPermissions(); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; + var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"]; + + var user = session.get(constants["USER_SESSION_KEY"]); + var permissions = userModule.getUIPermissions(); if (!permissions.VIEW_DASHBOARD) { - response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices"); + response.sendRedirect(devicemgtProps["appContext"] + "devices"); return; } var page = {}; page.permissions = permissions; page.enrollmentURL = devicemgtProps.enrollmentURL; - var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; - var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; - var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"]; - page.device_count = deviceModule.getDevicesCount(); page.group_count = groupModule.getGroupCount(); page.user_count = userModule.getUsers()["content"].length;