Search in sources :

Example 11 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method deleteByUniqueAttributes.

@Override
@GraphTransaction
public EntityMutationResponse deleteByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> uniqAttributes) throws AtlasBaseException {
    if (MapUtils.isEmpty(uniqAttributes)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, uniqAttributes.toString());
    }
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqAttributes);
    if (vertex != null) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: typeName=", entityType.getTypeName(), ", uniqueAttributes=", uniqAttributes);
        deletionCandidates.add(vertex);
    } else {
        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 uniqueAttributes " + uniqAttributes);
        }
    }
    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 12 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method deleteClassifications.

@Override
@GraphTransaction
public void deleteClassifications(final String guid, final List<String> classificationNames) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (CollectionUtils.isEmpty(classificationNames)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    for (String classification : classificationNames) {
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_REMOVE_CLASSIFICATION, entityHeader, new AtlasClassification(classification)), "remove classification: guid=", guid, ", classification=", classification);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting classifications={} from entity={}", classificationNames, guid);
    }
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    entityGraphMapper.deleteClassifications(guid, classificationNames);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 13 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method addClassification.

@Override
@GraphTransaction
public void addClassification(final List<String> guids, final AtlasClassification classification) throws AtlasBaseException {
    if (CollectionUtils.isEmpty(guids)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified");
    }
    if (classification == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classification not specified");
    }
    for (String guid : guids) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_ADD_CLASSIFICATION, entityHeader, classification), "add classification: guid=", guid, ", classification=", classification.getTypeName());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Adding classification={} to entities={}", classification, guids);
    }
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guids);
    validateAndNormalize(classification);
    List<AtlasClassification> classifications = Collections.singletonList(classification);
    for (String guid : guids) {
        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 14 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method updateClassifications.

@Override
@GraphTransaction
public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classifications={} for entity={}", classifications, guid);
    }
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid not specified");
    }
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
    }
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    for (AtlasClassification classification : classifications) {
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_CLASSIFICATION, entityHeader, classification), "update classification: guid=", guid, ", classification=", classification.getTypeName());
    }
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(guid);
    entityGraphMapper.updateClassifications(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 15 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method setPropagatedClassificationState.

@Override
@GraphTransaction
public void setPropagatedClassificationState(String entityGuid, String classificationName, String sourceEntityGuid, boolean disablePropagation) throws AtlasBaseException {
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(entityGuid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_CLASSIFICATION, entityHeader, new AtlasClassification(classificationName)), "change propagated classification state: guid=", entityGuid, ", classification=", classificationName);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Toggle propagated classification={}, sourceEntityGuid={} for entity={}, disablePropagation={}", classificationName, sourceEntityGuid, entityGuid, disablePropagation);
    }
    GraphTransactionInterceptor.lockObjectAndReleasePostCommit(entityGuid);
    entityGraphMapper.setPropagatedClassificationState(entityGuid, classificationName, sourceEntityGuid, disablePropagation);
}
Also used : AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

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