@Test public void testToVXResourceForServiceNull(){ RangerPolicy policy = new RangerPolicy(); policy.setId(1L); policy.setName("hive Policy"); policy.setService("hive"); policy.setDescription("hive policy description"); RangerService rangerService = null; VXResource vXResource = serviceUtil.toVXResource(policy, rangerService); Assert.assertNull(vXResource); }
public VXResource toVXResource(RangerPolicy policy, RangerService service) { if(policy == null || service == null || toAssetType(service.getType()) == null) { return null; } VXResource ret = new VXResource(); rangerObjectToDataObject(policy, ret); ret.setAssetName(policy.getService()); ret.setAssetId(service.getId()); ret.setAssetType(toAssetType(service.getType())); ret.setPolicyName(policy.getName()); ret.setDescription(policy.getDescription()); ret.setGuid(policy.getGuid()); ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED); List<VXAuditMap> auditList = null; if(policy.getIsAuditEnabled()) { VXAuditMap auditMap = new VXAuditMap(); auditMap.setResourceId(policy.getId()); auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList = new ArrayList<VXAuditMap>(); auditList.add(auditMap); } ret.setAuditList(auditList); for(Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) { RangerPolicy.RangerPolicyResource res = e.getValue(); String resType = e.getKey(); String resString = getResourceString(res.getValues()); if("path".equalsIgnoreCase(resType)) { ret.setName(resString); ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE); } else if("table".equalsIgnoreCase(resType)) { ret.setTables(resString); ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("column-family".equalsIgnoreCase(resType)) { ret.setColumnFamilies(resString); } else if("column".equalsIgnoreCase(resType)) { ret.setColumns(resString); ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("database".equalsIgnoreCase(resType)) { ret.setDatabases(resString); } else if("udf".equalsIgnoreCase(resType)) { ret.setUdfs(resString); } else if("topology".equalsIgnoreCase(resType)) { ret.setTopologies(resString); } else if("service".equalsIgnoreCase(resType)) { ret.setServices(resString); } else if(resType.equalsIgnoreCase("hiveservice")) { ret.setHiveServices(resString); } } updateResourceName(ret); List<VXPermMap> permMapList = getVXPermMapList(policy); ret.setPermMapList(permMapList); return ret; }
ServiceUtil { public VXResource toVXResource(RangerPolicy policy, RangerService service) { if(policy == null || service == null || toAssetType(service.getType()) == null) { return null; } VXResource ret = new VXResource(); rangerObjectToDataObject(policy, ret); ret.setAssetName(policy.getService()); ret.setAssetId(service.getId()); ret.setAssetType(toAssetType(service.getType())); ret.setPolicyName(policy.getName()); ret.setDescription(policy.getDescription()); ret.setGuid(policy.getGuid()); ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED); List<VXAuditMap> auditList = null; if(policy.getIsAuditEnabled()) { VXAuditMap auditMap = new VXAuditMap(); auditMap.setResourceId(policy.getId()); auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList = new ArrayList<VXAuditMap>(); auditList.add(auditMap); } ret.setAuditList(auditList); for(Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) { RangerPolicy.RangerPolicyResource res = e.getValue(); String resType = e.getKey(); String resString = getResourceString(res.getValues()); if("path".equalsIgnoreCase(resType)) { ret.setName(resString); ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE); } else if("table".equalsIgnoreCase(resType)) { ret.setTables(resString); ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("column-family".equalsIgnoreCase(resType)) { ret.setColumnFamilies(resString); } else if("column".equalsIgnoreCase(resType)) { ret.setColumns(resString); ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("database".equalsIgnoreCase(resType)) { ret.setDatabases(resString); } else if("udf".equalsIgnoreCase(resType)) { ret.setUdfs(resString); } else if("topology".equalsIgnoreCase(resType)) { ret.setTopologies(resString); } else if("service".equalsIgnoreCase(resType)) { ret.setServices(resString); } else if(resType.equalsIgnoreCase("hiveservice")) { ret.setHiveServices(resString); } } updateResourceName(ret); List<VXPermMap> permMapList = getVXPermMapList(policy); ret.setPermMapList(permMapList); return ret; } }
ServiceUtil { public VXResource toVXResource(RangerPolicy policy, RangerService service) { if(policy == null || service == null || toAssetType(service.getType()) == null) { return null; } VXResource ret = new VXResource(); rangerObjectToDataObject(policy, ret); ret.setAssetName(policy.getService()); ret.setAssetId(service.getId()); ret.setAssetType(toAssetType(service.getType())); ret.setPolicyName(policy.getName()); ret.setDescription(policy.getDescription()); ret.setGuid(policy.getGuid()); ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED); List<VXAuditMap> auditList = null; if(policy.getIsAuditEnabled()) { VXAuditMap auditMap = new VXAuditMap(); auditMap.setResourceId(policy.getId()); auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList = new ArrayList<VXAuditMap>(); auditList.add(auditMap); } ret.setAuditList(auditList); for(Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) { RangerPolicy.RangerPolicyResource res = e.getValue(); String resType = e.getKey(); String resString = getResourceString(res.getValues()); if("path".equalsIgnoreCase(resType)) { ret.setName(resString); ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE); } else if("table".equalsIgnoreCase(resType)) { ret.setTables(resString); ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("column-family".equalsIgnoreCase(resType)) { ret.setColumnFamilies(resString); } else if("column".equalsIgnoreCase(resType)) { ret.setColumns(resString); ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("database".equalsIgnoreCase(resType)) { ret.setDatabases(resString); } else if("udf".equalsIgnoreCase(resType)) { ret.setUdfs(resString); } else if("topology".equalsIgnoreCase(resType)) { ret.setTopologies(resString); } else if("service".equalsIgnoreCase(resType)) { ret.setServices(resString); } else if(resType.equalsIgnoreCase("hiveservice")) { ret.setHiveServices(resString); } } updateResourceName(ret); List<VXPermMap> permMapList = getVXPermMapList(policy); ret.setPermMapList(permMapList); return ret; }  }
ServiceUtil { public VXResource toVXResource(RangerPolicy policy, RangerService service) { if(policy == null || service == null || toAssetType(service.getType()) == null) { return null; } VXResource ret = new VXResource(); rangerObjectToDataObject(policy, ret); ret.setAssetName(policy.getService()); ret.setAssetId(service.getId()); ret.setAssetType(toAssetType(service.getType())); ret.setPolicyName(policy.getName()); ret.setDescription(policy.getDescription()); ret.setGuid(policy.getGuid()); ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED); List<VXAuditMap> auditList = null; if(policy.getIsAuditEnabled()) { VXAuditMap auditMap = new VXAuditMap(); auditMap.setResourceId(policy.getId()); auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList = new ArrayList<VXAuditMap>(); auditList.add(auditMap); } ret.setAuditList(auditList); for(Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) { RangerPolicy.RangerPolicyResource res = e.getValue(); String resType = e.getKey(); String resString = getResourceString(res.getValues()); if("path".equalsIgnoreCase(resType)) { ret.setName(resString); ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE); } else if("table".equalsIgnoreCase(resType)) { ret.setTables(resString); ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("column-family".equalsIgnoreCase(resType)) { ret.setColumnFamilies(resString); } else if("column".equalsIgnoreCase(resType)) { ret.setColumns(resString); ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("database".equalsIgnoreCase(resType)) { ret.setDatabases(resString); } else if("udf".equalsIgnoreCase(resType)) { ret.setUdfs(resString); } else if("topology".equalsIgnoreCase(resType)) { ret.setTopologies(resString); } else if("service".equalsIgnoreCase(resType)) { ret.setServices(resString); } else if(resType.equalsIgnoreCase("hiveservice")) { ret.setHiveServices(resString); } } updateResourceName(ret); List<VXPermMap> permMapList = getVXPermMapList(policy); ret.setPermMapList(permMapList); 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); }
ServiceUtil { public VXResource toVXResource(RangerPolicy policy, RangerService service) { if(policy == null || service == null || toAssetType(service.getType()) == null) { return null; } VXResource ret = new VXResource(); rangerObjectToDataObject(policy, ret); ret.setAssetName(policy.getService()); ret.setAssetId(service.getId()); ret.setAssetType(toAssetType(service.getType())); ret.setPolicyName(policy.getName()); ret.setDescription(policy.getDescription()); ret.setGuid(policy.getGuid()); ret.setResourceStatus(policy.getIsEnabled() ? RangerCommonEnums.STATUS_ENABLED : RangerCommonEnums.STATUS_DISABLED); List<VXAuditMap> auditList = null; if(policy.getIsAuditEnabled()) { VXAuditMap auditMap = new VXAuditMap(); auditMap.setResourceId(policy.getId()); auditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList = new ArrayList<VXAuditMap>(); auditList.add(auditMap); } ret.setAuditList(auditList); for(Map.Entry<String, RangerPolicy.RangerPolicyResource> e : policy.getResources().entrySet()) { RangerPolicy.RangerPolicyResource res = e.getValue(); String resType = e.getKey(); String resString = getResourceString(res.getValues()); if("path".equalsIgnoreCase(resType)) { ret.setName(resString); ret.setIsRecursive(Boolean.TRUE.equals(res.getIsRecursive()) ? RangerCommonEnums.BOOL_TRUE : RangerCommonEnums.BOOL_FALSE); } else if("table".equalsIgnoreCase(resType)) { ret.setTables(resString); ret.setTableType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("column-family".equalsIgnoreCase(resType)) { ret.setColumnFamilies(resString); } else if("column".equalsIgnoreCase(resType)) { ret.setColumns(resString); ret.setColumnType(Boolean.TRUE.equals(res.getIsExcludes()) ? RangerCommonEnums.POLICY_EXCLUSION : RangerCommonEnums.POLICY_INCLUSION); } else if("database".equalsIgnoreCase(resType)) { ret.setDatabases(resString); } else if("udf".equalsIgnoreCase(resType)) { ret.setUdfs(resString); } else if("topology".equalsIgnoreCase(resType)) { ret.setTopologies(resString); } else if("service".equalsIgnoreCase(resType)) { ret.setServices(resString); } else if(resType.equalsIgnoreCase("hiveservice")) { ret.setHiveServices(resString); } } updateResourceName(ret); List<VXPermMap> permMapList = getVXPermMapList(policy); ret.setPermMapList(permMapList); 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);  }