ServiceUtil { public RangerPolicy toRangerPolicy(VXResource resource, RangerService service) { if(resource == null) { return null; } RangerPolicy ret = new RangerPolicy(); dataObjectToRangerObject(resource, ret); if(service != null) { ret.setService(service.getName()); } else { ret.setService(resource.getAssetName()); } ret.setName(StringUtils.trim(resource.getPolicyName())); ret.setDescription(resource.getDescription()); ret.setIsEnabled(resource.getResourceStatus() == RangerCommonEnums.STATUS_ENABLED); ret.setIsAuditEnabled(resource.getAuditList() != null && !resource.getAuditList().isEmpty()); Boolean isPathRecursive = resource.getIsRecursive() == RangerCommonEnums.BOOL_TRUE; Boolean isTableExcludes = resource.getTableType() == RangerCommonEnums.POLICY_EXCLUSION; Boolean isColumnExcludes = resource.getColumnType() == RangerCommonEnums.POLICY_EXCLUSION; toRangerResourceList(resource.getName(), "path", Boolean.FALSE, isPathRecursive, ret.getResources()); toRangerResourceList(resource.getTables(), "table", isTableExcludes, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getColumnFamilies(), "column-family", Boolean.FALSE, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getColumns(), "column", isColumnExcludes, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getDatabases(), "database", Boolean.FALSE, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getUdfs(), "udf", Boolean.FALSE, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getTopologies(), "topology", Boolean.FALSE, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getServices(), "service", Boolean.FALSE, Boolean.FALSE, ret.getResources()); toRangerResourceList(resource.getHiveServices(), "hiveservice", Boolean.FALSE, Boolean.FALSE, ret.getResources()); HashMap<String, List<VXPermMap>> sortedPermMap = new HashMap<String, List<VXPermMap>>(); if (resource.getPermMapList() != null) { for(VXPermMap permMap : resource.getPermMapList()) { String permGrp = permMap.getPermGroup(); List<VXPermMap> sortedList = sortedPermMap.get(permGrp); if(sortedList == null) { sortedList = new ArrayList<VXPermMap>(); sortedPermMap.put(permGrp, sortedList); } sortedList.add(permMap); } } Integer assetType = getAssetType(service,ret.getService()); for (Entry<String, List<VXPermMap>> entry : sortedPermMap.entrySet()) { List<String> userList = new ArrayList<String>(); List<String> groupList = new ArrayList<String>(); List<RangerPolicyItemAccess> accessList = new ArrayList<RangerPolicyItemAccess>(); String ipAddress = null; RangerPolicy.RangerPolicyItem policyItem = new RangerPolicy.RangerPolicyItem(); for(VXPermMap permMap : entry.getValue()) { if(permMap.getPermFor() == AppConstants.XA_PERM_FOR_USER) { String userName = getUserName(permMap); if (! userList.contains(userName)) { userList.add(userName); } } else if(permMap.getPermFor() == AppConstants.XA_PERM_FOR_GROUP) { String groupName = getGroupName(permMap); if (! groupList.contains(groupName)) { groupList.add(groupName); } } String accessType = toAccessType(permMap.getPermType()); if(StringUtils.equalsIgnoreCase(accessType, "Admin")) { policyItem.setDelegateAdmin(Boolean.TRUE); if ( assetType != null && assetType == RangerCommonEnums.ASSET_HBASE) { accessList.add(new RangerPolicyItemAccess(accessType)); } } else { accessList.add(new RangerPolicyItemAccess(accessType)); } ipAddress = permMap.getIpAddress(); } policyItem.setUsers(userList); policyItem.setGroups(groupList); policyItem.setAccesses(accessList); if(ipAddress != null && !ipAddress.isEmpty()) { RangerPolicy.RangerPolicyItemCondition ipCondition = new RangerPolicy.RangerPolicyItemCondition("ipaddress", Collections.singletonList(ipAddress)); policyItem.getConditions().add(ipCondition); } ret.getPolicyItems().add(policyItem); } return ret; }  RangerService getServiceByName(@PathParam("name") String name); RangerService toRangerService(VXAsset asset); VXAsset toVXAsset(RangerService service); VXRepository toVXRepository(RangerService service); RangerPolicy toRangerPolicy(VXResource resource, RangerService service); VXResource toVXResource(RangerPolicy policy, RangerService service); VXAsset publicObjecttoVXAsset(VXRepository vXRepository); VXRepository vXAssetToPublicObject(VXAsset asset); static String toAccessType(int permType); SearchCriteria getMappedSearchParams(HttpServletRequest request,
			SearchCriteria searchCriteria); VXRepositoryList rangerServiceListToPublicObjectList(List<RangerService> serviceList); VXPolicy toVXPolicy(RangerPolicy policy, RangerService service); List<VXPermMap> getVXPermMapList(RangerPolicy policy); List<VXPermObj> mapPermMapToPermObj(List<VXPermMap> permMapList); RangerPolicy toRangerPolicy(VXPolicy vXPolicy, RangerService service ); VXPolicyList rangerPolicyListToPublic(List<RangerPolicy> rangerPolicyList,SearchFilter filter); GrantRevokeRequest toGrantRevokeRequest(VXPolicy vXPolicy); boolean isValidateHttpsAuthentication( String serviceName, HttpServletRequest request); boolean isValidService(String serviceName, HttpServletRequest request); List<RangerPolicy> getMatchingPoliciesForResource(HttpServletRequest request,
			List<RangerPolicy> policyLists);  }
