Search in sources :

Example 1 with AtlasEntityAccessRequest

use of org.apache.atlas.authorize.AtlasEntityAccessRequest in project atlas by apache.

the class AtlasEntityStoreV1 method getByUniqueAttributes.

@Override
@GraphTransaction
public AtlasEntityWithExtInfo getByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getByUniqueAttribute({}, {})", entityType.getTypeName(), uniqAttributes);
    }
    AtlasVertex entityVertex = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes);
    AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(entityVertex);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getByUniqueAttribute({}, {}): {}", entityType.getTypeName(), uniqAttributes, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 2 with AtlasEntityAccessRequest

use of org.apache.atlas.authorize.AtlasEntityAccessRequest in project atlas by apache.

the class AtlasEntityStoreV1 method getById.

@Override
@GraphTransaction
public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getById({})", guid);
    }
    AtlasEntityWithExtInfo ret = entityRetriever.toAtlasEntityWithExtInfo(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(ret.getEntity())), "read entity: guid=", guid);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getById({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 3 with AtlasEntityAccessRequest

use of org.apache.atlas.authorize.AtlasEntityAccessRequest in project atlas by apache.

the class AtlasEntityStoreV1 method addClassifications.

@Override
@GraphTransaction
public void addClassifications(final String guid, final List<AtlasClassification> classifications) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding classifications={} to entity={}", classifications, guid);
    }
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    for (AtlasClassification classification : classifications) {
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_ADD_CLASSIFICATION, entityHeader, classification), "add classification: guid=", guid, ", classification=", classification.getTypeName());
    }
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    for (AtlasClassification classification : classifications) {
        validateAndNormalize(classification);
    }
    // validate if entity, not already associated with classifications
    validateEntityAssociations(guid, classifications);
    entityGraphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 4 with AtlasEntityAccessRequest

use of org.apache.atlas.authorize.AtlasEntityAccessRequest in project atlas by apache.

the class AtlasEntityStoreV1 method deleteByIds.

@Override
@GraphTransaction
public EntityMutationResponse deleteByIds(final List<String> guids) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(guids)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    for (String guid : guids) {
        AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (vertex == null) {
            if (LOG.isDebugEnabled()) {
                // Entity does not exist - treat as non-error, since the caller
                // wanted to delete the entity and it's already gone.
                LOG.debug("Deletion request ignored for non-existent entity with guid " + guid);
            }
            continue;
        }
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: guid=", guid);
        deletionCandidates.add(vertex);
    }
    if (deletionCandidates.isEmpty()) {
        LOG.info("No deletion candidate entities were found for guids %s", guids);
    }
    EntityMutationResponse ret = deleteVertices(deletionCandidates);
    // Notify the change listeners
    entityChangeNotifier.onEntitiesMutated(ret, false);
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 5 with AtlasEntityAccessRequest

use of org.apache.atlas.authorize.AtlasEntityAccessRequest in project atlas by apache.

the class AtlasEntityStoreV1 method createOrUpdate.

private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createOrUpdate()");
    }
    if (entityStream == null || !entityStream.hasNext()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no entities to create/update.");
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "createOrUpdate()");
    }
    try {
        final boolean isImport = entityStream instanceof EntityImportStream;
        final EntityMutationContext context = preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);
        // Check if authorized to create entities
        if (!isImport && CollectionUtils.isNotEmpty(context.getCreatedEntities())) {
            for (AtlasEntity entity : context.getCreatedEntities()) {
                AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)), "create entity: type=", entity.getTypeName());
            }
        }
        // for existing entities, skip update if incoming entity doesn't have any change
        if (CollectionUtils.isNotEmpty(context.getUpdatedEntities())) {
            List<AtlasEntity> entitiesToSkipUpdate = null;
            for (AtlasEntity entity : context.getUpdatedEntities()) {
                String guid = entity.getGuid();
                AtlasVertex vertex = context.getVertex(guid);
                AtlasEntity entityInStore = entityRetriever.toAtlasEntity(vertex);
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                if (!AtlasEntityUtil.hasAnyAttributeUpdate(entityType, entity, entityInStore)) {
                    // if classifications are to be replaced as well, then skip updates only when no change in classifications as well
                    if (!replaceClassifications || Objects.equals(entity.getClassifications(), entityInStore.getClassifications())) {
                        if (entitiesToSkipUpdate == null) {
                            entitiesToSkipUpdate = new ArrayList<>();
                        }
                        entitiesToSkipUpdate.add(entity);
                    }
                }
            }
            if (entitiesToSkipUpdate != null) {
                context.getUpdatedEntities().removeAll(entitiesToSkipUpdate);
            }
            // Check if authorized to update entities
            if (!isImport) {
                for (AtlasEntity entity : context.getUpdatedEntities()) {
                    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(entity)), "update entity: type=", entity.getTypeName());
                }
            }
        }
        EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications);
        ret.setGuidAssignments(context.getGuidAssignments());
        // Notify the change listeners
        entityChangeNotifier.onEntitiesMutated(ret, isImport);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== createOrUpdate()");
        }
        return ret;
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasEntityAccessRequest (org.apache.atlas.authorize.AtlasEntityAccessRequest)17 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)15 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)3 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1