RangerBizUtil { public boolean checkUserAccessible(VXUser vXUser) { boolean isAccessible = true; Collection<String> roleList = userMgr.getRolesByLoginId(vXUser .getName()); if (isKeyAdmin()) { if (vXUser.getUserRoleList().contains(RangerConstants.ROLE_SYS_ADMIN) || vXUser.getUserRoleList().contains(RangerConstants.ROLE_ADMIN_AUDITOR) || roleList.contains(RangerConstants.ROLE_SYS_ADMIN) || roleList.contains(RangerConstants.ROLE_ADMIN_AUDITOR)) { isAccessible = false; } } if (isAdmin()) { if (vXUser.getUserRoleList().contains(RangerConstants.ROLE_KEY_ADMIN) || vXUser.getUserRoleList().contains(RangerConstants.ROLE_KEY_ADMIN_AUDITOR) || roleList.contains(RangerConstants.ROLE_KEY_ADMIN) || roleList.contains(RangerConstants.ROLE_KEY_ADMIN_AUDITOR)) { isAccessible = false; } } if (!isAccessible) { throw restErrorUtil.createRESTException( "Logged in user is not allowed to create/update user", MessageEnums.OPER_NO_PERMISSION); } return isAccessible; } RangerBizUtil(); void checkSystemAdminAccess(); String generatePublicName(VXPortalUser userProfile,
			XXPortalUser gjUser); String generatePublicName(String firstName, String lastName); VXStringList mapStringListToVStringList(List<String> stringList); VXResponse hasPermission(VXResource vXResource, int permission); boolean isAdmin(); boolean isAuditAdmin(); String getCurrentUserLoginId(); Long getXUserId(); void failUnauthenticatedIfNotAllowed(); boolean matchHbasePolicy(String resourceName,
			List<XXResource> xResourceList, VXResponse vXResponse,
			Long xUserId, int permission); boolean matchHivePolicy(String resourceName,
			List<XXResource> xResourceList, Long xUserId, int permission); boolean matchHivePolicy(String resourceName,
			List<XXResource> xResourceList, Long xUserId, int permission,
			int reqTableType, int reqColumnType, boolean isUdfPolicy); String replaceMetaChars(String path); Long getPublicGroupId(); boolean isGroupInList(Long groupId, List<XXGroup> xGroupList); boolean isRecursiveWildCardMatch(String pathToCheck,
			String wildcardPath); List<Integer> getResorceTypeParentHirearchy(int resourceType,
			int assetType); boolean comparePathsForExactMatch(String path1, String path2); boolean nonRecursiveWildCardMatch(String pathToCheck,
			String wildcardPath); static boolean areAllEqual(int checkValue, int... otherValues); void createTrxLog(List<XXTrxLog> trxLogList); static int getDBFlavor(); String getDBVersion(); String getAuditDBType(); void setAuditDBType(String auditDBType); boolean isKeyAdmin(); boolean isAuditKeyAdmin(); Boolean hasAccess(XXDBBase xxDbBase, RangerBaseModelObject baseModel); void hasAdminPermissions(String objType); void hasKMSPermissions(String objType, String implClassName); boolean checkUserAccessible(VXUser vXUser); boolean isSSOEnabled(); boolean isUserAllowed(RangerService rangerService, String cfgNameAllowedUsers); boolean isUserAllowedForGrantRevoke(RangerService rangerService, String userName); boolean isUserRangerAdmin(String username); boolean isUserServiceAdmin(RangerService rangerService, String userName); boolean isUserInConfigParameter(RangerService rangerService, String configParamName, String userName); void blockAuditorRoleUser(); boolean hasModuleAccess(String moduleName); void removeEmptyStrings(List<String> list); void trimAll(List<String> list); static boolean isBulkMode(); static boolean setBulkMode(boolean val); void bulkModeOnlyFlushAndClear(); boolean checkAdminAccess(); final String EMPTY_CONTENT_DISPLAY_NAME; static final String AUDIT_STORE_RDBMS; static final String AUDIT_STORE_SOLR; static final String AUDIT_STORE_ElasticSearch; static final boolean batchClearEnabled; static final int policyBatchSize; static final int batchPersistSize; }
@Test public void testCheckUserAccessibleThrowErrorForAdminAndUserRoleKeyAdmin() throws Exception { Collection<String> roleList = new ArrayList<String>(); roleList.add(RangerConstants.ROLE_KEY_ADMIN); Mockito.when(userMgr.getRolesByLoginId(vXUser.getName())).thenReturn( roleList); Mockito.when(vXUser.getUserRoleList()).thenReturn(roleList); currentUserSession.setUserAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.when(currentUserSession.isUserAdmin()).thenReturn(true); WebApplicationException webExp = new WebApplicationException(); Mockito.when( restErrorUtil.createRESTException( "Logged in user is not allowed to create/update user", MessageEnums.OPER_NO_PERMISSION)).thenReturn(webExp); thrown.expect(WebApplicationException.class); rangerBizUtil.checkUserAccessible(vXUser); Mockito.verify(restErrorUtil).createRESTException( "Logged in user is not allowed to create/update user", MessageEnums.OPER_NO_PERMISSION); }
@Test public void testCheckUserAccessibleThrowErrorForAdminAndUserRoleKeyAdminAuditor() throws Exception { Collection<String> roleList = new ArrayList<String>(); roleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR); Mockito.when(userMgr.getRolesByLoginId(vXUser.getName())).thenReturn( roleList); Mockito.when(vXUser.getUserRoleList()).thenReturn(roleList); currentUserSession.setUserAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.when(currentUserSession.isUserAdmin()).thenReturn(true); WebApplicationException webExp = new WebApplicationException(); Mockito.when( restErrorUtil.createRESTException( "Logged in user is not allowed to create/update user", MessageEnums.OPER_NO_PERMISSION)).thenReturn(webExp); thrown.expect(WebApplicationException.class); rangerBizUtil.checkUserAccessible(vXUser); Mockito.verify(restErrorUtil).createRESTException( "Logged in user is not allowed to create/update user", MessageEnums.OPER_NO_PERMISSION); }
@Test public void testCheckUserAccessibleSuccessForAdmin(){ Collection<String> roleList = new ArrayList<String>(); roleList.add(RangerConstants.ROLE_SYS_ADMIN); Mockito.when(userMgr.getRolesByLoginId(vXUser.getName())).thenReturn( roleList); Mockito.when(vXUser.getUserRoleList()).thenReturn(roleList); currentUserSession.setUserAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.when(currentUserSession.isUserAdmin()).thenReturn(true); boolean result = rangerBizUtil.checkUserAccessible(vXUser); Assert.assertTrue(result); }