@Test public void testToRangerPolicyForNull(){ VXResource resource = null; RangerService rangerService = null; RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNull(actualRangerPolicy); }
@Test public void testToRangerPolicyForResourceTypePath(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("resource"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(true); rangerPolicyResource.setValue("/localhost/files"); rangerPolicyResource.setValues(valuesList); expectedMap.put("path", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setName("resource"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeTable(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("xa_service"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(true); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("xa_service"); rangerPolicyResource.setValues(valuesList); expectedMap.put("table", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setTables("xa_service"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeColumnFamily(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("columnFamilies"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("columnFamilies"); rangerPolicyResource.setValues(valuesList); expectedMap.put("column-family", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setColumnFamilies("columnFamilies"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeColumn(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("column"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(true); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("column"); rangerPolicyResource.setValues(valuesList); expectedMap.put("column", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setColumns("column"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeDatabase(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("databases"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("databases"); rangerPolicyResource.setValues(valuesList); expectedMap.put("database", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setDatabases("databases"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeUDF(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("udf"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("databases"); rangerPolicyResource.setValues(valuesList); expectedMap.put("udf", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setUdfs("udf"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeTopology(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("topology"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("topology"); rangerPolicyResource.setValues(valuesList); expectedMap.put("topology", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setTopologies("topology"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeService(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("service"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("service"); rangerPolicyResource.setValues(valuesList); expectedMap.put("service", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setServices("service"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForResourceTypeHiveService(){ RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); Map<String, RangerPolicyResource> expectedMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("hiveservice"); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("hiveservice"); rangerPolicyResource.setValues(valuesList); expectedMap.put("service", rangerPolicyResource); expectedRangerPolicy.setResources(expectedMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setServices("hiveservice"); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); }
@Test public void testToRangerPolicyForPermGroup(){ RangerPolicyItemCondition rpic = new RangerPolicyItemCondition(); List<String> valuesList = new ArrayList<String>(); valuesList.add("10.129.25.56"); rpic.setType("ipaddress"); rpic.setValues(valuesList); List<String> usersList = new ArrayList<String>(); usersList.add("rangerAdmin"); List<String> groupList = new ArrayList<String>(); List<RangerPolicyItemCondition> listRPIC = new ArrayList<RangerPolicy.RangerPolicyItemCondition>(); listRPIC.add(rpic); RangerPolicyItemAccess rpia = new RangerPolicyItemAccess(); rpia.setIsAllowed(true); rpia.setType("drop"); List<RangerPolicyItemAccess> listRPIA = new ArrayList<RangerPolicy.RangerPolicyItemAccess>(); listRPIA.add(rpia); RangerPolicyItem rangerPolicyItem = new RangerPolicyItem(); rangerPolicyItem.setConditions(listRPIC); rangerPolicyItem.setAccesses(listRPIA); rangerPolicyItem.setDelegateAdmin(false); rangerPolicyItem.setUsers(usersList); rangerPolicyItem.setGroups(groupList); List<RangerPolicyItem> listRangerPolicyItem = new ArrayList<RangerPolicy.RangerPolicyItem>(); listRangerPolicyItem.add(rangerPolicyItem); RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hive Policy"); expectedRangerPolicy.setService("hive"); expectedRangerPolicy.setDescription("hive policy description"); expectedRangerPolicy.setPolicyItems(listRangerPolicyItem); VXPermMap vXPermMap = new VXPermMap(); vXPermMap.setId(5L); vXPermMap.setGroupName("myGroup"); vXPermMap.setPermGroup("permGroup"); vXPermMap.setUserName("rangerAdmin"); vXPermMap.setPermType(12); vXPermMap.setPermFor(AppConstants.XA_PERM_FOR_USER); vXPermMap.setIpAddress("10.129.25.56"); List<VXPermMap> vXPermMapList = new ArrayList<VXPermMap>(); vXPermMapList.add(vXPermMap); VXAuditMap vXAuditMap = new VXAuditMap(); vXAuditMap.setId(1L); vXAuditMap.setOwner("rangerAdmin"); List<VXAuditMap> vXAuditMapList = new ArrayList<VXAuditMap>(); vXAuditMapList.add(vXAuditMap); RangerService rangerService = new RangerService(); rangerService.setName("hive"); rangerService.setType("hive"); VXResource resource = new VXResource(); resource.setId(1L); resource.setUpdateDate(new Date()); resource.setCreateDate(new Date()); resource.setOwner("rangerAdmin"); resource.setUpdatedBy("rangerAdmin"); resource.setPolicyName("hive Policy"); resource.setDescription("hive policy description"); resource.setResourceStatus(RangerCommonEnums.STATUS_ENABLED); resource.setIsRecursive(1); resource.setTableType(1); resource.setColumnType(1); resource.setPermMapList(vXPermMapList); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(resource, rangerService); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getService(), actualRangerPolicy.getService()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getPolicyItems(), actualRangerPolicy.getPolicyItems()); }
@Test public void testToRangerPolicyForNullServiceAndNullVXPolicy(){ VXPolicy vXPolicy = null; RangerService service = null; RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(vXPolicy, service); Assert.assertNull(actualRangerPolicy); }
@Test public void testToRangerPolicy(){ Date date = new Date(); List<String> userList = new ArrayList<String>(); userList.add("rangerAdmin"); List<String> groupList = new ArrayList<String>(); groupList.add("rangerGroup"); List<String> permObjList = new ArrayList<String>(); permObjList.add("Admin"); Map<String, RangerPolicyResource> resourceMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("resource"); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(true); rangerPolicyResource.setValues(valuesList); resourceMap.put("path", rangerPolicyResource); List<RangerPolicyItem> rangerPolicyItemList = new ArrayList<RangerPolicy.RangerPolicyItem>(); RangerPolicyItem rangerPolicyItem = new RangerPolicyItem(); rangerPolicyItem.setUsers(userList); rangerPolicyItem.setGroups(groupList); List<RangerPolicyItemCondition> rangerPolicyItemConditionList = new ArrayList<RangerPolicy.RangerPolicyItemCondition>(); RangerPolicyItemCondition rangerPolicyItemCondition = new RangerPolicyItemCondition(); rangerPolicyItemCondition.setType("ipaddress"); List<String> conditionValueList = new ArrayList<String>(); conditionValueList.add("10.129.35.86"); rangerPolicyItemCondition.setValues(conditionValueList); rangerPolicyItemConditionList.add(rangerPolicyItemCondition); rangerPolicyItem.setConditions(rangerPolicyItemConditionList); rangerPolicyItem.setDelegateAdmin(true); rangerPolicyItemList.add(rangerPolicyItem); RangerPolicy expectedRangerPolicy = new RangerPolicy(); expectedRangerPolicy.setId(1L); expectedRangerPolicy.setName("hdfs"); expectedRangerPolicy.setCreatedBy("rangerAdmin"); expectedRangerPolicy.setCreateTime(date); expectedRangerPolicy.setDescription("hdfs policy description"); expectedRangerPolicy.setIsAuditEnabled(true); expectedRangerPolicy.setResources(resourceMap); expectedRangerPolicy.setPolicyItems(rangerPolicyItemList); VXPolicy vXPolicy = new VXPolicy(); vXPolicy.setId(1L); vXPolicy.setCreateDate(date); vXPolicy.setUpdateDate(date); vXPolicy.setOwner("rangerAdmin"); vXPolicy.setUpdatedBy("rangerAdmin"); vXPolicy.setPolicyName("hdfs"); vXPolicy.setDescription("hdfs policy description"); vXPolicy.setIsEnabled(true); vXPolicy.setIsAuditEnabled(true); vXPolicy.setIsRecursive(true); vXPolicy.setResourceName("resource"); RangerService service = new RangerService(); service.setId(1L); service.setName("hdfsService"); service.setType("hdfs"); List<VXPermObj> vXPermObjList = new ArrayList<VXPermObj>(); VXPermObj vXPermObj = new VXPermObj(); vXPermObj.setUserList(userList); vXPermObj.setGroupList(groupList); vXPermObj.setPermList(permObjList); vXPermObj.setIpAddress("10.129.35.86"); vXPermObjList.add(vXPermObj); vXPolicy.setPermMapList(vXPermObjList); RangerPolicy actualRangerPolicy = serviceUtil.toRangerPolicy(vXPolicy, service); Assert.assertNotNull(actualRangerPolicy); Assert.assertEquals(expectedRangerPolicy.getId(), actualRangerPolicy.getId()); Assert.assertEquals(expectedRangerPolicy.getName(), actualRangerPolicy.getName()); Assert.assertEquals(expectedRangerPolicy.getDescription(), actualRangerPolicy.getDescription()); Assert.assertEquals(expectedRangerPolicy.getCreatedBy(), actualRangerPolicy.getCreatedBy()); Assert.assertTrue(actualRangerPolicy.getIsAuditEnabled()); Assert.assertEquals(expectedRangerPolicy.getResources(), actualRangerPolicy.getResources()); Assert.assertEquals(expectedRangerPolicy.getPolicyItems(), actualRangerPolicy.getPolicyItems()); }