From 6b4ab635af453b85ed9182e7005ee468bc3acd26 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 18 Aug 2016 14:30:53 +0530 Subject: [PATCH 1/7] Fixing jiras: EMM-1472, EMM-1505 --- .../impl/UserManagementServiceImpl.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 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..e12b259fbb 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 @@ -264,10 +264,14 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information"); } - List userList, offsetList; + RequestValidationUtil.validatePaginationParameters(offset, limit); + + List userList, offsetList; String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); - int appliedLimit = (limit <= 0) ? -1 : (limit + offset); + // to get whole set of users, appliedLimit is set to -1 + // by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml + int appliedLimit = -1; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); @@ -285,14 +289,23 @@ public class UserManagementServiceImpl implements UserManagementService { userList.add(user); } - if (offset <= userList.size()) { - offsetList = userList.subList(offset, userList.size()); + int toIndex = offset + limit; + int listSize = userList.size(); + int lastIndex = listSize - 1; + + if (offset <= lastIndex) { + if (toIndex <= listSize) { + offsetList = userList.subList(offset, toIndex); + } else { + offsetList = userList.subList(offset, listSize); + } } else { offsetList = new ArrayList<>(); } + BasicUserInfoList result = new BasicUserInfoList(); result.setList(offsetList); - result.setCount(offsetList.size()); + result.setCount(users.length); return Response.status(Response.Status.OK).entity(result).build(); } catch (UserStoreException e) { From 8eeabcee2cb66206ce2b345e231f3ffcd0c78780 Mon Sep 17 00:00:00 2001 From: kamidu Date: Thu, 18 Aug 2016 15:21:52 +0530 Subject: [PATCH 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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" -}