Java Code Examples for org.apache.ranger.plugin.model.RangerPolicy#getName()
The following examples show how to use
org.apache.ranger.plugin.model.RangerPolicy#getName() .
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: TestPublicAPIsv2.java From ranger with Apache License 2.0 | 6 votes |
@Test public void test18getPolicyByName() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); RangerPolicy rangerPolicy = rangerPolicy(); RangerService rangerService = rangerService(); String serviceName = rangerService.getName(); String policyName = rangerPolicy.getName(); List<RangerPolicy> policies = new ArrayList<RangerPolicy>(); policies.add(rangerPolicy); Mockito.when(serviceREST.getPolicies((SearchFilter) Mockito.any())).thenReturn(policies); RangerPolicy dbRangerPolicy = publicAPIsv2.getPolicyByName(serviceName, policyName, request); Assert.assertNotNull(dbRangerPolicy); Assert.assertEquals(dbRangerPolicy, rangerPolicy); Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId()); Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName()); Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.any()); }
Example 2
Source File: TestPublicAPIsv2.java From ranger with Apache License 2.0 | 6 votes |
@Test public void test23updatePolicyByName() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); RangerPolicy rangerPolicy = rangerPolicy(); String policyName = rangerPolicy.getName(); RangerService rangerService = rangerService(); String serviceName = rangerService.getName(); List<RangerPolicy> policies = new ArrayList<RangerPolicy>(); policies.add(rangerPolicy); Mockito.when(serviceREST.getPolicies((SearchFilter) Mockito.any())).thenReturn(policies); Mockito.when(serviceREST.updatePolicy(rangerPolicy)).thenReturn(rangerPolicy); RangerPolicy dbRangerPolicy = publicAPIsv2.updatePolicyByName(rangerPolicy, serviceName, policyName, request); Assert.assertNotNull(dbRangerPolicy); Assert.assertEquals(dbRangerPolicy, rangerPolicy); Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId()); Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName()); Mockito.verify(serviceREST).updatePolicy(rangerPolicy); Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.any()); }
Example 3
Source File: TestPublicAPIsv2.java From ranger with Apache License 2.0 | 5 votes |
@Test public void test25deletePolicyByName() throws Exception { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); RangerPolicy rangerPolicy = rangerPolicy(); String policyName = rangerPolicy.getName(); RangerService rangerService = rangerService(); String serviceName = rangerService.getName(); List<RangerPolicy> policies = new ArrayList<RangerPolicy>(); policies.add(rangerPolicy); Mockito.when(serviceREST.getPolicies((SearchFilter) Mockito.any())).thenReturn(policies); Mockito.doNothing().when(serviceREST).deletePolicy(Id); publicAPIsv2.deletePolicyByName(serviceName, policyName, request); Mockito.verify(serviceREST).getPolicies((SearchFilter) Mockito.any()); Mockito.verify(serviceREST).deletePolicy(Id); }
Example 4
Source File: PatchForUpdatingPolicyJson_J10019.java From ranger with Apache License 2.0 | 4 votes |
private void portPolicy(String serviceType, RangerPolicy policy) throws Exception { logger.info("==> portPolicy(id=" + policy.getId() + ")"); String policyText = JsonUtils.objectToJson(policy); if (StringUtils.isEmpty(policyText)) { throw new Exception("Failed to convert policy to json string. Policy: [id=" + policy.getId() + "; name=" + policy.getName() + "; serviceType=" + serviceType + "]"); } XXPolicyDao policyDao = daoMgr.getXXPolicy(); XXPolicy dbBean = policyDao.getById(policy.getId()); dbBean.setPolicyText(policyText); policyDao.update(dbBean); try { Set<String> accesses = new HashSet<>(); Set<String> users = new HashSet<>(); Set<String> groups = new HashSet<>(); Set<String> conditions = new HashSet<>(); Set<String> dataMasks = new HashSet<>(); buildLists(policy.getPolicyItems(), accesses, conditions, users, groups); buildLists(policy.getDenyPolicyItems(), accesses, conditions, users, groups); buildLists(policy.getAllowExceptions(), accesses, conditions, users, groups); buildLists(policy.getDenyExceptions(), accesses, conditions, users, groups); buildLists(policy.getDataMaskPolicyItems(), accesses, conditions, users, groups); buildLists(policy.getRowFilterPolicyItems(), accesses, conditions, users, groups); buildList(policy.getDataMaskPolicyItems(), dataMasks); addResourceDefRef(serviceType, policy); addUserNameRef(policy.getId(), users); addGroupNameRef(policy.getId(), groups); addAccessDefRef(serviceType, policy.getId(), accesses); addPolicyConditionDefRef(serviceType, policy.getId(), conditions); addDataMaskDefRef(serviceType, policy.getId(), dataMasks); } catch (Exception e) { logger.error("portPoliry(id=" + policy.getId() +") failed!!"); logger.error("Offending policy:" + policyText); throw e; } logger.info("<== portPolicy(id=" + policy.getId() + ")"); }
Example 5
Source File: PatchForUpdatingPolicyJson_J10019.java From ranger with Apache License 2.0 | 4 votes |
private void addResourceDefRef(String serviceType, RangerPolicy policy) throws Exception { logger.info("==> addResourceDefRef(id=" + policy.getId() + ")"); Map<String, Long> serviceDefResourceNameIDMap = resourceNameIdMap.get(serviceType); if (serviceDefResourceNameIDMap == null) { serviceDefResourceNameIDMap = new HashMap<>(); resourceNameIdMap.put(serviceType, serviceDefResourceNameIDMap); XXServiceDef dbServiceDef = daoMgr.getXXServiceDef().findByName(serviceType); for (XXResourceDef resourceDef : daoMgr.getXXResourceDef().findByServiceDefId(dbServiceDef.getId())) { serviceDefResourceNameIDMap.put(resourceDef.getName(), resourceDef.getId()); } } Map<String, RangerPolicyResource> policyResources = policy.getResources(); if (MapUtils.isNotEmpty(policyResources)) { XXPolicyRefResourceDao policyRefResourceDao = daoMgr.getXXPolicyRefResource(); Set<String> resourceNames = policyResources.keySet(); for (String resourceName : resourceNames) { Long resourceDefId = serviceDefResourceNameIDMap.get(resourceName); if (resourceDefId == null) { throw new Exception(resourceName + ": unknown resource in policy [id=" + policy.getId() + "; name=" + policy.getName() + "; serviceType=" + serviceType + "]. Known resources: " + serviceDefResourceNameIDMap.keySet()); } // insert policy-id, resourceDefId, resourceName into Ref table XXPolicyRefResource policyRefResource = new XXPolicyRefResource(); policyRefResource.setPolicyId(policy.getId()); policyRefResource.setResourceDefId(resourceDefId); policyRefResource.setResourceName(resourceName); policyRefResourceDao.create(policyRefResource); } } logger.info("<== addResourceDefRef(id=" + policy.getId() + ")"); }
Example 6
Source File: RangerDataHistService.java From ranger with Apache License 2.0 | 4 votes |
public void createObjectDataHistory(RangerBaseModelObject baseModelObj, String action) { if(baseModelObj == null || action == null) { throw restErrorUtil .createRESTException("Error while creating DataHistory. " + "Object or Action can not be null.", MessageEnums.DATA_NOT_FOUND); } Integer classType = null; String objectName = null; String content = null; Long objectId = baseModelObj.getId(); String objectGuid = baseModelObj.getGuid(); Date currentDate = DateUtil.getUTCDate(); XXDataHist xDataHist = new XXDataHist(); xDataHist.setObjectId(baseModelObj.getId()); xDataHist.setObjectGuid(objectGuid); xDataHist.setCreateTime(currentDate); xDataHist.setAction(action); xDataHist.setVersion(baseModelObj.getVersion()); xDataHist.setUpdateTime(currentDate); xDataHist.setFromTime(currentDate); if(baseModelObj instanceof RangerServiceDef) { RangerServiceDef serviceDef = (RangerServiceDef) baseModelObj; objectName = serviceDef.getName(); classType = AppConstants.CLASS_TYPE_XA_SERVICE_DEF; content = jsonUtil.writeObjectAsString(serviceDef); } else if(baseModelObj instanceof RangerService) { RangerService service = (RangerService) baseModelObj; objectName = service.getName(); classType = AppConstants.CLASS_TYPE_XA_SERVICE; content = jsonUtil.writeObjectAsString(service); } else if(baseModelObj instanceof RangerPolicy) { RangerPolicy policy = (RangerPolicy) baseModelObj; objectName = policy.getName(); classType = AppConstants.CLASS_TYPE_RANGER_POLICY; policy.setServiceType(policy.getServiceType()); content = jsonUtil.writeObjectAsString(policy); } xDataHist.setObjectClassType(classType); xDataHist.setObjectName(objectName); xDataHist.setContent(content); xDataHist = daoMgr.getXXDataHist().create(xDataHist); if (ACTION_UPDATE.equalsIgnoreCase(action) || ACTION_DELETE.equalsIgnoreCase(action)) { XXDataHist prevHist = daoMgr.getXXDataHist().findLatestByObjectClassTypeAndObjectId(classType, objectId); if(prevHist == null) { throw restErrorUtil.createRESTException( "Error updating DataHistory Object. ObjectName: " + objectName, MessageEnums.DATA_NOT_UPDATABLE); } prevHist.setUpdateTime(currentDate); prevHist.setToTime(currentDate); prevHist.setObjectName(objectName); prevHist = daoMgr.getXXDataHist().update(prevHist); } }