Java Code Examples for org.apache.ranger.plugin.model.RangerPolicy#setName()
The following examples show how to use
org.apache.ranger.plugin.model.RangerPolicy#setName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034.java From ranger with Apache License 2.0 | 6 votes |
private RangerPolicy getRangerPolicyObject(String serviceName, String policyName) { RangerPolicy rangerPolicy = new RangerPolicy(); RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(rangerPolicy); rangerPolicy.setName(policyName); rangerPolicy.setDescription("Policy for " + policyName); rangerPolicy.setService(serviceName); rangerPolicy.setPolicyPriority(RangerPolicy.POLICY_PRIORITY_NORMAL); rangerPolicy.setIsAuditEnabled(Boolean.TRUE); rangerPolicy.setIsEnabled(Boolean.TRUE); rangerPolicy.setPolicyType(RangerPolicy.POLICY_TYPE_ACCESS); rangerPolicy.setGuid(guidUtil.genGUID()); rangerPolicy.setResourceSignature(resourceSignature.getSignature()); rangerPolicy.setZoneName(""); rangerPolicy.setUpdatedBy(LOGIN_ID_ADMIN); return rangerPolicy; }
Example 2
Source File: PublicAPIsv2.java From ranger with Apache License 2.0 | 6 votes |
@PUT @Path("/api/service/{servicename}/policy/{policyname}") @Produces({ "application/json", "application/xml" }) public RangerPolicy updatePolicyByName(RangerPolicy policy, @PathParam("servicename") String serviceName, @PathParam("policyname") String policyName, @Context HttpServletRequest request) { if (policy.getService() == null || !policy.getService().equals(serviceName)) { throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST , "service name mismatch", true); } RangerPolicy oldPolicy = getPolicyByName(serviceName, policyName, request); // ignore policy.id - if specified. Retrieve using the given serviceName+policyName and use id from the retrieved object policy.setId(oldPolicy.getId()); if(StringUtils.isEmpty(policy.getGuid())) { policy.setGuid(oldPolicy.getGuid()); } if(StringUtils.isEmpty(policy.getName())) { policy.setName(StringUtils.trim(oldPolicy.getName())); } return serviceREST.updatePolicy(policy); }
Example 3
Source File: RangerServiceHdfs.java From ranger with Apache License 2.0 | 5 votes |
private RangerPolicy getPolicyForKMSAudit(List<RangerServiceDef.RangerResourceDef> resourceHierarchy) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceHdfs.getPolicyForKMSAudit()"); } RangerPolicy policy = new RangerPolicy(); policy.setIsEnabled(true); policy.setVersion(1L); policy.setName(AUDITTOHDFS_POLICY_NAME); policy.setService(service.getName()); policy.setDescription("Policy for " + AUDITTOHDFS_POLICY_NAME); policy.setIsAuditEnabled(true); policy.setResources(createKMSAuditResource(resourceHierarchy)); List<RangerPolicy.RangerPolicyItem> policyItems = new ArrayList<RangerPolicy.RangerPolicyItem>(); //Create policy item for keyadmin RangerPolicy.RangerPolicyItem policyItem = new RangerPolicy.RangerPolicyItem(); List<String> userKeyAdmin = new ArrayList<String>(); userKeyAdmin.add("keyadmin"); policyItem.setUsers(userKeyAdmin); policyItem.setAccesses(getAllowedAccesses(policy.getResources())); policyItem.setDelegateAdmin(false); policyItems.add(policyItem); policy.setPolicyItems(policyItems); if (LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceHdfs.getPolicyForKMSAudit()" + policy); } return policy; }
Example 4
Source File: RangerBaseService.java From ranger with Apache License 2.0 | 5 votes |
private RangerPolicy getDefaultPolicy(List<RangerServiceDef.RangerResourceDef> resourceHierarchy) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerBaseService.getDefaultPolicy()"); } RangerPolicy policy = new RangerPolicy(); String policyName=buildPolicyName(resourceHierarchy); policy.setIsEnabled(true); policy.setVersion(1L); policy.setName(policyName); policy.setService(service.getName()); policy.setDescription("Policy for " + policyName); policy.setIsAuditEnabled(true); policy.setResources(createDefaultPolicyResource(resourceHierarchy)); List<RangerPolicy.RangerPolicyItem> policyItems = new ArrayList<RangerPolicy.RangerPolicyItem>(); //Create Default policy item for the service user RangerPolicy.RangerPolicyItem policyItem = createDefaultPolicyItem(policy.getResources()); policyItems.add(policyItem); policy.setPolicyItems(policyItems); if (LOG.isDebugEnabled()) { LOG.debug("<== RangerBaseService.getDefaultPolicy()" + policy); } return policy; }
Example 5
Source File: RangerServiceAtlas.java From ranger with Apache License 2.0 | 5 votes |
private RangerPolicy getSearchFeaturePolicy() { RangerPolicy searchFeaturePolicy = new RangerPolicy(); searchFeaturePolicy.setName(SEARCH_FEATURE_POLICY_NAME); searchFeaturePolicy.setService(serviceName); searchFeaturePolicy.setResources(getSearchFeaturePolicyResource()); searchFeaturePolicy.setPolicyItems(getSearchFeaturePolicyItem()); return searchFeaturePolicy; }
Example 6
Source File: TestPublicAPIsv2.java From ranger with Apache License 2.0 | 5 votes |
private RangerPolicy rangerPolicy() { List<RangerPolicyItemAccess> accesses = new ArrayList<RangerPolicyItemAccess>(); List<String> users = new ArrayList<String>(); List<String> groups = new ArrayList<String>(); List<RangerPolicyItemCondition> conditions = new ArrayList<RangerPolicyItemCondition>(); List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicyItem>(); RangerPolicyItem rangerPolicyItem = new RangerPolicyItem(); rangerPolicyItem.setAccesses(accesses); rangerPolicyItem.setConditions(conditions); rangerPolicyItem.setGroups(groups); rangerPolicyItem.setUsers(users); rangerPolicyItem.setDelegateAdmin(false); policyItems.add(rangerPolicyItem); Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>(); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(true); rangerPolicyResource.setIsRecursive(true); rangerPolicyResource.setValue("1"); rangerPolicyResource.setValues(users); policyResource.put("resource", rangerPolicyResource); RangerPolicy policy = new RangerPolicy(); policy.setId(Id); policy.setCreateTime(new Date()); policy.setDescription("policy"); policy.setGuid("policyguid"); policy.setIsEnabled(true); policy.setName("HDFS_1-1-20150316062453"); policy.setUpdatedBy("Admin"); policy.setUpdateTime(new Date()); policy.setService("HDFS_1-1-20150316062453"); policy.setIsAuditEnabled(true); policy.setPolicyItems(policyItems); policy.setResources(policyResource); policy.setService("HDFS_1"); return policy; }
Example 7
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 9
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 10
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@Test public void testToVXResourceForPath(){ GUIDUtil guid = new GUIDUtil(); String guidString = guid.genGUID(); List<VXAuditMap> auditList = new ArrayList<VXAuditMap>(); VXAuditMap vxAuditMap = new VXAuditMap(); vxAuditMap.setResourceId(1L); vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList.add(vxAuditMap); VXResource expectedVXResource = new VXResource(); expectedVXResource.setName("resource"); expectedVXResource.setGuid(guidString); expectedVXResource.setPolicyName("hdfs Policy"); expectedVXResource.setDescription("hdfs policy description"); expectedVXResource.setResourceType(1); expectedVXResource.setAssetName("hdfs"); expectedVXResource.setAssetType(1); expectedVXResource.setAuditList(auditList); Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesList = new ArrayList<String>(); valuesList.add("resource"); RangerPolicy policy = new RangerPolicy(); policy.setId(1L); policy.setName("hdfs Policy"); policy.setService("hdfs"); policy.setDescription("hdfs policy description"); policy.setIsEnabled(true); policy.setGuid(guidString); policy.setIsAuditEnabled(true); RangerService rangerService = new RangerService(); rangerService.setName("hdfs"); rangerService.setType("hdfs"); RangerPolicyResource rangerPolicyResource = new RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(true); rangerPolicyResource.setValue("/localhost/files"); rangerPolicyResource.setValues(valuesList); rangerPolicyResourceMap.put("path", rangerPolicyResource); policy.setResources(rangerPolicyResourceMap); VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService); Assert.assertNotNull(actualVXResource); Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName()); Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid()); Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName()); Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType()); Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription()); Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName()); Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType()); Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId()); Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType()); }
Example 11
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 12
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@Test public void testToVXResourceForTopologyAndService(){ GUIDUtil guid = new GUIDUtil(); String guidString = guid.genGUID(); List<VXAuditMap> auditList = new ArrayList<VXAuditMap>(); VXAuditMap vxAuditMap = new VXAuditMap(); vxAuditMap.setResourceId(1L); vxAuditMap.setAuditType(AppConstants.XA_AUDIT_TYPE_ALL); auditList.add(vxAuditMap); VXResource expectedVXResource = new VXResource(); expectedVXResource.setName("/myTopology/myService"); expectedVXResource.setTopologies("myTopology"); expectedVXResource.setServices("myService"); expectedVXResource.setGuid(guidString); expectedVXResource.setPolicyName("knox Policy"); expectedVXResource.setDescription("knox policy description"); expectedVXResource.setResourceType(1); expectedVXResource.setAssetName("knox"); expectedVXResource.setAssetType(5); expectedVXResource.setResourceStatus(1); expectedVXResource.setAuditList(auditList); Map<String, RangerPolicyResource> rangerPolicyResourceMap = new HashMap<String, RangerPolicyResource>(); List<String> valuesListForTopology = new ArrayList<String>(); valuesListForTopology.add("myTopology"); List<String> valuesListForService = new ArrayList<String>(); valuesListForService.add("myService"); RangerPolicy policy = new RangerPolicy(); policy.setId(1L); policy.setName("knox Policy"); policy.setService("knox"); policy.setDescription("knox policy description"); policy.setIsEnabled(true); policy.setGuid(guidString); policy.setIsAuditEnabled(true); RangerService rangerService = new RangerService(); rangerService.setName("knox"); rangerService.setType("knox"); RangerPolicyResource rangerPolicyResourceForTopology = new RangerPolicyResource(); rangerPolicyResourceForTopology.setValue("topology"); rangerPolicyResourceForTopology.setValues(valuesListForTopology); rangerPolicyResourceMap.put("topology", rangerPolicyResourceForTopology); RangerPolicyResource rangerPolicyResourceForService = new RangerPolicyResource(); rangerPolicyResourceForService.setValue("service"); rangerPolicyResourceForService.setValues(valuesListForService); rangerPolicyResourceMap.put("service", rangerPolicyResourceForService); policy.setResources(rangerPolicyResourceMap); VXResource actualVXResource = serviceUtil.toVXResource(policy, rangerService); Assert.assertNotNull(actualVXResource); Assert.assertEquals(expectedVXResource.getName(), actualVXResource.getName()); Assert.assertEquals(expectedVXResource.getGuid(), actualVXResource.getGuid()); Assert.assertEquals(expectedVXResource.getPolicyName(), actualVXResource.getPolicyName()); Assert.assertEquals(expectedVXResource.getResourceType(), actualVXResource.getResourceType()); Assert.assertEquals(expectedVXResource.getDescription(), actualVXResource.getDescription()); Assert.assertEquals(expectedVXResource.getAssetName(), actualVXResource.getAssetName()); Assert.assertEquals(expectedVXResource.getAssetType(), actualVXResource.getAssetType()); Assert.assertEquals(expectedVXResource.getResourceStatus(), actualVXResource.getResourceStatus()); Assert.assertEquals(expectedVXResource.getTopologies(), actualVXResource.getTopologies()); Assert.assertEquals(expectedVXResource.getServices(), actualVXResource.getServices()); Assert.assertEquals(expectedVXResource.getAuditList().get(0).getResourceId(), actualVXResource.getAuditList().get(0).getResourceId()); Assert.assertEquals(expectedVXResource.getAuditList().get(0).getAuditType(), actualVXResource.getAuditList().get(0).getAuditType()); }
Example 13
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 14
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 15
Source File: RangerBaseService.java From ranger with Apache License 2.0 | 4 votes |
private void addCustomRangerDefaultPolicies(List<RangerPolicy> ret, Map<String, RangerPolicy.RangerPolicyResource> policyResourceMap, String policyPropertyPrefix) throws Exception { String policyName = configs.get(policyPropertyPrefix + PROP_DEFAULT_POLICY_NAME_SUFFIX); String description = configs.get(policyPropertyPrefix + "description"); if (StringUtils.isEmpty(description)) { description = "Policy for " + policyName; } RangerPolicy policy = new RangerPolicy(); policy.setName(policyName); policy.setIsEnabled(true); policy.setVersion(1L); policy.setIsAuditEnabled(true); policy.setService(serviceName); policy.setDescription(description); policy.setName(policyName); policy.setResources(policyResourceMap); for (int i = 1; ; i++) { String policyItemPropertyPrefix = policyPropertyPrefix + "policyItem." + i + "."; String policyItemUsers = configs.get(policyItemPropertyPrefix + "users"); String policyItemGroups = configs.get(policyItemPropertyPrefix + "groups"); String policyItemRoles = configs.get(policyItemPropertyPrefix + "roles"); String policyItemAccessTypes = configs.get(policyItemPropertyPrefix + "accessTypes"); String isDelegateAdmin = configs.get(policyItemPropertyPrefix + "isDelegateAdmin"); if (StringUtils.isEmpty(policyItemAccessTypes) || (StringUtils.isEmpty(policyItemUsers) && StringUtils.isEmpty(policyItemGroups) && StringUtils.isEmpty(policyItemRoles))) { break; } RangerPolicyItem policyItem = new RangerPolicyItem(); policyItem.setDelegateAdmin(Boolean.parseBoolean(isDelegateAdmin)); if (StringUtils.isNotBlank(policyItemUsers)) { policyItem.setUsers(Arrays.asList(policyItemUsers.split(","))); } if (StringUtils.isNotBlank(policyItemGroups)) { policyItem.setGroups(Arrays.asList(policyItemGroups.split(","))); } if (StringUtils.isNotBlank(policyItemRoles)) { policyItem.setRoles(Arrays.asList(policyItemRoles.split(","))); } if (StringUtils.isNotBlank(policyItemAccessTypes)) { for (String accessType : Arrays.asList(policyItemAccessTypes.split(","))) { RangerPolicyItemAccess polAccess = new RangerPolicyItemAccess(accessType, true); policyItem.getAccesses().add(polAccess); } } policy.getPolicyItems().add(policyItem); } LOG.info(getServiceName() + ": adding default policy: name=" + policy.getName()); ret.add(policy); }
Example 16
Source File: ServiceREST.java From ranger with Apache License 2.0 | 4 votes |
@POST @Path("/policies/apply") @Produces({ "application/json", "application/xml" }) public RangerPolicy applyPolicy(RangerPolicy policy, @Context HttpServletRequest request) { if (LOG.isDebugEnabled()) { LOG.debug("==> ServiceREST.applyPolicy(" + policy + ")"); } RangerPolicy ret = null; if (policy != null && StringUtils.isNotBlank(policy.getService())) { try { final RangerPolicy existingPolicy; String signature = (new RangerPolicyResourceSignature(policy)).getSignature(); List<RangerPolicy> policiesWithMatchingSignature = svcStore.getPoliciesByResourceSignature(policy.getService(), signature, true); if (CollectionUtils.isNotEmpty(policiesWithMatchingSignature)) { if (policiesWithMatchingSignature.size() == 1) { existingPolicy = policiesWithMatchingSignature.get(0); } else { throw new Exception("Multiple policies with matching policy-signature are found. Cannot determine target for applying policy"); } } else { existingPolicy = null; } boolean mergeIfExists = "true".equalsIgnoreCase(StringUtils.trimToEmpty(request.getParameter(PARAM_MERGE_IF_EXISTS))) ? true : false; if (existingPolicy == null) { if (StringUtils.isNotEmpty(policy.getName())) { XXPolicy dbPolicy = daoManager.getXXPolicy().findByPolicyName(policy.getName()); if (dbPolicy != null) { policy.setName(policy.getName() + System.currentTimeMillis()); } } ret = createPolicy(policy, null); } else { if(mergeIfExists) { ServiceRESTUtil.processApplyPolicy(existingPolicy, policy); } ret = updatePolicy(existingPolicy); } } catch(WebApplicationException excp) { throw excp; } catch (Exception exception) { LOG.error("Failed to apply policy:", exception); throw restErrorUtil.createRESTException(exception.getMessage()); } } else { throw restErrorUtil.createRESTException("Non-existing service specified:"); } if (LOG.isDebugEnabled()) { LOG.debug("<== ServiceREST.applyPolicy(" + policy + ") : " + ret); } return ret; }
Example 17
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 18
Source File: PatchForKafkaServiceDefUpdate_J10033.java From ranger with Apache License 2.0 | 4 votes |
private RangerPolicy getRangerPolicy(String newResource, XXPortalUser xxPortalUser, XXService xxService) { RangerPolicy policy = new RangerPolicy(); List<RangerPolicy.RangerPolicyItemAccess> accesses = getPolicyItemAccesses(); List<String> users = new ArrayList<>(DEFAULT_POLICY_USERS); List<String> groups = new ArrayList<>(DEFAULT_POLICY_GROUP); List<RangerPolicy.RangerPolicyItemCondition> conditions = new ArrayList<>(); List<RangerPolicy.RangerPolicyItem> policyItems = new ArrayList<>(); RangerPolicy.RangerPolicyItem rangerPolicyItem = new RangerPolicy.RangerPolicyItem(); rangerPolicyItem.setAccesses(accesses); rangerPolicyItem.setConditions(conditions); rangerPolicyItem.setGroups(groups); rangerPolicyItem.setUsers(users); rangerPolicyItem.setDelegateAdmin(false); policyItems.add(rangerPolicyItem); Map<String, RangerPolicy.RangerPolicyResource> policyResource = new HashMap<>(); RangerPolicy.RangerPolicyResource rangerPolicyResource = new RangerPolicy.RangerPolicyResource(); rangerPolicyResource.setIsExcludes(false); rangerPolicyResource.setIsRecursive(false); rangerPolicyResource.setValue("*"); String policyResourceName = CONSUMERGROUP_RESOURCE_NAME; policyResource.put(policyResourceName, rangerPolicyResource); policy.setCreateTime(new Date()); policy.setDescription(newResource); policy.setIsEnabled(true); policy.setName(newResource); policy.setCreatedBy(xxPortalUser.getLoginId()); policy.setUpdatedBy(xxPortalUser.getLoginId()); policy.setUpdateTime(new Date()); policy.setService(xxService.getName()); policy.setIsAuditEnabled(true); policy.setPolicyItems(policyItems); policy.setResources(policyResource); policy.setPolicyType(0); policy.setId(0L); policy.setGuid(""); policy.setPolicyLabels(new ArrayList<>()); policy.setVersion(1L); RangerPolicyResourceSignature resourceSignature = new RangerPolicyResourceSignature(policy); policy.setResourceSignature(resourceSignature.getSignature()); return policy; }
Example 19
Source File: TestServiceUtil.java From ranger with Apache License 2.0 | 4 votes |
@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()); }
Example 20
Source File: RangerServiceTag.java From ranger with Apache License 2.0 | 4 votes |
@Override public List<RangerPolicy> getDefaultRangerPolicies() throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceTag.getDefaultRangerPolicies() "); } List<RangerPolicy> ret = new ArrayList<RangerPolicy>(); boolean isConditionDefFound = false; List<RangerServiceDef.RangerPolicyConditionDef> policyConditionDefs = serviceDef.getPolicyConditions(); if (CollectionUtils.isNotEmpty(policyConditionDefs)) { for (RangerServiceDef.RangerPolicyConditionDef conditionDef : policyConditionDefs) { if (conditionDef.getName().equals(RANGER_TAG_EXPIRY_CONDITION_NAME)) { isConditionDefFound = true; break; } } } if (isConditionDefFound) { ret = super.getDefaultRangerPolicies(); String tagResourceName = null; if (!serviceDef.getResources().isEmpty()) { tagResourceName = serviceDef.getResources().get(0).getName(); for (RangerPolicy defaultPolicy : ret) { RangerPolicy.RangerPolicyResource tagPolicyResource = defaultPolicy.getResources().get(tagResourceName); if (tagPolicyResource != null) { String value = RANGER_TAG_NAME_EXPIRES_ON; tagPolicyResource.setValue(value); defaultPolicy.setName(value); defaultPolicy.setDescription("Policy for data with " + value + " tag"); List<RangerPolicy.RangerPolicyItem> defaultPolicyItems = defaultPolicy.getPolicyItems(); for (RangerPolicy.RangerPolicyItem defaultPolicyItem : defaultPolicyItems) { List<String> groups = new ArrayList<String>(); groups.add(GROUP_PUBLIC); defaultPolicyItem.setGroups(groups); List<RangerPolicy.RangerPolicyItemCondition> policyItemConditions = new ArrayList<RangerPolicy.RangerPolicyItemCondition>(); List<String> values = new ArrayList<String>(); values.add("yes"); RangerPolicy.RangerPolicyItemCondition policyItemCondition = new RangerPolicy.RangerPolicyItemCondition(RANGER_TAG_EXPIRY_CONDITION_NAME, values); policyItemConditions.add(policyItemCondition); defaultPolicyItem.setConditions(policyItemConditions); defaultPolicyItem.setDelegateAdmin(Boolean.FALSE); } defaultPolicy.setDenyPolicyItems(defaultPolicyItems); defaultPolicy.setPolicyItems(null); } } } } else { LOG.error("RangerServiceTag.getDefaultRangerPolicies() - Cannot create default TAG policy: Cannot get tagPolicyConditionDef with name=" + RANGER_TAG_EXPIRY_CONDITION_NAME); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceTag.getDefaultRangerPolicies() : " + ret); } return ret; }