From 843095e7c664da6aa79a7df29639eba61b4a782c Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Wed, 17 Jan 2024 14:39:52 +0530 Subject: [PATCH] Fix null userlist when assigning role permissions --- .../api/jaxrs/service/impl/RoleManagementServiceImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java index 49cd588b82..d4c00504c7 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -556,6 +556,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); + String[] stringUserList; final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserStoreManager userStoreManager = userRealm.getUserStoreManager(); if (!userStoreManager.isExistingRole(roleName)) { @@ -571,7 +572,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (newRoleName != null && !roleName.equals(newRoleName)) { userStoreManager.updateRoleName(roleName, newRoleName); } - + if (roleInfo.getUsers() != null) { SetReferenceTransformer transformer = new SetReferenceTransformer<>(); transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)), @@ -581,13 +582,16 @@ public class RoleManagementServiceImpl implements RoleManagementService { final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer .getObjectsToRemove().size()]); userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd); + stringUserList = roleInfo.getUsers(); + } else { + stringUserList = userStoreManager.getUserListOfRole(roleName); } if (roleInfo.getPermissions() != null) { String[] roleDetails = roleName.split("/"); updatePermissions(roleDetails[roleDetails.length - 1], roleInfo, userRealm); } - String stringUsers = new Gson().toJson(roleInfo.getUsers()); + String stringUsers = new Gson().toJson(stringUserList); log.info( "Role " + roleInfo.getRoleName().split("/")[1] + " updated", roleMgtContextBuilder