|
111 | 111 | import javax.ws.rs.core.Response;
|
112 | 112 |
|
113 | 113 | import java.util.ArrayList;
|
| 114 | +import java.util.Collections; |
114 | 115 | import java.util.HashMap;
|
115 | 116 | import java.util.List;
|
116 | 117 | import java.util.Map;
|
@@ -457,13 +458,31 @@ public VXUserList searchXUsers(@Context HttpServletRequest request, @QueryParam(
|
457 | 458 | hasRole = !userRolesList.contains(RangerConstants.ROLE_KEY_ADMIN_AUDITOR) ? userRolesList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR) : hasRole;
|
458 | 459 | hasRole = !userRolesList.contains(RangerConstants.ROLE_USER) ? userRolesList.add(RangerConstants.ROLE_USER) : hasRole;
|
459 | 460 | } else if (loggedInVXUser.getUserRoleList().contains(RangerConstants.ROLE_USER)) {
|
| 461 | + if ((CollectionUtils.isNotEmpty(userRolesList) && (userRolesList.size() != 1 || !userRolesList.contains(RangerConstants.ROLE_USER))) |
| 462 | + || (userRole != null && !RangerConstants.ROLE_USER.equals(userRole))) { |
| 463 | + throw restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested user data."); |
| 464 | + } |
| 465 | + |
460 | 466 | logger.info("Logged-In user having user role will be able to fetch his own user details.");
|
461 | 467 |
|
462 |
| - if (!searchCriteria.getParamList().containsKey("name")) { |
463 |
| - searchCriteria.addParam("name", loggedInVXUser.getName()); |
464 |
| - } else if (searchCriteria.getParamList().containsKey("name") && !stringUtil.isEmpty(searchCriteria.getParamValue("name").toString()) && !searchCriteria.getParamValue("name").toString().equalsIgnoreCase(loggedInVXUser.getName())) { |
| 468 | + if (searchCriteria.getParamList().containsKey("name") && !stringUtil.isEmpty(searchCriteria.getParamValue("name").toString()) && !searchCriteria.getParamValue("name").toString().equalsIgnoreCase(loggedInVXUser.getName())) { |
465 | 469 | throw restErrorUtil.create403RESTException("Logged-In user is not allowed to access requested user data.");
|
466 | 470 | }
|
| 471 | + |
| 472 | + if (loggedInVXUser != null && !xUserMgr.hasAccessToModule(RangerConstants.MODULE_USER_GROUPS)) { |
| 473 | + loggedInVXUser = xUserMgr.getMaskedVXUser(loggedInVXUser); |
| 474 | + } |
| 475 | + |
| 476 | + VXUserList vXUserList = new VXUserList(); |
| 477 | + vXUserList.setVXUsers(Collections.singletonList(loggedInVXUser)); |
| 478 | + vXUserList.setStartIndex(searchCriteria.getStartIndex()); |
| 479 | + vXUserList.setResultSize(vXUserList.getVXUsers().size()); |
| 480 | + vXUserList.setTotalCount(vXUserList.getVXUsers().size()); |
| 481 | + vXUserList.setPageSize(searchCriteria.getMaxRows()); |
| 482 | + vXUserList.setSortBy(searchCriteria.getSortBy()); |
| 483 | + vXUserList.setSortType(searchCriteria.getSortType()); |
| 484 | + |
| 485 | + return vXUserList; |
467 | 486 | }
|
468 | 487 | }
|
469 | 488 | }
|
|
0 commit comments