From d8555c34abaa40916566339876c9e2b46696269d Mon Sep 17 00:00:00 2001 From: Megala Date: Thu, 13 Oct 2016 16:58:22 +0530 Subject: [PATCH 1/8] Fixing issues related with roles of secondary user store --- .../service/api/RoleManagementService.java | 17 +++++++++- .../impl/RoleManagementServiceImpl.java | 23 ++++++++++--- .../app/modules/business-controllers/user.js | 8 +++++ .../cdmf.page.roles/public/js/role-listing.js | 2 +- .../permission.js | 12 +++++-- .../public/js/bottomJs.js | 22 ++++++++++++- .../app/units/cdmf.unit.role.edit/edit.js | 33 ++++++++++++------- 7 files changed, 95 insertions(+), 22 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index cc4df75cb5..fb11549d5c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -172,6 +172,11 @@ public interface RoleManagementService { required = true, defaultValue = "Engineer") @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time." + @@ -237,6 +242,11 @@ public interface RoleManagementService { required = true, defaultValue = "admin") @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time." + @@ -355,7 +365,12 @@ public interface RoleManagementService { value = "The properties required to update a role.\n" + "NOTE: Don't change the role and the permissions of the admin user. " + "If you want to try out this API by updating all the properties, create a new role and update the properties accordingly.", - required = true) RoleInfo role); + required = true) RoleInfo role, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName); @DELETE @Path("/{roleName}") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index bfc767b8cd..b5c4370f32 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -95,8 +95,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { @Path("/{roleName}/permissions") @Override public Response getPermissionsOfRole( - @PathParam("roleName") String roleName, + @PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, @HeaderParam("If-Modified-Since") String ifModifiedSince) { + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + '/' + roleName; + } RequestValidationUtil.validateRoleName(roleName); try { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); @@ -164,11 +167,14 @@ public class RoleManagementServiceImpl implements RoleManagementService { @GET @Path("/{roleName}") @Override - public Response getRole(@PathParam("roleName") String roleName, + public Response getRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, @HeaderParam("If-Modified-Since") String ifModifiedSince) { if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + '/' + roleName; + } RequestValidationUtil.validateRoleName(roleName); RoleInfo roleInfo = new RoleInfo(); try { @@ -248,8 +254,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { @PUT @Path("/{roleName}") - @Override - public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo) { + @Override public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo, + @QueryParam("user-store") String userStoreName) { + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + '/' + roleName; + } RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleDetails(roleInfo); try { @@ -372,7 +381,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } - roles = userStoreManager.getRoleNames(userStore+"/*", -1, false, true, true); + if (userStore.equals("all")) { + roles = userStoreManager.getRoleNames("*", -1, false, true, true); + } else { + roles = userStoreManager.getRoleNames(userStore + "/*", -1, false, true, true); + } // removing all internal roles, roles created for Service-providers and application related roles. List filteredRoles = new ArrayList<>(); for (String role : roles) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index eb7798a837..b74757d678 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -374,14 +374,22 @@ var userModule = function () { publicMethods.getRole = function (roleName) { var carbonUser = session.get(constants["USER_SESSION_KEY"]); var utility = require("/app/modules/utility.js")["utility"]; + var userStore; if (!carbonUser) { log.error("User object was not found in the session"); throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { utility.startTenantFlow(carbonUser); + if (roleName.indexOf('/') > 0) { + userStore = roleName.substr(0, roleName.indexOf('/')); + roleName = roleName.substr(roleName.indexOf('/') + 1); + } var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles/" + encodeURIComponent(roleName); + if (userStore) { + url += "?user-store=" + userStore; + } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index d5cb812ce2..1bad1949b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -188,7 +188,7 @@ function loadRoles() { "sorting": false }; - $('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles', dataFilter, columns, fnCreatedRow, null, options); + $('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles?user-store=all', dataFilter, columns, fnCreatedRow, null, options); loadingContent.hide(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js index 5790f1b7ff..13bb91a2df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js @@ -27,11 +27,19 @@ function onRequest(context) { var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); var isMatched = uriMatcher.match("/{context}/role/edit-permission/{rolename}"); + var matchedElements; + var roleName; + var userStore; if (isMatched) { - var matchedElements = uriMatcher.elements(); - var roleName = matchedElements.rolename; + matchedElements = uriMatcher.elements(); + roleName = matchedElements.rolename; context["roleName"] = roleName; + } else if (uriMatcher.match("/{context}/role/edit-permission/{userStore}/{rolename}")) { + matchedElements = uriMatcher.elements(); + userStore = matchedElements.userStore; + roleName = matchedElements.rolename; + context["roleName"] = userStore + '/' + roleName; } return context; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js index af3a8e5629..78560c1562 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js @@ -102,7 +102,15 @@ $(document).ready(function () { var listPartialSrc = $("#list-partial").attr("src"); var treeTemplateSrc = $("#tree-template").attr("src"); var roleName = $("#permissionList").data("currentrole"); + var userStore; + if (roleName.indexOf('/') > 0) { + userStore = roleName.substr(0, roleName.indexOf('/')); + roleName = roleName.substr(roleName.indexOf('/') + 1); + } var serviceUrl = apiBasePath + "/roles/" +encodeURIComponent(roleName)+"/permissions"; + if (userStore) { + serviceUrl += "?user-store=" + userStore; + } $.registerPartial("list", listPartialSrc, function(){ $.template("treeTemplate", treeTemplateSrc, function (template) { invokerUtil.get(serviceUrl, @@ -145,13 +153,25 @@ $(document).ready(function () { */ $("button#update-permissions-btn").click(function() { var roleName = $("#permissionList").data("currentrole"); + var userStore; + if (roleName.indexOf('/') > 0) { + userStore = roleName.substr(0, roleName.indexOf('/')); + roleName = roleName.substr(roleName.indexOf('/') + 1); + } var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName; + if (userStore) { + updateRolePermissionAPI += "?user-store=" + userStore; + } var updateRolePermissionData = {}; var perms = []; $("#permissionList li input:checked").each(function(){ perms.push($(this).data("resourcepath")); }); - updateRolePermissionData.roleName = roleName; + if (userStore) { + updateRolePermissionData.roleName = userStore + roleName; + } else { + updateRolePermissionData.roleName = roleName; + } updateRolePermissionData.permissions = perms; invokerUtil.put( updateRolePermissionAPI, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index ac21d0b696..3b6635dd9f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -25,23 +25,32 @@ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; - var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); - var isMatched = uriMatcher.match("/{context}/role/edit/{roleName}"); + var isMatched = uriMatcher.match("/{context}/role/edit/{roleName}") || + uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}"); + var matchedElements; + var roleName; + var response; + var userStore; if (isMatched) { - var matchedElements = uriMatcher.elements(); - var roleName = matchedElements["roleName"]; - var response = userModule.getRole(roleName); - if (response["status"] == "success") { - context["role"] = response["content"]; - } - var userStore; - if (roleName.indexOf("/") > -1) { - userStore = roleName.substring(0, roleName.indexOf("/")); - } else { + if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{roleName}"))) { + matchedElements = uriMatcher.elements(); + roleName = matchedElements["roleName"]; + response = userModule.getRole(roleName); + if (response["status"] == "success") { + context["role"] = response["content"]; + } userStore = "PRIMARY"; + } else if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}"))) { + matchedElements = uriMatcher.elements(); + roleName = matchedElements["userStoreName"] + "/" + matchedElements["roleName"]; + response = userModule.getRole(roleName); + if (response["status"] == "success") { + context["role"] = response["content"]; + } + userStore = matchedElements["userStoreName"]; } context["userStore"] = userStore; context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"]; From 87150f5074ed564a973ac72bc15d42c56ab60c4f Mon Sep 17 00:00:00 2001 From: Megala Date: Fri, 14 Oct 2016 00:01:15 +0530 Subject: [PATCH 2/8] Fixing secondary role deletion --- .../service/api/RoleManagementService.java | 12 +++++++- .../impl/RoleManagementServiceImpl.java | 28 +++++++++++-------- .../app/modules/business-controllers/user.js | 4 +-- .../public/js/bottomJs.js | 2 +- .../cdmf.page.roles/public/js/role-listing.js | 15 ++++++++-- .../public/js/bottomJs.js | 6 ++-- .../app/units/cdmf.unit.role.edit/edit.js | 15 ++++++---- .../cdmf.unit.role.edit/public/js/bottomJs.js | 4 +-- 8 files changed, 58 insertions(+), 28 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index fb11549d5c..0476ba4cde 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -404,7 +404,12 @@ public interface RoleManagementService { value = "The name of the role that needs to de deleted.\n" + "NOTE: Don't delete the admin role", required = true) - @PathParam("roleName") String roleName); + @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName); @PUT @Path("/{roleName}/users") @@ -464,6 +469,11 @@ public interface RoleManagementService { required = true, defaultValue = "admin") @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName, @ApiParam( name = "users", value = "Define the users that belong to the role.\n" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index b5c4370f32..088b29672f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -93,12 +93,10 @@ public class RoleManagementServiceImpl implements RoleManagementService { @GET @Path("/{roleName}/permissions") - @Override - public Response getPermissionsOfRole( - @PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, - @HeaderParam("If-Modified-Since") String ifModifiedSince) { + @Override public Response getPermissionsOfRole(@PathParam("roleName") String roleName, + @QueryParam("user-store") String userStoreName, @HeaderParam("If-Modified-Since") String ifModifiedSince) { if (userStoreName != null && !userStoreName.isEmpty()) { - roleName = userStoreName + '/' + roleName; + roleName = userStoreName + "/" + roleName; } RequestValidationUtil.validateRoleName(roleName); try { @@ -168,12 +166,12 @@ public class RoleManagementServiceImpl implements RoleManagementService { @Path("/{roleName}") @Override public Response getRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, - @HeaderParam("If-Modified-Since") String ifModifiedSince) { + @HeaderParam("If-Modified-Since") String ifModifiedSince) { if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } if (userStoreName != null && !userStoreName.isEmpty()) { - roleName = userStoreName + '/' + roleName; + roleName = userStoreName + "/" + roleName; } RequestValidationUtil.validateRoleName(roleName); RoleInfo roleInfo = new RoleInfo(); @@ -254,10 +252,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { @PUT @Path("/{roleName}") - @Override public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo, + @Override + public Response updateRole(@PathParam("roleName") String roleName, RoleInfo roleInfo, @QueryParam("user-store") String userStoreName) { if (userStoreName != null && !userStoreName.isEmpty()) { - roleName = userStoreName + '/' + roleName; + roleName = userStoreName + "/" + roleName; } RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateRoleDetails(roleInfo); @@ -315,7 +314,10 @@ public class RoleManagementServiceImpl implements RoleManagementService { @DELETE @Path("/{roleName}") @Override - public Response deleteRole(@PathParam("roleName") String roleName) { + public Response deleteRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName) { + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + "/" + roleName; + } RequestValidationUtil.validateRoleName(roleName); try { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); @@ -346,7 +348,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { @PUT @Path("/{roleName}/users") @Override - public Response updateUsersOfRole(@PathParam("roleName") String roleName, List users) { + public Response updateUsersOfRole(@PathParam("roleName") String roleName, + @QueryParam("user-store") String userStoreName, List users) { + if (userStoreName != null && !userStoreName.isEmpty()) { + roleName = userStoreName + "/" + roleName; + } RequestValidationUtil.validateRoleName(roleName); RequestValidationUtil.validateUsers(users); try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index b74757d678..36164975b2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -268,7 +268,7 @@ var userModule = function () { try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + - "/roles?offset=0&limit=100"; + "/roles?offset=0&limit=100&user-store=all"; var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content).roles; @@ -294,7 +294,7 @@ var userModule = function () { try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + - "/roles?offset=0&limit=1"; + "/roles?offset=0&limit=1&user-store=all"; return serviceInvokers.XMLHttp.get( url, function (responsePayload) { return parse(responsePayload["responseText"])["count"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index 93f7817db9..a5fb63e876 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -201,7 +201,7 @@ $(document).ready(function () { $("input#roleName").val(""); $("#domain").val("PRIMARY"); $("#users").val(""); - window.location.href = appContext + "/role/edit-permission/" + roleName; + window.location.href = appContext + "/role/edit-permission/" + addRoleFormData.roleName; } }, function (jqXHR) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index ae0e40fd58..1d9fdf3003 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -201,8 +201,15 @@ function loadRoles() { */ $("#role-grid").on("click", ".remove-role-link", function () { var role = $(this).data("role"); + var userStore; + if (role.indexOf('/') > 0) { + userStore = role.substr(0, role.indexOf('/')); + role = role.substr(role.indexOf('/') + 1); + } var removeRoleAPI = apiBasePath + "/roles/" + role; - + if (userStore) { + removeRoleAPI += "?user-store=" + userStore; + } $(modalPopupContent).html($('#remove-role-modal-content').html()); showPopup(); @@ -210,7 +217,11 @@ $("#role-grid").on("click", ".remove-role-link", function () { invokerUtil.delete( removeRoleAPI, function () { - $("#role-" + role).remove(); + if (userStore) { + $("#role-" + userStore + "\\/" + role).remove(); + } else { + $("#role-" + role).remove(); + } $(modalPopupContent).html($('#remove-role-success-content').html()); $("a#remove-role-success-link").click(function () { hidePopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js index 78560c1562..8dcdc85a43 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js @@ -159,16 +159,14 @@ $(document).ready(function () { roleName = roleName.substr(roleName.indexOf('/') + 1); } var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName; - if (userStore) { - updateRolePermissionAPI += "?user-store=" + userStore; - } var updateRolePermissionData = {}; var perms = []; $("#permissionList li input:checked").each(function(){ perms.push($(this).data("resourcepath")); }); if (userStore) { - updateRolePermissionData.roleName = userStore + roleName; + updateRolePermissionAPI += "?user-store=" + userStore; + updateRolePermissionData.roleName = userStore + "/" + roleName; } else { updateRolePermissionData.roleName = roleName; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index 3b6635dd9f..940867904f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -35,7 +35,7 @@ function onRequest(context) { var userStore; if (isMatched) { - if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{roleName}"))) { + if (uriMatcher.match("/{context}/role/edit/{roleName}")) { matchedElements = uriMatcher.elements(); roleName = matchedElements["roleName"]; response = userModule.getRole(roleName); @@ -43,19 +43,24 @@ function onRequest(context) { context["role"] = response["content"]; } userStore = "PRIMARY"; - } else if (uriMatcher.match( uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}"))) { + } else if (uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}")) { matchedElements = uriMatcher.elements(); - roleName = matchedElements["userStoreName"] + "/" + matchedElements["roleName"]; - response = userModule.getRole(roleName); + roleName = matchedElements["roleName"]; + userStore = matchedElements["userStoreName"]; + response = userModule.getRole(userStore + "/" + roleName); if (response["status"] == "success") { context["role"] = response["content"]; } - userStore = matchedElements["userStoreName"]; + } context["userStore"] = userStore; context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"]; context["roleNameHelpText"] = deviceMgtProps["roleValidationConfig"]["roleNameHelpMsg"]; context["roleNameRegExViolationErrorMsg"] = deviceMgtProps["roleValidationConfig"]["roleNameRegExViolationErrorMsg"]; + roleName = context["role"]["roleName"]; + if (roleName.indexOf("/") > -1) { + context["role"]["roleName"] = roleName.substr(roleName.indexOf("/") + 1); + } return context; } else { //TODO: handle error scenario diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js index e038c32592..a2c4161c0a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js @@ -163,11 +163,11 @@ $(document).ready(function () { } else { var addRoleFormData = {}; addRoleFormData.roleName = roleName; + var addRoleAPI = apiBasePath + "/roles/" + currentRoleName; if (domain != "PRIMARY"){ addRoleFormData.roleName = domain + "/" + roleName; + addRoleAPI = addRoleAPI + "?user-store=" + domain; } - - var addRoleAPI = apiBasePath + "/roles/" + currentRoleName; invokerUtil.put( addRoleAPI, addRoleFormData, From a04f91cddbac628c9a2296aabc32ffb9a0ddddc5 Mon Sep 17 00:00:00 2001 From: Megala Date: Fri, 14 Oct 2016 10:59:56 +0530 Subject: [PATCH 3/8] Fixing issues related to mapping users and roles from different user stores --- .../service/api/UserManagementService.java | 5 ++++ .../impl/RoleManagementServiceImpl.java | 10 +++---- .../impl/UserManagementServiceImpl.java | 29 +++++++++++-------- .../device/mgt/jaxrs/util/Constants.java | 1 + .../public/js/bottomJs.js | 13 ++++++++- .../public/js/bottomJs.js | 6 ++-- .../cdmf.unit.role.edit/public/js/bottomJs.js | 29 ++++++++++++++++++- 7 files changed, 70 insertions(+), 23 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 08fb287d20..06569d21cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -457,6 +457,11 @@ public interface UserManagementService { value = "Provide a character or a few character in the user name", required = true) @QueryParam("filter") String filter, + @ApiParam( + name = "domain", + value = "The user store domain which the user names should be fetched from", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "If-Modified-Since", value = "Checks if the requested variant was modified, since the specified date-time\n." + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 088b29672f..2f33d5a5df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -22,17 +22,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementException; -import org.wso2.carbon.device.mgt.common.scope.mgt.ScopeManagementService; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; -import org.wso2.carbon.device.mgt.jaxrs.beans.Scope; import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; -import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; import org.wso2.carbon.user.api.*; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; @@ -49,6 +45,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static org.wso2.carbon.device.mgt.jaxrs.util.Constants.PRIMARY_USER_STORE; + @Path("/roles") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -56,7 +54,6 @@ public class RoleManagementServiceImpl implements RoleManagementService { private static final String API_BASE_PATH = "/roles"; private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class); - private static final String PRIMARY_USER_STORE = "PRIMARY"; @GET @Override @@ -93,7 +90,8 @@ public class RoleManagementServiceImpl implements RoleManagementService { @GET @Path("/{roleName}/permissions") - @Override public Response getPermissionsOfRole(@PathParam("roleName") String roleName, + @Override + public Response getPermissionsOfRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName, @HeaderParam("If-Modified-Since") String ifModifiedSince) { if (userStoreName != null && !userStoreName.isEmpty()) { roleName = userStoreName + "/" + roleName; 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 8ec2f898df..bb196bad3d 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 @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.opensaml.ws.wstrust.Primary; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; @@ -353,28 +354,32 @@ public class UserManagementServiceImpl implements UserManagementService { @GET @Path("/search/usernames") @Override - public Response getUserNames(@QueryParam("filter") String filter, @HeaderParam("If-Modified-Since") String timestamp, + public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain, + @HeaderParam("If-Modified-Since") String timestamp, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { if (log.isDebugEnabled()) { log.debug("Getting the list of users with all user-related information using the filter : " + filter); } + String userStoreDomain = Constants.PRIMARY_USER_STORE; + if (domain != null && !domain.isEmpty()) { + userStoreDomain = domain; + } List userList; try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); - String[] users = userStoreManager.listUsers(filter + "*", -1); - userList = new ArrayList<>(users.length); + String[] users = userStoreManager.listUsers(userStoreDomain + "/*", -1); + userList = new ArrayList<>(); UserInfo user; for (String username : users) { - user = new UserInfo(); - user.setUsername(username); - user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); - user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); - user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); - userList.add(user); + if (username.contains(filter)) { + user = new UserInfo(); + user.setUsername(username); + user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); + user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); + user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); + userList.add(user); + } } -// if (userList.size() <= 0) { -// return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build(); -// } return Response.status(Response.Status.OK).entity(userList).build(); } catch (UserStoreException e) { String msg = "Error occurred while retrieving the list of users using the filter : " + filter; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java index 451c58b178..d9981ba782 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java @@ -26,6 +26,7 @@ public class Constants { public static final String USER_CLAIM_EMAIL_ADDRESS = "http://wso2.org/claims/emailaddress"; public static final String USER_CLAIM_FIRST_NAME = "http://wso2.org/claims/givenname"; public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname"; + public static final String PRIMARY_USER_STORE = "PRIMARY"; public final class ErrorMessages { private ErrorMessages () { throw new AssertionError(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index a5fb63e876..dc90ad0cc0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -32,6 +32,7 @@ var validateInline = {}; var clearInline = {}; var apiBasePath = "/api/device-mgt/v1.0"; +var domain = $("#domain").val(); var enableInlineError = function (inputField, errorMsg, errorSign) { var fieldIdentifier = "#" + inputField; @@ -113,6 +114,7 @@ function formatRepoSelection (user) { $(document).ready(function () { var appContext = $("#app-context").data("app-context"); + $("#users").select2({ multiple:true, tags: false, @@ -127,7 +129,8 @@ $(document).ready(function () { data: function (params) { var postData = {}; postData.requestMethod = "GET"; - postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term; + postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term + + "&domain=" + domain; postData.requestPayload = null; return JSON.stringify(postData); }, @@ -222,4 +225,12 @@ $(document).ready(function () { $(roleNameInputElement).blur(function() { validateInline["role-name"](); }); + + /* When the user store domain value is changed, the users who are assigned to that role should be removed, as + user and role can be mapped only if both are in same user store + */ + $("#domain").change(function () { + $("#users").select2("val", ""); + domain = $("#domain").val(); + }); }); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js index 2071baf9f9..bed8b810bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js @@ -189,10 +189,10 @@ $("#userStore").change( if (data.errorMessage) { $(errorMsg).text("Selected user store prompted an error : " + data.errorMessage); $(errorMsgWrapper).removeClass("hidden"); - } else if (data["statusCode"] == 200) { + } else if (data.count > 0) { $("#roles").empty(); - for (var i = 0; i < data.responseContent.length; i++) { - var newOption = $(''); + for (var i = 0; i < data.roles.length; i++) { + var newOption = $(''); $('#roles').append(newOption); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js index a2c4161c0a..f92d1962b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /** * Checks if provided input is valid against RegEx input. * @@ -12,6 +30,7 @@ function inputIsValid(regExp, inputString) { var validateInline = {}; var clearInline = {}; +var domain = $("#domain").val(); var apiBasePath = "/api/device-mgt/v1.0"; @@ -112,7 +131,7 @@ $(document).ready(function () { data: function (params) { var postData = {}; postData.actionMethod = "GET"; - postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term; + postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term + "&domain=" + domain; postData.actionPayload = null; return JSON.stringify(postData); }, @@ -196,4 +215,12 @@ $(document).ready(function () { $("#rolename").blur(function() { validateInline["role-name"](); }); + + /* When the user store domain value is changed, the users who are assigned to that role should be removed, as + user and role can be mapped only if both are in same user store + */ + $("#domain").change(function () { + $("#users").select2("val", ""); + domain = $("#domain").val(); + }); }); \ No newline at end of file From e55b3a6d5ff5859257e36f7137a55bfb1e2c5d66 Mon Sep 17 00:00:00 2001 From: Megala Date: Fri, 14 Oct 2016 16:03:14 +0530 Subject: [PATCH 4/8] Fixes related to having special characters in role name --- .../pom.xml | 1 - .../app/modules/business-controllers/user.js | 8 ++++---- .../public/js/bottomJs.js | 4 ++-- .../permission.json | 2 +- .../cdmf.page.roles/public/js/role-listing.js | 4 ++-- .../public/js/bottomJs.js | 5 ++--- .../cdmf.page.user.edit/public/js/bottomJs.js | 3 ++- .../pages/cdmf.page.users/public/js/listing.js | 7 +++---- .../permission.js | 18 +----------------- .../public/js/bottomJs.js | 6 +++--- .../cdmf.unit.role.edit/public/js/bottomJs.js | 7 ++++--- 11 files changed, 24 insertions(+), 41 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 573b3dfbc5..4a29430e5a 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -175,7 +175,6 @@ org.wso2.carbon org.wso2.carbon.user.core - 4.4.3 org.wso2.carbon.registry diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 36164975b2..67743b3bc0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -187,7 +187,7 @@ var userModule = function () { var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username); if (domain) { - url += '?domain=' + domain; + url += '?domain=' + encodeURIComponent(domain); } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); response["content"] = parse(response.content); @@ -217,7 +217,7 @@ var userModule = function () { var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username) + "/roles"; if (domain) { - url += '?domain=' + domain; + url += '?domain=' + encodeURIComponent(domain); } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { @@ -328,7 +328,7 @@ var userModule = function () { try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + - "/roles?user-store=" + userStore + "&limit=100"; + "/roles?user-store=" + encodeURIComponent(userStore) + "&limit=100"; var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content).roles; @@ -388,7 +388,7 @@ var userModule = function () { var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles/" + encodeURIComponent(roleName); if (userStore) { - url += "?user-store=" + userStore; + url += "?user-store=" + encodeURIComponent(userStore); } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index dc90ad0cc0..2b5a331398 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -130,7 +130,7 @@ $(document).ready(function () { var postData = {}; postData.requestMethod = "GET"; postData.requestURL = "/api/device-mgt/v1.0/users/search/usernames?filter=" + params.term + - "&domain=" + domain; + "&domain=" + encodeURIComponent(domain); postData.requestPayload = null; return JSON.stringify(postData); }, @@ -204,7 +204,7 @@ $(document).ready(function () { $("input#roleName").val(""); $("#domain").val("PRIMARY"); $("#users").val(""); - window.location.href = appContext + "/role/edit-permission/" + addRoleFormData.roleName; + window.location.href = appContext + "/role/edit-permission/?rolename=" + encodeURIComponent(addRoleFormData.roleName); } }, function (jqXHR) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json index a6e56c02a5..952c4abe20 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit.permission/permission.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/role/edit-permission/{+any}", + "uri": "/role/edit-permission/", "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 1d9fdf3003..27c137c0f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -206,9 +206,9 @@ $("#role-grid").on("click", ".remove-role-link", function () { userStore = role.substr(0, role.indexOf('/')); role = role.substr(role.indexOf('/') + 1); } - var removeRoleAPI = apiBasePath + "/roles/" + role; + var removeRoleAPI = apiBasePath + "/roles/" + encodeURIComponent(role); if (userStore) { - removeRoleAPI += "?user-store=" + userStore; + removeRoleAPI += "?user-store=" + encodeURIComponent(userStore); } $(modalPopupContent).html($('#remove-role-modal-content').html()); showPopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js index bed8b810bd..317cf435e4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/public/js/bottomJs.js @@ -180,8 +180,7 @@ $("#userStore").change( str += $(this).text() + ""; }); if ($("#roles").length > 0) { - var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + str + "&limit=100"; - + var getRolesAPI = deviceMgtAPIsBasePath + "/roles?user-store=" + encodeURIComponent(str) + "&limit=100"; invokerUtil.get( getRolesAPI, function (data) { @@ -189,7 +188,7 @@ $("#userStore").change( if (data.errorMessage) { $(errorMsg).text("Selected user store prompted an error : " + data.errorMessage); $(errorMsgWrapper).removeClass("hidden"); - } else if (data.count > 0) { + } else { $("#roles").empty(); for (var i = 0; i < data.roles.length; i++) { var newOption = $(''); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js index 00357909e6..2ecada94ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/public/js/bottomJs.js @@ -236,7 +236,8 @@ $(document).ready(function () { } addUserFormData.roles = roles; username = username.substr(username.indexOf('/') + 1); - var addUserAPI = deviceMgtBasePath + "/users/" + username + "?domain=" + domain; + var addUserAPI = deviceMgtBasePath + "/users/" + encodeURIComponent(username) + "?domain=" + + encodeURIComponent(domain); invokerUtil.put( addUserAPI, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index d8dc9d4860..d7e557a46c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -158,7 +158,7 @@ function resetPassword(username) { } var resetPasswordServiceURL = apiBasePath + "/admin/users/" + username + "/credentials"; if (domain) { - resetPasswordServiceURL += '?domain=' + domain; + resetPasswordServiceURL += '?domain=' + encodeURIComponent(domain); } invokerUtil.post( resetPasswordServiceURL, @@ -198,11 +198,10 @@ function removeUser(username) { domain = username.substr(0, username.indexOf('/')); username = username.substr(username.indexOf('/') + 1); } - var removeUserAPI = apiBasePath + "/users/" + username; + var removeUserAPI = apiBasePath + "/users/" + encodeURIComponent(username); if (domain) { - removeUserAPI += '?domain=' + domain; + removeUserAPI += '?domain=' + encodeURIComponent(domain); } - modalDialog.header("Remove User"); modalDialog.content("Do you really want to remove this user ?"); modalDialog.footer('
Remove ' + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js index 13bb91a2df..10d47721d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js @@ -24,22 +24,6 @@ */ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; - var uri = request.getRequestURI(); - var uriMatcher = new URIMatcher(String(uri)); - var isMatched = uriMatcher.match("/{context}/role/edit-permission/{rolename}"); - var matchedElements; - var roleName; - var userStore; - - if (isMatched) { - matchedElements = uriMatcher.elements(); - roleName = matchedElements.rolename; - context["roleName"] = roleName; - } else if (uriMatcher.match("/{context}/role/edit-permission/{userStore}/{rolename}")) { - matchedElements = uriMatcher.elements(); - userStore = matchedElements.userStore; - roleName = matchedElements.rolename; - context["roleName"] = userStore + '/' + roleName; - } + context["roleName"] = request.getParameter("rolename"); return context; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js index 8dcdc85a43..5443e77270 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/public/js/bottomJs.js @@ -109,7 +109,7 @@ $(document).ready(function () { } var serviceUrl = apiBasePath + "/roles/" +encodeURIComponent(roleName)+"/permissions"; if (userStore) { - serviceUrl += "?user-store=" + userStore; + serviceUrl += "?user-store=" + encodeURIComponent(userStore); } $.registerPartial("list", listPartialSrc, function(){ $.template("treeTemplate", treeTemplateSrc, function (template) { @@ -158,14 +158,14 @@ $(document).ready(function () { userStore = roleName.substr(0, roleName.indexOf('/')); roleName = roleName.substr(roleName.indexOf('/') + 1); } - var updateRolePermissionAPI = apiBasePath + "/roles/" + roleName; + var updateRolePermissionAPI = apiBasePath + "/roles/" + encodeURIComponent(roleName); var updateRolePermissionData = {}; var perms = []; $("#permissionList li input:checked").each(function(){ perms.push($(this).data("resourcepath")); }); if (userStore) { - updateRolePermissionAPI += "?user-store=" + userStore; + updateRolePermissionAPI += "?user-store=" + encodeURIComponent(userStore); updateRolePermissionData.roleName = userStore + "/" + roleName; } else { updateRolePermissionData.roleName = roleName; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js index f92d1962b7..7dae919969 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/public/js/bottomJs.js @@ -131,7 +131,8 @@ $(document).ready(function () { data: function (params) { var postData = {}; postData.actionMethod = "GET"; - postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term + "&domain=" + domain; + postData.actionUrl = apiBasePath + "/users/search/usernames?filter=" + params.term + "&domain=" + + encodeURIComponent(domain); postData.actionPayload = null; return JSON.stringify(postData); }, @@ -182,10 +183,10 @@ $(document).ready(function () { } else { var addRoleFormData = {}; addRoleFormData.roleName = roleName; - var addRoleAPI = apiBasePath + "/roles/" + currentRoleName; + var addRoleAPI = apiBasePath + "/roles/" + encodeURIComponent(currentRoleName); if (domain != "PRIMARY"){ addRoleFormData.roleName = domain + "/" + roleName; - addRoleAPI = addRoleAPI + "?user-store=" + domain; + addRoleAPI = addRoleAPI + "?user-store=" + encodeURIComponent(domain); } invokerUtil.put( addRoleAPI, From d9ec20372748c100a0c15493af553c58175c1c1e Mon Sep 17 00:00:00 2001 From: Megala Date: Sun, 16 Oct 2016 13:24:32 +0530 Subject: [PATCH 5/8] Fixing EMM-1755 --- .../app/pages/cdmf.page.role.edit/edit.json | 2 +- .../cdmf.page.roles/public/js/role-listing.js | 2 +- .../app/units/cdmf.unit.role.edit/edit.js | 31 ++++++------------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json index 3efeeeb8e2..6959b98af0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.edit/edit.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/role/edit/{+any}", + "uri": "/role/edit/", "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index c934cd1c8a..0f5f905ec3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -17,7 +17,7 @@ */ var loadRoleBasedActionURL = function (action, rolename) { - var href = $("#ast-container").data("app-context") + "role/" + action + "/" + rolename; + href = $("#ast-container").data("app-context") + "role/" + action + "/?rolename=" + encodeURIComponent(rolename); $(location).attr('href', href); }; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index 940867904f..9bca327597 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -26,32 +26,19 @@ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var uri = request.getRequestURI(); - var uriMatcher = new URIMatcher(String(uri)); - var isMatched = uriMatcher.match("/{context}/role/edit/{roleName}") || - uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}"); - var matchedElements; - var roleName; + var roleName = request.getParameter("rolename"); var response; var userStore; - if (isMatched) { - if (uriMatcher.match("/{context}/role/edit/{roleName}")) { - matchedElements = uriMatcher.elements(); - roleName = matchedElements["roleName"]; - response = userModule.getRole(roleName); - if (response["status"] == "success") { - context["role"] = response["content"]; - } + if (roleName) { + if (roleName.indexOf("/") > -1) { + userStore = roleName.substr(0, roleName.indexOf("/")); + } else { userStore = "PRIMARY"; - } else if (uriMatcher.match("/{context}/role/edit/{userStoreName}/{roleName}")) { - matchedElements = uriMatcher.elements(); - roleName = matchedElements["roleName"]; - userStore = matchedElements["userStoreName"]; - response = userModule.getRole(userStore + "/" + roleName); - if (response["status"] == "success") { - context["role"] = response["content"]; - } - + } + response = userModule.getRole(roleName); + if (response["status"] == "success") { + context["role"] = response["content"]; } context["userStore"] = userStore; context["roleNameJSRegEx"] = deviceMgtProps["roleValidationConfig"]["roleNameJSRegEx"]; From 4a71be850c76a1baa83e6386cdab0f0446848e2a Mon Sep 17 00:00:00 2001 From: Megala Date: Mon, 17 Oct 2016 14:23:55 +0530 Subject: [PATCH 6/8] Refactoring code --- .../mgt/jaxrs/service/api/RoleManagementService.java | 10 +++++----- .../jaxrs/service/impl/UserManagementServiceImpl.java | 1 - .../app/pages/cdmf.page.role.create/create.hbs | 3 ++- .../pages/cdmf.page.role.create/public/js/bottomJs.js | 7 ++++--- .../pages/cdmf.page.roles/public/js/role-listing.js | 5 ++--- .../app/pages/cdmf.page.users/public/js/listing.js | 5 ++--- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index 0476ba4cde..d53c367450 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -174,7 +174,7 @@ public interface RoleManagementService { @PathParam("roleName") String roleName, @ApiParam( name = "user-store", - value = "The name of the UserStore you wish to get the list of roles.", + value = "The name of the user store from which you wish to get the permission of role.", required = false) @QueryParam("user-store") String userStoreName, @ApiParam( @@ -244,7 +244,7 @@ public interface RoleManagementService { @PathParam("roleName") String roleName, @ApiParam( name = "user-store", - value = "The name of the UserStore you wish to get the list of roles.", + value = "The name of the user store which the particular of role resides in", required = false) @QueryParam("user-store") String userStoreName, @ApiParam( @@ -368,7 +368,7 @@ public interface RoleManagementService { required = true) RoleInfo role, @ApiParam( name = "user-store", - value = "The name of the UserStore you wish to get the list of roles.", + value = "The name of the user store which the particular role resides in.", required = false) @QueryParam("user-store") String userStoreName); @@ -407,7 +407,7 @@ public interface RoleManagementService { @PathParam("roleName") String roleName, @ApiParam( name = "user-store", - value = "The name of the UserStore you wish to get the list of roles.", + value = "The name of the user store which the particular role resides in.", required = false) @QueryParam("user-store") String userStoreName); @@ -471,7 +471,7 @@ public interface RoleManagementService { @PathParam("roleName") String roleName, @ApiParam( name = "user-store", - value = "The name of the UserStore you wish to get the list of roles.", + value = "The name of the user store which the particular role resides in.", required = false) @QueryParam("user-store") String userStoreName, @ApiParam( 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 bb196bad3d..91538230a1 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 @@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.opensaml.ws.wstrust.Primary; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs index d3b2f15329..0bfdfe1d8f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/create.hbs @@ -94,7 +94,8 @@ data-error-msg="{{roleNameRegExViolationErrorMsg}}" class="form-control" />
{{#if canViewUsers}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index 2b5a331398..d67c46ea8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -83,7 +83,8 @@ clearInline["role-name"] = function () { */ validateInline["role-name"] = function () { var roleNameInput = $("input#roleName"); - if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val())) { + if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val()) && roleNameInput.indexOf("@") < 0 && + roleNameInput.indexOf("/") < 0) { disableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); } else { enableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); @@ -114,7 +115,6 @@ function formatRepoSelection (user) { $(document).ready(function () { var appContext = $("#app-context").data("app-context"); - $("#users").select2({ multiple:true, tags: false, @@ -204,7 +204,8 @@ $(document).ready(function () { $("input#roleName").val(""); $("#domain").val("PRIMARY"); $("#users").val(""); - window.location.href = appContext + "/role/edit-permission/?rolename=" + encodeURIComponent(addRoleFormData.roleName); + window.location.href = appContext + "/role/edit-permission/?rolename=" + + encodeURIComponent(addRoleFormData.roleName); } }, function (jqXHR) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 0f5f905ec3..907d124f70 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -218,10 +218,9 @@ $("#role-grid").on("click", ".remove-role-link", function () { removeRoleAPI, function () { if (userStore) { - $("#role-" + userStore + "\\/" + role).remove(); - } else { - $("#role-" + role).remove(); + role = userStore + '/' + role; } + $('[id=role-' + role + ']').remove(); $(modalPopupContent).html($('#remove-role-success-content').html()); $("a#remove-role-success-link").click(function () { hidePopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index d7e557a46c..b737f4472c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -218,10 +218,9 @@ function removeUser(username) { function (data, textStatus, jqXHR) { if (jqXHR.status == 200) { if (domain) { - $("#user-" + domain + "\\/" + username).remove(); - } else { - $("#user-" + username).remove(); + username = domain + '/' + username; } + $('[id=user-' + username + ']').remove(); // update modal-content with success message modalDialog.header("User Removed."); modalDialog.content("Done. User was successfully removed."); From 1ff86289fdd496f1888bfa018abc11f6da53420b Mon Sep 17 00:00:00 2001 From: Megala Date: Mon, 17 Oct 2016 15:47:32 +0530 Subject: [PATCH 7/8] Fixing the problems that happend when we have special chracters in roles --- .../service/impl/RoleManagementServiceImpl.java | 13 ++++++++++--- .../cdmf.page.role.create/public/js/bottomJs.js | 7 ++++--- .../pages/cdmf.page.roles/public/js/role-listing.js | 2 +- .../app/pages/cdmf.page.users/public/js/listing.js | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 2f33d5a5df..29db06c3d0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -39,8 +39,10 @@ import org.wso2.carbon.user.mgt.common.UserAdminException; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -231,9 +233,9 @@ public class RoleManagementServiceImpl implements RoleManagementService { userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions); //TODO fix what's returned in the entity - return Response.created(new URI(API_BASE_PATH + "/" + roleInfo.getRoleName())).entity( - "Role '" + roleInfo.getRoleName() + "' has " + - "successfully been added").build(); + return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))). + entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been" + + " added").build(); } catch (UserStoreException e) { String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'"; log.error(msg, e); @@ -245,6 +247,11 @@ public class RoleManagementServiceImpl implements RoleManagementService { log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (UnsupportedEncodingException e) { + String msg = "Error occurred while encoding role name"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js index d67c46ea8b..2cb8292af7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.role.create/public/js/bottomJs.js @@ -83,8 +83,8 @@ clearInline["role-name"] = function () { */ validateInline["role-name"] = function () { var roleNameInput = $("input#roleName"); - if (inputIsValid( roleNameInput.data("regex"), roleNameInput.val()) && roleNameInput.indexOf("@") < 0 && - roleNameInput.indexOf("/") < 0) { + var roleName = roleNameInput.val(); + if (inputIsValid( roleNameInput.data("regex"), roleName) && roleName.indexOf("@") < 0 && roleName.indexOf("/") < 0) { disableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); } else { enableInlineError("roleNameField", "roleNameEmpty", "roleNameError"); @@ -173,7 +173,8 @@ $(document).ready(function () { if (!roleName) { $(errorMsg).text("Role name is a required field. It cannot be empty."); $(errorMsgWrapper).removeClass("hidden"); - } else if (!inputIsValid(roleNameInput.data("regex"), roleName)) { + } else if (!inputIsValid(roleNameInput.data("regex"), roleName) || roleName.indexOf("@") >= 0 || + roleName.indexOf("/") >= 0) { $(errorMsg).text(roleNameInput.data("error-msg")); $(errorMsgWrapper).removeClass("hidden"); } else if (!domain) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 907d124f70..4a6b44fbb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -220,7 +220,7 @@ $("#role-grid").on("click", ".remove-role-link", function () { if (userStore) { role = userStore + '/' + role; } - $('[id=role-' + role + ']').remove(); + $('[id="role-' + role + '"]').remove(); $(modalPopupContent).html($('#remove-role-success-content').html()); $("a#remove-role-success-link").click(function () { hidePopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index b737f4472c..af9792e18a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -220,7 +220,7 @@ function removeUser(username) { if (domain) { username = domain + '/' + username; } - $('[id=user-' + username + ']').remove(); + $('[id="user-' + username + '"]').remove(); // update modal-content with success message modalDialog.header("User Removed."); modalDialog.content("Done. User was successfully removed."); From 3416ae78c43e6d398af2fbc6f762b51778f04e6f Mon Sep 17 00:00:00 2001 From: Megala Date: Mon, 17 Oct 2016 16:35:58 +0530 Subject: [PATCH 8/8] Fixing the problems in displaying user list when the user names has special chracters --- .../jaxrs/service/impl/UserManagementServiceImpl.java | 11 ++++++++++- .../app/pages/cdmf.page.users/public/js/listing.js | 3 ++- 2 files changed, 12 insertions(+), 2 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 91538230a1..8fc57a0c89 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 @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; @@ -36,6 +37,7 @@ import org.wso2.carbon.user.api.UserStoreManager; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.security.SecureRandom; @@ -85,7 +87,8 @@ public class UserManagementServiceImpl implements UserManagementService { if (log.isDebugEnabled()) { log.debug("User by username: " + userInfo.getUsername() + " was found."); } - return Response.created(new URI(API_BASE_PATH + "/" + userInfo.getUsername())).entity( + return Response.created(new URI(API_BASE_PATH + "/" + URIEncoder.encode(userInfo.getUsername(), "UTF-8"))) + .entity( createdUserInfo).build(); } catch (UserStoreException e) { String msg = "Error occurred while trying to add user '" + userInfo.getUsername() + "' to the " + @@ -99,6 +102,12 @@ public class UserManagementServiceImpl implements UserManagementService { log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (UnsupportedEncodingException e) { + String msg = "Error occurred while encoding username in the URI for the newly created user " + + userInfo.getUsername(); + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index af9792e18a..50f11a3df3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -336,7 +336,8 @@ function loadUsers() { class: "text-right content-fill text-left-on-grid-view no-wrap", data: null, render: function (data, type, row, meta) { - var editbtn = ' ' + ' ' +