@Test public void tess29deletePolicy() throws Exception { setup(); XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXService xService = Mockito.mock(XXService.class); XXPolicyLabelMapDao xPolicyLabelMapDao = Mockito.mock(XXPolicyLabelMapDao.class); RangerService rangerService = rangerService(); RangerPolicy rangerPolicy = rangerPolicy(); String name = "HDFS_1-1-20150316062453"; List<XXPolicyItem> policyItemList = new ArrayList<XXPolicyItem>(); XXPolicyItem policyItem = new XXPolicyItem(); policyItem.setAddedByUserId(Id); policyItem.setCreateTime(new Date()); policyItem.setDelegateAdmin(false); policyItem.setId(Id); policyItem.setOrder(1); policyItem.setPolicyId(Id); policyItem.setUpdatedByUserId(Id); policyItem.setUpdateTime(new Date()); policyItemList.add(policyItem); List<XXPolicyItemCondition> policyItemConditionList = new ArrayList<XXPolicyItemCondition>(); XXPolicyItemCondition policyItemCondition = new XXPolicyItemCondition(); policyItemCondition.setAddedByUserId(Id); policyItemCondition.setCreateTime(new Date()); policyItemCondition.setType(1L); policyItemCondition.setId(Id); policyItemCondition.setOrder(1); policyItemCondition.setPolicyItemId(Id); policyItemCondition.setUpdatedByUserId(Id); policyItemCondition.setUpdateTime(new Date()); policyItemConditionList.add(policyItemCondition); List<XXPolicyItemGroupPerm> policyItemGroupPermList = new ArrayList<XXPolicyItemGroupPerm>(); XXPolicyItemGroupPerm policyItemGroupPerm = new XXPolicyItemGroupPerm(); policyItemGroupPerm.setAddedByUserId(Id); policyItemGroupPerm.setCreateTime(new Date()); policyItemGroupPerm.setGroupId(Id); List<XXServiceConfigMap> xConfMapList = new ArrayList<XXServiceConfigMap>(); XXServiceConfigMap xConfMap = new XXServiceConfigMap(); xConfMap.setAddedByUserId(null); xConfMap.setConfigkey(name); xConfMap.setConfigvalue(name); xConfMap.setCreateTime(new Date()); xConfMap.setServiceId(null); xConfMap.setId(Id); xConfMap.setUpdatedByUserId(null); xConfMap.setUpdateTime(new Date()); xConfMapList.add(xConfMap); policyItemGroupPerm.setId(Id); policyItemGroupPerm.setOrder(1); policyItemGroupPerm.setPolicyItemId(Id); policyItemGroupPerm.setUpdatedByUserId(Id); policyItemGroupPerm.setUpdateTime(new Date()); policyItemGroupPermList.add(policyItemGroupPerm); List<XXPolicyItemUserPerm> policyItemUserPermList = new ArrayList<XXPolicyItemUserPerm>(); XXPolicyItemUserPerm policyItemUserPerm = new XXPolicyItemUserPerm(); policyItemUserPerm.setAddedByUserId(Id); policyItemUserPerm.setCreateTime(new Date()); policyItemUserPerm.setPolicyItemId(Id); policyItemUserPerm.setId(Id); policyItemUserPerm.setOrder(1); policyItemUserPerm.setUpdatedByUserId(Id); policyItemUserPerm.setUpdateTime(new Date()); policyItemUserPermList.add(policyItemUserPerm); List<XXPolicyItemAccess> policyItemAccessList = new ArrayList<XXPolicyItemAccess>(); XXPolicyItemAccess policyItemAccess = new XXPolicyItemAccess(); policyItemAccess.setAddedByUserId(Id); policyItemAccess.setCreateTime(new Date()); policyItemAccess.setPolicyitemid(Id); policyItemAccess.setId(Id); policyItemAccess.setOrder(1); policyItemAccess.setUpdatedByUserId(Id); policyItemAccess.setUpdateTime(new Date()); policyItemAccessList.add(policyItemAccess); List<XXPolicyResource> policyResourceList = new ArrayList<XXPolicyResource>(); XXPolicyResource policyResource = new XXPolicyResource(); policyResource.setId(Id); policyResource.setCreateTime(new Date()); policyResource.setAddedByUserId(Id); policyResource.setIsExcludes(false); policyResource.setIsRecursive(false); policyResource.setPolicyId(Id); policyResource.setResDefId(Id); policyResource.setUpdatedByUserId(Id); policyResource.setUpdateTime(new Date()); policyResourceList.add(policyResource); XXPolicyResourceMap policyResourceMap = new XXPolicyResourceMap(); policyResourceMap.setAddedByUserId(Id); policyResourceMap.setCreateTime(new Date()); policyResourceMap.setId(Id); policyResourceMap.setOrder(1); policyResourceMap.setResourceId(Id); policyResourceMap.setUpdatedByUserId(Id); policyResourceMap.setUpdateTime(new Date()); policyResourceMap.setValue("1L"); List<XXServiceConfigDef> xServiceConfigDefList = new ArrayList<XXServiceConfigDef>(); XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef(); serviceConfigDefObj.setId(Id); xServiceConfigDefList.add(serviceConfigDefObj); Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.findByName(name)).thenReturn(xService); Mockito.when(svcService.getPopulatedViewObject(xService)).thenReturn( rangerService); Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.getById(Id)).thenReturn(xService); Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.getById(rangerService.getId())).thenReturn( xService); Mockito.when(daoManager.getXXPolicyLabelMap()).thenReturn(xPolicyLabelMapDao); Mockito.when(xPolicyLabelMapDao.findByPolicyId(rangerPolicy.getId())).thenReturn(ListUtils.EMPTY_LIST); Mockito.when(!bizUtil.hasAccess(xService, null)).thenReturn(true); Mockito.when(policyRefUpdater.cleanupRefTables(rangerPolicy)).thenReturn(true); serviceDBStore.deletePolicy(rangerPolicy); }
@Override public void deletePolicy(RangerPolicy policy) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.deletePolicy(" + policy + ")"); } if(policy == null) { throw new Exception("No such policy exists"); } String policyName = policy.getName(); RangerService service = getServiceByName(policy.getService()); if(service == null) { throw new Exception("service does not exist - name='" + policy.getService()); } Long version = policy.getVersion(); if(version == null) { version = Long.valueOf(1); LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null."); } else { version = Long.valueOf(version.longValue() + 1); } policy.setVersion(version); List<XXTrxLog> trxLogList = getTransactionLogList(policy, RangerPolicyService.OPERATION_IMPORT_DELETE_CONTEXT, RangerPolicyService.OPERATION_DELETE_CONTEXT); policyRefUpdater.cleanupRefTables(policy); deleteExistingPolicyLabel(policy); policyService.delete(policy); handlePolicyUpdate(service, RangerPolicyDelta.CHANGE_TYPE_POLICY_DELETE, policy, false); dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE); bizUtil.createTrxLog(trxLogList); LOG.info("Policy Deleted Successfully. PolicyName : " + policyName); }
ServiceDBStore extends AbstractServiceStore { @Override public void deletePolicy(RangerPolicy policy) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.deletePolicy(" + policy + ")"); } if(policy == null) { throw new Exception("No such policy exists"); } String policyName = policy.getName(); RangerService service = getServiceByName(policy.getService()); if(service == null) { throw new Exception("service does not exist - name='" + policy.getService()); } Long version = policy.getVersion(); if(version == null) { version = Long.valueOf(1); LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null."); } else { version = Long.valueOf(version.longValue() + 1); } policy.setVersion(version); List<XXTrxLog> trxLogList = getTransactionLogList(policy, RangerPolicyService.OPERATION_IMPORT_DELETE_CONTEXT, RangerPolicyService.OPERATION_DELETE_CONTEXT); policyRefUpdater.cleanupRefTables(policy); deleteExistingPolicyLabel(policy); policyService.delete(policy); handlePolicyUpdate(service, RangerPolicyDelta.CHANGE_TYPE_POLICY_DELETE, policy, false); dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE); bizUtil.createTrxLog(trxLogList); LOG.info("Policy Deleted Successfully. PolicyName : " + policyName); } }
ServiceDBStore extends AbstractServiceStore { @Override public void deletePolicy(RangerPolicy policy) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.deletePolicy(" + policy + ")"); } if(policy == null) { throw new Exception("No such policy exists"); } String policyName = policy.getName(); RangerService service = getServiceByName(policy.getService()); if(service == null) { throw new Exception("service does not exist - name='" + policy.getService()); } Long version = policy.getVersion(); if(version == null) { version = Long.valueOf(1); LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null."); } else { version = Long.valueOf(version.longValue() + 1); } policy.setVersion(version); List<XXTrxLog> trxLogList = getTransactionLogList(policy, RangerPolicyService.OPERATION_IMPORT_DELETE_CONTEXT, RangerPolicyService.OPERATION_DELETE_CONTEXT); policyRefUpdater.cleanupRefTables(policy); deleteExistingPolicyLabel(policy); policyService.delete(policy); handlePolicyUpdate(service, RangerPolicyDelta.CHANGE_TYPE_POLICY_DELETE, policy, false); dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE); bizUtil.createTrxLog(trxLogList); LOG.info("Policy Deleted Successfully. PolicyName : " + policyName); }  }
ServiceDBStore extends AbstractServiceStore { @Override public void deletePolicy(RangerPolicy policy) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.deletePolicy(" + policy + ")"); } if(policy == null) { throw new Exception("No such policy exists"); } String policyName = policy.getName(); RangerService service = getServiceByName(policy.getService()); if(service == null) { throw new Exception("service does not exist - name='" + policy.getService()); } Long version = policy.getVersion(); if(version == null) { version = Long.valueOf(1); LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null."); } else { version = Long.valueOf(version.longValue() + 1); } policy.setVersion(version); List<XXTrxLog> trxLogList = getTransactionLogList(policy, RangerPolicyService.OPERATION_IMPORT_DELETE_CONTEXT, RangerPolicyService.OPERATION_DELETE_CONTEXT); policyRefUpdater.cleanupRefTables(policy); deleteExistingPolicyLabel(policy); policyService.delete(policy); handlePolicyUpdate(service, RangerPolicyDelta.CHANGE_TYPE_POLICY_DELETE, policy, false); dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE); bizUtil.createTrxLog(trxLogList); LOG.info("Policy Deleted Successfully. PolicyName : " + policyName); }  @Override void init(); @PostConstruct void initStore(); @Override RangerServiceDef createServiceDef(RangerServiceDef serviceDef); @Override RangerServiceDef updateServiceDef(RangerServiceDef serviceDef); void deleteServiceDef(Long serviceDefId, Boolean forceDelete); void deleteXXAccessTypeDef(XXAccessTypeDef xAccess); void deleteXXResourceDef(XXResourceDef xRes); @Override RangerServiceDef getServiceDef(Long id); @Override RangerServiceDef getServiceDefByName(String name); @Override RangerServiceDef getServiceDefByDisplayName(String displayName); @Override List<RangerServiceDef> getServiceDefs(SearchFilter filter); @Override PList<RangerServiceDef> getPaginatedServiceDefs(SearchFilter filter); @Override RangerService createService(RangerService service); @Override RangerService updateService(RangerService service, Map<String, Object> options); @Override void deleteService(Long id); @Override List<RangerPolicy> getPoliciesByResourceSignature(String serviceName, String policySignature, Boolean isPolicyEnabled); @Override RangerService getService(Long id); @Override RangerService getServiceByName(String name); @Override RangerService getServiceByDisplayName(String displayName); RangerService getServiceByNameForDP(String name); @Override List<RangerService> getServices(SearchFilter filter); PList<RangerService> getPaginatedServices(SearchFilter filter); @Override RangerPolicy createPolicy(RangerPolicy policy); void createOrMapLabels(XXPolicy xPolicy, Set<String> uniquePolicyLabels); @Override RangerPolicy updatePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy, RangerService service); @Override boolean policyExists(Long id); @Override RangerPolicy getPolicy(Long id); @Override List<RangerPolicy> getPolicies(SearchFilter filter); @Override Long getPolicyId(final Long serviceId, final String policyName, final Long zoneId); void getPoliciesInExcel(List<RangerPolicy> policies, HttpServletResponse response); void getPoliciesInCSV(List<RangerPolicy> policies,
			HttpServletResponse response); void getPoliciesInJson(List<RangerPolicy> policies,
			HttpServletResponse response); PList<RangerPolicy> getPaginatedPolicies(SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(Long serviceId, SearchFilter filter); List<RangerPolicy> noZoneFilter(List<RangerPolicy> servicePolicies); PList<RangerPolicy> getPaginatedServicePolicies(Long serviceId, SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(String serviceName, SearchFilter filter); PList<RangerPolicy> getPaginatedServicePolicies(String serviceName, SearchFilter filter); @Override ServicePolicies getServicePoliciesIfUpdated(String serviceName, Long lastKnownVersion, boolean needsBackwardCompatibility); @Override Long getServicePolicyVersion(String serviceName); @Override ServicePolicies getServicePolicyDeltasOrPolicies(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicyDeltas(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicies(String serviceName, Long lastKnownVersion); void createZoneDefaultPolicies(Collection<String> serviceNames, RangerSecurityZone zone); void deleteZonePolicies(Collection<String> serviceNames, Long zoneId); static void persistVersionChange(ServiceVersionUpdater serviceVersionUpdater); @Override Boolean getPopulateExistingBaseFields(); @Override void setPopulateExistingBaseFields(Boolean populateExistingBaseFields); RangerPolicy getPolicyFromEventTime(String eventTime, Long policyId); VXString getPolicyVersionList(Long policyId); RangerPolicy getPolicyForVersionNumber(Long policyId, int versionNo); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZone(String name); @Override long getPoliciesCount(final String serviceName); void putMetaDataInfo(RangerExportPolicyList rangerExportPolicyList); Map<String, String> getMapFromInputStream(InputStream mapStream); Map<String, RangerPolicy> setPolicyMapKeyValue(Map<String, RangerPolicy> policiesMap, RangerPolicy policy); Map<String, RangerPolicy> createPolicyMap(Map<String, String> zoneMappingMap, List<String> sourceZones,
			String destinationZoneName, Map<String, String> servicesMappingMap, List<String> sourceServices,
			List<String> destinationServices, RangerPolicy policy, Map<String, RangerPolicy> policiesMap); void getServiceUpgraded(); void resetPolicyUpdateLog(int retentionInDays, Integer policyChangeType); void resetTagUpdateLog(int retentionInDays, ServiceTags.TagsChangeType tagChangeType); List<String> getPolicyLabels(SearchFilter searchFilter); String getMetricByType(String type); boolean isServiceAdminUser(String serviceName, String userName); static boolean isSupportsPolicyDeltas(); static boolean isSupportsRolesDownloadByService(); @Override Map<String, String> getServiceConfigForPlugin(Long serviceId); }
ServiceDBStore extends AbstractServiceStore { @Override public void deletePolicy(RangerPolicy policy) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("==> ServiceDBStore.deletePolicy(" + policy + ")"); } if(policy == null) { throw new Exception("No such policy exists"); } String policyName = policy.getName(); RangerService service = getServiceByName(policy.getService()); if(service == null) { throw new Exception("service does not exist - name='" + policy.getService()); } Long version = policy.getVersion(); if(version == null) { version = Long.valueOf(1); LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null."); } else { version = Long.valueOf(version.longValue() + 1); } policy.setVersion(version); List<XXTrxLog> trxLogList = getTransactionLogList(policy, RangerPolicyService.OPERATION_IMPORT_DELETE_CONTEXT, RangerPolicyService.OPERATION_DELETE_CONTEXT); policyRefUpdater.cleanupRefTables(policy); deleteExistingPolicyLabel(policy); policyService.delete(policy); handlePolicyUpdate(service, RangerPolicyDelta.CHANGE_TYPE_POLICY_DELETE, policy, false); dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE); bizUtil.createTrxLog(trxLogList); LOG.info("Policy Deleted Successfully. PolicyName : " + policyName); }  @Override void init(); @PostConstruct void initStore(); @Override RangerServiceDef createServiceDef(RangerServiceDef serviceDef); @Override RangerServiceDef updateServiceDef(RangerServiceDef serviceDef); void deleteServiceDef(Long serviceDefId, Boolean forceDelete); void deleteXXAccessTypeDef(XXAccessTypeDef xAccess); void deleteXXResourceDef(XXResourceDef xRes); @Override RangerServiceDef getServiceDef(Long id); @Override RangerServiceDef getServiceDefByName(String name); @Override RangerServiceDef getServiceDefByDisplayName(String displayName); @Override List<RangerServiceDef> getServiceDefs(SearchFilter filter); @Override PList<RangerServiceDef> getPaginatedServiceDefs(SearchFilter filter); @Override RangerService createService(RangerService service); @Override RangerService updateService(RangerService service, Map<String, Object> options); @Override void deleteService(Long id); @Override List<RangerPolicy> getPoliciesByResourceSignature(String serviceName, String policySignature, Boolean isPolicyEnabled); @Override RangerService getService(Long id); @Override RangerService getServiceByName(String name); @Override RangerService getServiceByDisplayName(String displayName); RangerService getServiceByNameForDP(String name); @Override List<RangerService> getServices(SearchFilter filter); PList<RangerService> getPaginatedServices(SearchFilter filter); @Override RangerPolicy createPolicy(RangerPolicy policy); void createOrMapLabels(XXPolicy xPolicy, Set<String> uniquePolicyLabels); @Override RangerPolicy updatePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy); @Override void deletePolicy(RangerPolicy policy, RangerService service); @Override boolean policyExists(Long id); @Override RangerPolicy getPolicy(Long id); @Override List<RangerPolicy> getPolicies(SearchFilter filter); @Override Long getPolicyId(final Long serviceId, final String policyName, final Long zoneId); void getPoliciesInExcel(List<RangerPolicy> policies, HttpServletResponse response); void getPoliciesInCSV(List<RangerPolicy> policies,
			HttpServletResponse response); void getPoliciesInJson(List<RangerPolicy> policies,
			HttpServletResponse response); PList<RangerPolicy> getPaginatedPolicies(SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(Long serviceId, SearchFilter filter); List<RangerPolicy> noZoneFilter(List<RangerPolicy> servicePolicies); PList<RangerPolicy> getPaginatedServicePolicies(Long serviceId, SearchFilter filter); @Override List<RangerPolicy> getServicePolicies(String serviceName, SearchFilter filter); PList<RangerPolicy> getPaginatedServicePolicies(String serviceName, SearchFilter filter); @Override ServicePolicies getServicePoliciesIfUpdated(String serviceName, Long lastKnownVersion, boolean needsBackwardCompatibility); @Override Long getServicePolicyVersion(String serviceName); @Override ServicePolicies getServicePolicyDeltasOrPolicies(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicyDeltas(String serviceName, Long lastKnownVersion); @Override ServicePolicies getServicePolicies(String serviceName, Long lastKnownVersion); void createZoneDefaultPolicies(Collection<String> serviceNames, RangerSecurityZone zone); void deleteZonePolicies(Collection<String> serviceNames, Long zoneId); static void persistVersionChange(ServiceVersionUpdater serviceVersionUpdater); @Override Boolean getPopulateExistingBaseFields(); @Override void setPopulateExistingBaseFields(Boolean populateExistingBaseFields); RangerPolicy getPolicyFromEventTime(String eventTime, Long policyId); VXString getPolicyVersionList(Long policyId); RangerPolicy getPolicyForVersionNumber(Long policyId, int versionNo); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZone(String name); @Override long getPoliciesCount(final String serviceName); void putMetaDataInfo(RangerExportPolicyList rangerExportPolicyList); Map<String, String> getMapFromInputStream(InputStream mapStream); Map<String, RangerPolicy> setPolicyMapKeyValue(Map<String, RangerPolicy> policiesMap, RangerPolicy policy); Map<String, RangerPolicy> createPolicyMap(Map<String, String> zoneMappingMap, List<String> sourceZones,
			String destinationZoneName, Map<String, String> servicesMappingMap, List<String> sourceServices,
			List<String> destinationServices, RangerPolicy policy, Map<String, RangerPolicy> policiesMap); void getServiceUpgraded(); void resetPolicyUpdateLog(int retentionInDays, Integer policyChangeType); void resetTagUpdateLog(int retentionInDays, ServiceTags.TagsChangeType tagChangeType); List<String> getPolicyLabels(SearchFilter searchFilter); String getMetricByType(String type); boolean isServiceAdminUser(String serviceName, String userName); static boolean isSupportsPolicyDeltas(); static boolean isSupportsRolesDownloadByService(); @Override Map<String, String> getServiceConfigForPlugin(Long serviceId); static final String SERVICE_ADMIN_USERS; static final String CRYPT_ALGO; static final String ENCRYPT_KEY; static final String SALT; static final Integer ITERATION_COUNT; static boolean SUPPORTS_POLICY_DELTAS; static Integer RETENTION_PERIOD_IN_DAYS; static Integer TAG_RETENTION_PERIOD_IN_DAYS; static final String HIDDEN_PASSWORD_STR; static final String CONFIG_KEY_PASSWORD; static final String ACCESS_TYPE_DECRYPT_EEK; static final String ACCESS_TYPE_GENERATE_EEK; static final String ACCESS_TYPE_GET_METADATA; }