RangerBizUtil { public void blockAuditorRoleUser() { UserSessionBase session = ContextUtil.getCurrentUserSession(); if (session != null) { if (session.isAuditKeyAdmin() || session.isAuditUserAdmin()) { VXResponse vXResponse = new VXResponse(); vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED); vXResponse.setMsgDesc("Operation" + " denied. LoggedInUser=" + session.getXXPortalUser().getId() + " ,isn't permitted to perform the action."); throw restErrorUtil.generateRESTException(vXResponse); } } else { VXResponse vXResponse = new VXResponse(); vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED); vXResponse.setMsgDesc("Bad Credentials"); throw restErrorUtil.generateRESTException(vXResponse); } } 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 testBlockAuditorRoleUserThrowsErrorForAuditKeyAdmin(){ RangerBizUtil rangerBizUtilMock = Mockito.mock(RangerBizUtil.class); vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED); vXResponse.setMsgDesc("Operation denied. LoggedInUser=1 ,isn't permitted to perform the action."); XXPortalUser xxPortalUser = new XXPortalUser(); xxPortalUser.setId(1L); currentUserSession.setAuditKeyAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.doThrow(new WebApplicationException()).when(rangerBizUtilMock).blockAuditorRoleUser(); thrown.expect(WebApplicationException.class); rangerBizUtilMock.blockAuditorRoleUser(); }
@Test public void testBlockAuditorRoleUserThrowsErrorForAuditUserAdmin(){ RangerBizUtil rangerBizUtilMock = Mockito.mock(RangerBizUtil.class); vXResponse.setStatusCode(HttpServletResponse.SC_UNAUTHORIZED); vXResponse.setMsgDesc("Operation denied. LoggedInUser=1 ,isn't permitted to perform the action."); XXPortalUser xxPortalUser = new XXPortalUser(); xxPortalUser.setId(1L); currentUserSession.setAuditKeyAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.doThrow(new WebApplicationException()).when(rangerBizUtilMock).blockAuditorRoleUser(); thrown.expect(WebApplicationException.class); rangerBizUtilMock.blockAuditorRoleUser(); }
@Test public void testBlockAuditorRoleUserSuccess(){ RangerBizUtil rangerBizUtilMock = Mockito.mock(RangerBizUtil.class); XXPortalUser xxPortalUser = new XXPortalUser(); xxPortalUser.setId(1L); currentUserSession.setUserAdmin(true); RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(currentUserSession); RangerContextHolder.setSecurityContext(context); Mockito.doNothing().when(rangerBizUtilMock).blockAuditorRoleUser(); rangerBizUtilMock.blockAuditorRoleUser(); Mockito.verify(rangerBizUtilMock).blockAuditorRoleUser(); }