RangerBizUtil { public Long getXUserId() { UserSessionBase currentUserSession = ContextUtil .getCurrentUserSession(); if (currentUserSession == null) { logger.debug("Unable to find session."); return null; } XXPortalUser user = daoManager.getXXPortalUser().getById( currentUserSession.getUserId()); if (user == null) { logger.debug("XXPortalUser not found with logged in user id : " + currentUserSession.getUserId()); return null; } XXUser xUser = daoManager.getXXUser().findByUserName(user.getLoginId()); if (xUser == null) { logger.debug("XXPortalUser not found for user id :" + user.getId() + " with name " + user.getFirstName()); return null; } return xUser.getId(); } 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 testGetXUserId_NoUserSession(){ RangerContextHolder.setSecurityContext(null); Long chk = rangerBizUtil.getXUserId(); Assert.assertNull(chk); }
@Test public void testGetXUserId_NoUser(){ RangerSecurityContext context = new RangerSecurityContext(); context.setUserSession(new UserSessionBase()); RangerContextHolder.setSecurityContext(context); XXPortalUser xxPortalUser = new XXPortalUser(); xxPortalUser.setId(id); xxPortalUser.setLoginId("12121"); context.getUserSession().setXXPortalUser(xxPortalUser); XXUser xxUser = new XXUser(); XXUserDao xxUserDao = Mockito.mock(XXUserDao.class); XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class); Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao); Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPortalUser); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser); Long chk = rangerBizUtil.getXUserId(); Mockito.verify(daoManager).getXXPortalUser(); Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong()); Mockito.verify(daoManager).getXXUser(); Mockito.verify(xxUserDao).findByUserName(Mockito.anyString()); Assert.assertNull(chk); }
@Test public void testGetXUserId(){ XXPortalUser xxPortalUser = new XXPortalUser(); xxPortalUser.setId(id); xxPortalUser.setLoginId("12121"); XXUser xxUser = new XXUser(); xxUser.setId(id); XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class); XXUserDao xxUserDao = Mockito.mock(XXUserDao.class); RangerSecurityContext context = new RangerSecurityContext(); UserSessionBase userSessionBase = new UserSessionBase(); userSessionBase.setUserAdmin(true); context.setUserSession(userSessionBase); userSessionBase.setXXPortalUser(xxPortalUser); RangerContextHolder.setSecurityContext(context); Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao); Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPortalUser); Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao); Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser); Long chk = rangerBizUtil.getXUserId(); Mockito.verify(daoManager).getXXPortalUser(); Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong()); Mockito.verify(daoManager).getXXUser(); Mockito.verify(xxUserDao).findByUserName(Mockito.anyString()); Assert.assertEquals(chk, id); }