From b7990b91462092090aabdb5be90e9a8b3bd2f6b7 Mon Sep 17 00:00:00 2001 From: Megala Date: Tue, 4 Oct 2016 17:22:45 +0530 Subject: [PATCH 1/4] Fixing problems in retriveing data from secondary user store --- .../service/api/UserManagementService.java | 25 +++++++++++++++++-- .../api/admin/UserManagementAdminService.java | 5 ++++ .../impl/UserManagementServiceImpl.java | 20 ++++++++++++--- .../admin/UserManagementAdminServiceImpl.java | 5 +++- .../app/modules/business-controllers/user.js | 16 ++++++++++++ .../cdmf.page.user.edit/public/js/bottomJs.js | 4 +-- .../cdmf.page.users/public/js/listing.js | 18 ++++++++++++- .../user-menu.hbs | 2 +- 8 files changed, 84 insertions(+), 11 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 7ea6d8d5c5..c8d528dd3e 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 @@ -135,6 +135,7 @@ public interface UserManagementService { " fetching the requested user.", response = ErrorResponse.class) }) + @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getUser( @ApiParam( @@ -142,6 +143,11 @@ public interface UserManagementService { value = "Username of the user to be fetched.", required = true) @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "If-Modified-Since", value = "Validates if the requested variant has not been modified since the time specified", @@ -199,6 +205,11 @@ public interface UserManagementService { value = "Username of the user to be updated.", required = true) @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "userData", value = "User related details.", @@ -230,7 +241,12 @@ public interface UserManagementService { @Permission(name = "Manage Users", permission = "/device-mgt/users/manage") Response removeUser( @ApiParam(name = "username", value = "Username of the user to be deleted.", required = true) - @PathParam("username") String username); + @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain); @GET @Path("/{username}/roles") @@ -279,7 +295,12 @@ public interface UserManagementService { @Permission(name = "View Users", permission = "/device-mgt/users/view") Response getRolesOfUser( @ApiParam(name = "username", value = "Username of the user.", required = true) - @PathParam("username") String username); + @PathParam("username") String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain); @GET @ApiOperation( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index 6b18ea8367..026910d8e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -78,6 +78,11 @@ public interface UserManagementAdminService { @PathParam("username") @Size(max = 45) String username, + @ApiParam( + name = "domain", + value = "Domain name of the user store.", + required = false) + @QueryParam("domain") String domain, @ApiParam( name = "credentials", value = "Credential.", 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 43f52d812a..f6ba34a085 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 @@ -105,8 +105,11 @@ public class UserManagementServiceImpl implements UserManagementService { @GET @Path("/{username}") @Override - public Response getUser(@PathParam("username") String username, + public Response getUser(@PathParam("username") String username, @QueryParam("domain") String domain, @HeaderParam("If-Modified-Since") String ifModifiedSince) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -131,7 +134,10 @@ public class UserManagementServiceImpl implements UserManagementService { @PUT @Path("/{username}") @Override - public Response updateUser(@PathParam("username") String username, UserInfo userInfo) { + public Response updateUser(@PathParam("username") String username, @QueryParam("domain") String domain, UserInfo userInfo) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -205,7 +211,10 @@ public class UserManagementServiceImpl implements UserManagementService { @DELETE @Path("/{username}") @Override - public Response removeUser(@PathParam("username") String username) { + public Response removeUser(@PathParam("username") String username, @QueryParam("domain") String domain) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { @@ -233,7 +242,10 @@ public class UserManagementServiceImpl implements UserManagementService { @GET @Path("/{username}/roles") @Override - public Response getRolesOfUser(@PathParam("username") String username) { + public Response getRolesOfUser(@PathParam("username") String username, @QueryParam("domain") String domain) { + if (domain != null) { + username = domain + '/' + username; + } try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (!userStoreManager.isExistingUser(username)) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java index 5fad04b0d9..fbcc38178b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/UserManagementAdminServiceImpl.java @@ -37,7 +37,10 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic @Override public Response resetUserPassword(@PathParam("username") @Size(max = 45) - String user, PasswordResetWrapper credentials) { + String user, @QueryParam("domain") String domain, PasswordResetWrapper credentials) { + if (domain != null) { + user = domain + '/' + user; + } return CredentialManagementResponseBuilder.buildResetPasswordResponse(user, credentials); } 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 43e30b530c..299c39ebc6 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 @@ -177,10 +177,18 @@ var userModule = function () { */ publicMethods.getUser = function (username) { var carbonUser = privateMethods.getCarbonUser(); + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username); + if (domain) { + url += '?domain=' + domain; + } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); response["content"] = parse(response.content); response["userDomain"] = carbonUser.domain; @@ -199,10 +207,18 @@ var userModule = function () { */ publicMethods.getRolesByUsername = function (username) { var carbonUser = privateMethods.getCarbonUser(); + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } try { utility.startTenantFlow(carbonUser); var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + encodeURIComponent(username) + "/roles"; + if (domain) { + url += '?domain=' + domain; + } var response = privateMethods.callBackend(url, constants["HTTP_GET"]); if (response.status == "success") { response.content = parse(response.content).roles; 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 295195e3f7..a39472b01a 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 @@ -235,8 +235,8 @@ $(document).ready(function () { roles = []; } addUserFormData.roles = roles; - - var addUserAPI = deviceMgtBasePath + "/users/" + username; + username = username.substr(username.indexOf('/') + 1); + var addUserAPI = deviceMgtBasePath + "/users/" + username + "?domain="+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 2d5b88e35b..30c601f180 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 @@ -162,9 +162,17 @@ function resetPassword(username) { } else { var resetPasswordFormData = {}; resetPasswordFormData.newPassword = unescape(confirmedPassword); - + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } var resetPasswordServiceURL = apiBasePath + "/admin/users/"+ username +"/credentials"; + if (domain) { + resetPasswordServiceURL += '?domain=' + domain; + } + invokerUtil.post( resetPasswordServiceURL, resetPasswordFormData, @@ -198,7 +206,15 @@ function resetPassword(username) { * on User Listing page in WSO2 MDM Console. */ function removeUser(username) { + var domain; + if (username.indexOf('/') > 0) { + domain = username.substr(0, username.indexOf('/')); + username = username.substr(username.indexOf('/')+1); + } var removeUserAPI = apiBasePath + "/users/" + username; + if (domain) { + url += '?domain=' + domain; + } $(modalPopupContent).html($('#remove-user-modal-content').html()); showPopup(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs index eb958f6bfc..d2aba63fdc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.user-menu/user-menu.hbs @@ -46,7 +46,7 @@
- +