Search in sources :

Example 36 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class AtlasHbaseResourceMapper method buildResource.

@Override
public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception {
    String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME);
    if (StringUtils.isEmpty(qualifiedName)) {
        throw new Exception("attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity");
    }
    String resourceStr = getResourceNameFromQualifiedName(qualifiedName);
    if (StringUtils.isEmpty(resourceStr)) {
        throwExceptionWithMessage("resource not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName);
    }
    String clusterName = getClusterNameFromQualifiedName(qualifiedName);
    if (StringUtils.isEmpty(clusterName)) {
        throwExceptionWithMessage("cluster-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName);
    }
    String entityType = entity.getTypeName();
    String entityGuid = entity.getGuid();
    String serviceName = getRangerServiceName(clusterName);
    Map<String, RangerPolicyResource> elements = new HashMap<String, RangerPolicyResource>();
    if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_NAMESPACE)) {
        if (StringUtils.isNotEmpty(resourceStr)) {
            String namespaceName = StringUtils.strip(resourceStr);
            if (StringUtils.isNotEmpty(namespaceName)) {
                elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(namespaceName + RANGER_NAMESPACE_TABLE_DELIMITER + "*"));
            }
        }
    } else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_TABLE)) {
        if (StringUtils.isNotEmpty(resourceStr)) {
            elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(resourceStr));
        }
    } else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_COLUMN_FAMILY)) {
        String[] resources = resourceStr.split(QUALIFIED_NAME_DELIMITER);
        String tblName = null;
        String familyName = null;
        if (resources.length == 2) {
            tblName = resources[0];
            familyName = resources[1];
        } else if (resources.length > 2) {
            StringBuilder tblNameBuf = new StringBuilder(resources[0]);
            for (int i = 1; i < resources.length - 1; i++) {
                tblNameBuf.append(QUALIFIED_NAME_DELIMITER_CHAR).append(resources[i]);
            }
            tblName = tblNameBuf.toString();
            familyName = resources[resources.length - 1];
        }
        if (StringUtils.isNotEmpty(tblName) && StringUtils.isNotEmpty(familyName)) {
            elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(tblName));
            elements.put(RANGER_TYPE_HBASE_COLUMN_FAMILY, new RangerPolicyResource(familyName));
        }
    } else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_COLUMN)) {
        String[] resources = resourceStr.split(QUALIFIED_NAME_DELIMITER);
        String tblName = null;
        String familyName = null;
        String colName = null;
        if (resources.length == 3) {
            tblName = resources[0];
            familyName = resources[1];
            colName = resources[2];
        } else if (resources.length > 3) {
            StringBuilder tblNameBuf = new StringBuilder(resources[0]);
            for (int i = 1; i < resources.length - 2; i++) {
                tblNameBuf.append(QUALIFIED_NAME_DELIMITER_CHAR).append(resources[i]);
            }
            tblName = tblNameBuf.toString();
            familyName = resources[resources.length - 2];
            colName = resources[resources.length - 1];
        }
        if (StringUtils.isNotEmpty(tblName) && StringUtils.isNotEmpty(familyName) && StringUtils.isNotEmpty(colName)) {
            elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(tblName));
            elements.put(RANGER_TYPE_HBASE_COLUMN_FAMILY, new RangerPolicyResource(familyName));
            elements.put(RANGER_TYPE_HBASE_COLUMN, new RangerPolicyResource(colName));
        }
    } else {
        throwExceptionWithMessage("unrecognized entity-type: " + entityType);
    }
    if (elements.isEmpty()) {
        throwExceptionWithMessage("invalid qualifiedName for entity-type '" + entityType + "': " + qualifiedName);
    }
    return new RangerServiceResource(entityGuid, serviceName, elements);
}
Also used : HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)

Example 37 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class AtlasNotificationMapper method buildServiceTagsForEntityDeleteNotification.

