Skip to content

Commit

Permalink
RANGER-4804: fix for NPE while updating user-group associations
Browse files Browse the repository at this point in the history
Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
RakeshGuptaDev authored and mneethiraj committed Jul 18, 2024
1 parent 7cf63c2 commit b051ad6
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions security-admin/src/main/java/org/apache/ranger/biz/XUserMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ public VXUser createXUser(VXUser vXUser) {
createdXUser.setGroupIdList(groupIdList);
createdXUser.setGroupNameList(groupNamesList);
for (VXGroupUser vXGroupUser : vXGroupUsers) {
trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT));
List<XXTrxLogV2> groupUserTrxLogs = xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT);

if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
if (trxLogList == null) {
trxLogList = new ArrayList<>();
}

trxLogList.addAll(groupUserTrxLogs);
}
}
//
xaBizUtil.createTrxLog(trxLogList);
Expand Down Expand Up @@ -491,7 +499,16 @@ else if (oldUserProfile.getUserSource() == RangerCommonEnums.USER_EXTERNAL) {

Long userId = vXUser.getId();
List<Long> groupUsersToRemove = new ArrayList<Long>();
trxLogList.addAll(createOrDelGrpUserWithUpdatedGrpId(vXUser, groupIdList,userId, groupUsersToRemove));
List<XXTrxLogV2> groupUserTrxLogs = createOrDelGrpUserWithUpdatedGrpId(vXUser, groupIdList,userId, groupUsersToRemove);

if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
if (trxLogList == null) {
trxLogList = new ArrayList<>();
}

trxLogList.addAll(groupUserTrxLogs);
}

xaBizUtil.createTrxLog(trxLogList);

updateUserStoreVersion("updateXUser(" + vXUser.getName() + ")");
Expand Down Expand Up @@ -523,7 +540,10 @@ private List<XXTrxLogV2> createOrDelGrpUserWithUpdatedGrpId(VXUser vXUser, Colle
}
if (!found) {
VXGroupUser vXGroupUser = createXGroupUser(userId, groupId);
trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT));
List<XXTrxLogV2> groupUserTrxLogs = xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT);
if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
trxLogList.addAll(groupUserTrxLogs);
}
groupNamesSet.add(vXGroupUser.getName());
}
}
Expand All @@ -533,14 +553,20 @@ private List<XXTrxLogV2> createOrDelGrpUserWithUpdatedGrpId(VXUser vXUser, Colle
boolean found = false;
for (Long groupId : groupIdList) {
if (groupId.equals(vXGroupUser.getParentGroupId())) {
trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_UPDATE_CONTEXT));
List<XXTrxLogV2> groupUserTrxLogs = xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_UPDATE_CONTEXT);
if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
trxLogList.addAll(groupUserTrxLogs);
}
found = true;
break;
}
}
if (!found) {
// TODO I've to get the transaction log from here.
trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_DELETE_CONTEXT));
List<XXTrxLogV2> groupUserTrxLogs = xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_DELETE_CONTEXT);
if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
trxLogList.addAll(groupUserTrxLogs);
}
groupUsersToRemove.add(vXGroupUser.getId());
// xGroupUserService.deleteResource(vXGroupUser.getId());
groupNamesSet.remove(vXGroupUser.getName());
Expand All @@ -550,7 +576,10 @@ private List<XXTrxLogV2> createOrDelGrpUserWithUpdatedGrpId(VXUser vXUser, Colle
} else {
for (Long groupId : groupIdList) {
VXGroupUser vXGroupUser = createXGroupUser(userId, groupId);
trxLogList.addAll(xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT));
List<XXTrxLogV2> groupUserTrxLogs = xGroupUserService.getTransactionLog(vXGroupUser, null, OPERATION_CREATE_CONTEXT);
if (CollectionUtils.isNotEmpty(groupUserTrxLogs)) {
trxLogList.addAll(groupUserTrxLogs);
}
groupNamesSet.add(vXGroupUser.getName());
}
}
Expand Down

0 comments on commit b051ad6

Please sign in to comment.