Java Code Examples for org.apache.ranger.plugin.model.RangerServiceDef#getDataMaskDef()
The following examples show how to use
org.apache.ranger.plugin.model.RangerServiceDef#getDataMaskDef() .
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: RangerServiceDefHelper.java From ranger with Apache License 2.0 | 6 votes |
List<RangerResourceDef> getResourceDefs(RangerServiceDef serviceDef, Integer policyType) { final List<RangerResourceDef> resourceDefs; if(policyType == null || policyType == RangerPolicy.POLICY_TYPE_ACCESS) { resourceDefs = serviceDef.getResources(); } else if(policyType == RangerPolicy.POLICY_TYPE_DATAMASK) { if(serviceDef.getDataMaskDef() != null) { resourceDefs = serviceDef.getDataMaskDef().getResources(); } else { resourceDefs = null; } } else if(policyType == RangerPolicy.POLICY_TYPE_ROWFILTER) { if(serviceDef.getRowFilterDef() != null) { resourceDefs = serviceDef.getRowFilterDef().getResources(); } else { resourceDefs = null; } } else { // unknown policyType; use all resources resourceDefs = serviceDef.getResources(); } return resourceDefs; }
Example 2
Source File: ServiceDefUtil.java From ranger with Apache License 2.0 | 6 votes |
public static RangerDataMaskTypeDef getDataMaskType(RangerServiceDef serviceDef, String typeName) { RangerDataMaskTypeDef ret = null; if(serviceDef != null && serviceDef.getDataMaskDef() != null) { List<RangerDataMaskTypeDef> maskTypes = serviceDef.getDataMaskDef().getMaskTypes(); if(CollectionUtils.isNotEmpty(maskTypes)) { for(RangerDataMaskTypeDef maskType : maskTypes) { if(StringUtils.equals(maskType.getName(), typeName)) { ret = maskType; break; } } } } return ret; }
Example 3
Source File: AbstractServiceStore.java From ranger with Apache License 2.0 | 5 votes |
private void updateTagServiceDefForDeletingDataMaskDef(RangerServiceDef tagServiceDef, String serviceDefName) { if (LOG.isDebugEnabled()) { LOG.debug("==> AbstractServiceStore.updateTagServiceDefForDeletingDataMaskDef(" + serviceDefName + ")"); } RangerServiceDef.RangerDataMaskDef tagDataMaskDef = tagServiceDef.getDataMaskDef(); if (tagDataMaskDef == null) { return; } String prefix = serviceDefName + COMPONENT_ACCESSTYPE_SEPARATOR; List<RangerServiceDef.RangerAccessTypeDef> accessTypes = new ArrayList<>(); for (RangerServiceDef.RangerAccessTypeDef accessType : tagDataMaskDef.getAccessTypes()) { if (accessType.getName().startsWith(prefix)) { accessTypes.add(accessType); } } List<RangerServiceDef.RangerDataMaskTypeDef> maskTypes = new ArrayList<>(); for (RangerServiceDef.RangerDataMaskTypeDef maskType : tagDataMaskDef.getMaskTypes()) { if (maskType.getName().startsWith(prefix)) { maskTypes.add(maskType); } } tagDataMaskDef.getAccessTypes().removeAll(accessTypes); tagDataMaskDef.getMaskTypes().removeAll(maskTypes); if (LOG.isDebugEnabled()) { LOG.debug("<== AbstractServiceStore.updateTagServiceDefForDeletingDataMaskDef(" + serviceDefName + ")"); } }
Example 4
Source File: PatchForTagServiceDefUpdate_J10028.java From ranger with Apache License 2.0 | 4 votes |
private boolean updateResourceInTagServiceDef(RangerServiceDef tagServiceDef) { if (logger.isDebugEnabled()) { logger.debug("==> PatchForTagServiceDefUpdate_J10028.updateResourceInTagServiceDef(" + tagServiceDef + ")"); } boolean ret = false; final RangerServiceDef.RangerResourceDef accessPolicyTagResource = getResourceDefForTagResource(tagServiceDef.getResources()); if (accessPolicyTagResource != null) { RangerServiceDef.RangerDataMaskDef dataMaskDef = tagServiceDef.getDataMaskDef(); if (dataMaskDef != null) { if (CollectionUtils.isNotEmpty(dataMaskDef.getAccessTypes())) { addOrUpdateResourceDefForTagResource(dataMaskDef.getResources(), accessPolicyTagResource); ret = true; } else { if (CollectionUtils.isNotEmpty(dataMaskDef.getResources())) { dataMaskDef.setResources(null); ret = true; } } } RangerServiceDef.RangerRowFilterDef rowFilterDef = tagServiceDef.getRowFilterDef(); if (rowFilterDef != null) { boolean autopropagateRowfilterdefToTag = config.getBoolean(AbstractServiceStore.AUTOPROPAGATE_ROWFILTERDEF_TO_TAG_PROP, AbstractServiceStore.AUTOPROPAGATE_ROWFILTERDEF_TO_TAG_PROP_DEFAULT); if (autopropagateRowfilterdefToTag) { if (CollectionUtils.isNotEmpty(rowFilterDef.getAccessTypes())) { addOrUpdateResourceDefForTagResource(rowFilterDef.getResources(), accessPolicyTagResource); ret = true; } else { if (CollectionUtils.isNotEmpty(rowFilterDef.getResources())) { rowFilterDef.setResources(null); ret = true; } } } } } else { logger.warn("Resource with name :[" + RangerServiceTag.TAG_RESOURCE_NAME + "] not found in tag-service-definition!!"); } if (logger.isDebugEnabled()) { logger.debug("<== PatchForTagServiceDefUpdate_J10028.updateResourceInTagServiceDef(" + tagServiceDef + ") : " + ret); } return ret; }
Example 5
Source File: PatchForHiveServiceDefUpdate_J10006.java From ranger with Apache License 2.0 | 4 votes |
private void updateHiveServiceDef(){ RangerServiceDef ret = null; RangerServiceDef embeddedHiveServiceDef = null; RangerServiceDef dbHiveServiceDef = null; RangerDataMaskDef dataMaskDef = null; RangerRowFilterDef rowFilterDef = null; XXServiceDef xXServiceDefObj = null; try{ embeddedHiveServiceDef=EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME); if(embeddedHiveServiceDef!=null){ xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME); Map<String, String> serviceDefOptionsPreUpdate=null; String jsonStrPreUpdate=null; if(xXServiceDefObj!=null) { jsonStrPreUpdate=xXServiceDefObj.getDefOptions(); serviceDefOptionsPreUpdate=jsonStringToMap(jsonStrPreUpdate); xXServiceDefObj=null; } dataMaskDef= embeddedHiveServiceDef.getDataMaskDef(); rowFilterDef= embeddedHiveServiceDef.getRowFilterDef(); dbHiveServiceDef=svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME); if(dbHiveServiceDef!=null){ if(dataMaskDef!=null){ dbHiveServiceDef.setDataMaskDef(dataMaskDef); } if(rowFilterDef!=null){ dbHiveServiceDef.setRowFilterDef(rowFilterDef); } RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore); validator.validate(dbHiveServiceDef, Action.UPDATE); ret = svcStore.updateServiceDef(dbHiveServiceDef); if(ret==null){ logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME+"service-def"); System.exit(1); } xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME); if(xXServiceDefObj!=null) { String jsonStrPostUpdate=xXServiceDefObj.getDefOptions(); Map<String, String> serviceDefOptionsPostUpdate=jsonStringToMap(jsonStrPostUpdate); if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) { if(serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) { String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES); if (preUpdateValue == null) { serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES); } else { serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue); } xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate)); daoMgr.getXXServiceDef().update(xXServiceDefObj); } } } } } }catch(Exception e) { logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME+"service-def", e); } }
Example 6
Source File: AbstractServiceStore.java From ranger with Apache License 2.0 | 4 votes |
private boolean updateResourceInTagServiceDef(RangerServiceDef tagServiceDef) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> AbstractServiceStore.updateResourceInTagServiceDef(" + tagServiceDef + ")"); } boolean ret = false; final RangerServiceDef.RangerResourceDef accessPolicyTagResource = getResourceDefForTagResource(tagServiceDef.getResources()); final List<RangerServiceDef.RangerResourceDef> resources = new ArrayList<>(); if (accessPolicyTagResource == null) { LOG.warn("Resource with name :[" + RangerServiceTag.TAG_RESOURCE_NAME + "] not found in tag-service-definition!!"); } else { resources.add(accessPolicyTagResource); } RangerServiceDef.RangerDataMaskDef dataMaskDef = tagServiceDef.getDataMaskDef(); if (dataMaskDef != null) { if (CollectionUtils.isNotEmpty(dataMaskDef.getAccessTypes())) { if (CollectionUtils.isEmpty(dataMaskDef.getResources())) { dataMaskDef.setResources(resources); ret = true; } } else { if (CollectionUtils.isNotEmpty(dataMaskDef.getResources())) { dataMaskDef.setResources(null); ret = true; } } } RangerServiceDef.RangerRowFilterDef rowFilterDef = tagServiceDef.getRowFilterDef(); if (rowFilterDef != null) { boolean autopropagateRowfilterdefToTag = config.getBoolean(AUTOPROPAGATE_ROWFILTERDEF_TO_TAG_PROP, AUTOPROPAGATE_ROWFILTERDEF_TO_TAG_PROP_DEFAULT); if (autopropagateRowfilterdefToTag) { if (CollectionUtils.isNotEmpty(rowFilterDef.getAccessTypes())) { if (CollectionUtils.isEmpty(rowFilterDef.getResources())) { rowFilterDef.setResources(resources); ret = true; } } else { if (CollectionUtils.isNotEmpty(rowFilterDef.getResources())) { rowFilterDef.setResources(null); ret = true; } } } } if (LOG.isDebugEnabled()) { LOG.debug("<== AbstractServiceStore.updateResourceInTagServiceDef(" + tagServiceDef + ") : " + ret); } return ret; }