@SuppressWarnings("unchecked")
private static ServiceTags buildServiceTagsForEntityDeleteNotification(RangerAtlasEntityWithTags entityWithTags) {
    final ServiceTags ret;
    RangerAtlasEntity entity = entityWithTags.getEntity();
    String guid = entity.getGuid();
    if (StringUtils.isNotBlank(guid)) {
        ret = new ServiceTags();
        RangerServiceResource serviceResource = new RangerServiceResource();
        serviceResource.setGuid(guid);
        ret.getServiceResources().add(serviceResource);
    } else {
        ret = buildServiceTags(entityWithTags, null);
        if (ret != null) {
            // tag-definitions should NOT be deleted as part of service-resource delete
            ret.setTagDefinitions(MapUtils.EMPTY_MAP);
            // Ranger deletes tags associated with deleted service-resource
            ret.setTags(MapUtils.EMPTY_MAP);
        }
    }
    if (ret != null) {
        ret.setOp(ServiceTags.OP_DELETE);
    }
    return ret;
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ServiceTags(org.apache.ranger.plugin.util.ServiceTags)

Example 38 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class AtlasResourceMapperUtil method getRangerServiceResource.

public static RangerServiceResource getRangerServiceResource(RangerAtlasEntity atlasEntity) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getRangerServiceResource(" + atlasEntity.getGuid() + ")");
    }
    RangerServiceResource resource = null;
    AtlasResourceMapper mapper = atlasResourceMappers.get(atlasEntity.getTypeName());
    if (mapper != null) {
        try {
            resource = mapper.buildResource(atlasEntity);
        } catch (Exception exception) {
            LOG.error("Could not get serviceResource for atlas entity:" + atlasEntity.getGuid() + ": ", exception);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getRangerServiceResource(" + atlasEntity.getGuid() + "): resource=" + resource);
    }
    return resource;
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource)

Example 39 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class AtlasStormResourceMapper method buildResource.

@Override
public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception {
    String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME);
    String topology = getResourceNameFromQualifiedName(qualifiedName);
    if (StringUtils.isEmpty(topology)) {
        throwExceptionWithMessage("topology not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "'");
    }
    String clusterName = getClusterNameFromQualifiedName(qualifiedName);
    if (StringUtils.isEmpty(clusterName)) {
        clusterName = defaultClusterName;
    }
    if (StringUtils.isEmpty(clusterName)) {
        throwExceptionWithMessage("attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity");
    }
    Map<String, RangerPolicyResource> elements = new HashMap<>();
    Boolean isExcludes = Boolean.FALSE;
    Boolean isRecursive = Boolean.TRUE;
    elements.put(RANGER_TYPE_STORM_TOPOLOGY, new RangerPolicyResource(topology, isExcludes, isRecursive));
    String entityGuid = entity.getGuid();
    String serviceName = getRangerServiceName(clusterName);
    return new RangerServiceResource(entityGuid, serviceName, elements);
}
Also used : HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)

Example 40 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class TestHbaseResourceMapper method testHbaseDottedColumn.

@Test
public void testHbaseDottedColumn() throws Exception {
    Map<String, Object> entAttribs = new HashMap<String, Object>();
    entAttribs.put(ENTITY_ATTRIBUTE_QUALIFIED_NAME, DOTTED_COLUMN_QUALIFIED_NAME);
    RangerAtlasEntity entity = getHbaseColumnEntity(entAttribs);
    RangerServiceResource resource = resourceMapper.buildResource(entity);
    assertColumnResource(resource, true);
}
Also used : RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) HashMap(java.util.HashMap) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) Test(org.junit.Test)

Aggregations

RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)65 Test (org.junit.Test)42 HashMap (java.util.HashMap)37 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)30 WebApplicationException (javax.ws.rs.WebApplicationException)17 ExpectedException (org.junit.rules.ExpectedException)14 ArrayList (java.util.ArrayList)10 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)7 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)5 Predicate (org.apache.commons.collections.Predicate)4 XXServiceResource (org.apache.ranger.entity.XXServiceResource)4 RangerTag (org.apache.ranger.plugin.model.RangerTag)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 PUT (javax.ws.rs.PUT)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2