Search in sources :

Example 16 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method getClassification.

@Override
@GraphTransaction
public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Getting classifications for entities={}", guid);
    }
    AtlasClassification ret = null;
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    if (CollectionUtils.isNotEmpty(entityHeader.getClassifications())) {
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ_CLASSIFICATION, entityHeader), "get classification: guid=", guid, ", classification=", classificationName);
        for (AtlasClassification classification : entityHeader.getClassifications()) {
            if (!StringUtils.equalsIgnoreCase(classification.getTypeName(), classificationName)) {
                continue;
            }
            if (StringUtils.isEmpty(classification.getEntityGuid()) || StringUtils.equalsIgnoreCase(classification.getEntityGuid(), guid)) {
                ret = classification;
                break;
            } else if (ret == null) {
                ret = classification;
            }
        }
    }
    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 17 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method getByIds.

@Override
@GraphTransaction
public AtlasEntitiesWithExtInfo getByIds(List<String> guids) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getByIds({})", guids);
    }
    AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids);
    // verify authorization to read the entities
    if (ret != null) {
        for (String guid : guids) {
            AtlasEntity entity = ret.getEntity(guid);
            AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity: guid=", guid);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getByIds({}): {}", guids, ret);
    }
    return ret;
}
Also used : AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) 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