Java Code Examples for org.apache.ranger.plugin.model.RangerServiceDef#RangerDataMaskTypeDef

The following examples show how to use org.apache.ranger.plugin.model.RangerServiceDef#RangerDataMaskTypeDef . 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: RangerGaianAuthorizer.java    From egeria with Apache License 2.0 5 votes vote down vote up
private String getTransformer(RangerAccessResult result) {
    RangerServiceDef.RangerDataMaskTypeDef maskTypeDef = result.getMaskTypeDef();

    if (maskTypeDef != null) {
        return maskTypeDef.getTransformer();
    }

    return null;
}
 
Example 2
Source File: RangerAccessResult.java    From ranger with Apache License 2.0 5 votes vote down vote up
public RangerServiceDef.RangerDataMaskTypeDef getMaskTypeDef() {
	RangerServiceDef.RangerDataMaskTypeDef ret = null;

	String maskType = getMaskType();
	if(StringUtils.isNotEmpty(maskType)) {
		ret = ServiceDefUtil.getDataMaskType(getServiceDef(), maskType);
	}

	return ret;
}
 
Example 3
Source File: AbstractServiceStore.java    From ranger with Apache License 2.0 5 votes vote down vote up
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: RangerSystemAccessControl.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<ViewExpression> getColumnMask(SystemSecurityContext context, CatalogSchemaTableName tableName, String columnName, Type type) {
  RangerPrestoAccessRequest request = createAccessRequest(
    createResource(tableName.getCatalogName(), tableName.getSchemaTableName().getSchemaName(),
      tableName.getSchemaTableName().getTableName(), Optional.of(columnName)),
    context, PrestoAccessType.SELECT);
  RangerAccessResult result = getDataMaskResult(request);

  ViewExpression viewExpression = null;
  if (isDataMaskEnabled(result)) {
    String                maskType    = result.getMaskType();
    RangerServiceDef.RangerDataMaskTypeDef maskTypeDef = result.getMaskTypeDef();
    String transformer	= null;

    if (maskTypeDef != null) {
      transformer = maskTypeDef.getTransformer();
    }

    if(StringUtils.equalsIgnoreCase(maskType, RangerPolicy.MASK_TYPE_NULL)) {
      transformer = "NULL";
    } else if(StringUtils.equalsIgnoreCase(maskType, RangerPolicy.MASK_TYPE_CUSTOM)) {
      String maskedValue = result.getMaskedValue();

      if(maskedValue == null) {
        transformer = "NULL";
      } else {
        transformer = maskedValue;
      }
    }

    if(StringUtils.isNotEmpty(transformer)) {
      transformer = transformer.replace("{col}", columnName).replace("{type}", type.getDisplayName());
    }

    viewExpression = new ViewExpression(
      context.getIdentity().getUser(),
      Optional.of(tableName.getCatalogName()),
      Optional.of(tableName.getSchemaTableName().getSchemaName()),
      transformer
    );
    if (LOG.isDebugEnabled()) {
      LOG.debug("getColumnMask: user: %s, catalog: %s, schema: %s, transformer: %s");
    }

  }

  return Optional.ofNullable(viewExpression);
}