Fix null userlist when assigning role permissions

file-uploading-issue
Lasantha Dharmakeerthi 11 months ago
commit c6ec90801d

@ -556,6 +556,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername());
String[] stringUserList;
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
final UserStoreManager userStoreManager = userRealm.getUserStoreManager(); final UserStoreManager userStoreManager = userRealm.getUserStoreManager();
if (!userStoreManager.isExistingRole(roleName)) { if (!userStoreManager.isExistingRole(roleName)) {
@ -571,7 +572,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
if (newRoleName != null && !roleName.equals(newRoleName)) { if (newRoleName != null && !roleName.equals(newRoleName)) {
userStoreManager.updateRoleName(roleName, newRoleName); userStoreManager.updateRoleName(roleName, newRoleName);
} }
if (roleInfo.getUsers() != null) { if (roleInfo.getUsers() != null) {
SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>(); SetReferenceTransformer<String> transformer = new SetReferenceTransformer<>();
transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)), 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 final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer
.getObjectsToRemove().size()]); .getObjectsToRemove().size()]);
userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd); userStoreManager.updateUserListOfRole(newRoleName, usersToDelete, usersToAdd);
stringUserList = roleInfo.getUsers();
} else {
stringUserList = userStoreManager.getUserListOfRole(roleName);
} }
if (roleInfo.getPermissions() != null) { if (roleInfo.getPermissions() != null) {
String[] roleDetails = roleName.split("/"); String[] roleDetails = roleName.split("/");
updatePermissions(roleDetails[roleDetails.length - 1], roleInfo, userRealm); updatePermissions(roleDetails[roleDetails.length - 1], roleInfo, userRealm);
} }
String stringUsers = new Gson().toJson(roleInfo.getUsers()); String stringUsers = new Gson().toJson(stringUserList);
log.info( log.info(
"Role " + roleInfo.getRoleName().split("/")[1] + " updated", "Role " + roleInfo.getRoleName().split("/")[1] + " updated",
roleMgtContextBuilder roleMgtContextBuilder

Loading…
Cancel
Save