Search in sources :

Example 6 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method deleteById.

@Override
@GraphTransaction
public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    Collection<AtlasVertex> deletionCandidates = new ArrayList<>();
    AtlasVertex vertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (vertex != null) {
        AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(vertex);
        AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_DELETE, entityHeader), "delete entity: guid=", guid);
        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 guid " + guid);
        }
    }
    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 7 with AtlasEntityAccessRequest

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

the class AtlasEntityStoreV1 method getClassifications.

@Override
@GraphTransaction
public List<AtlasClassification> getClassifications(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Getting classifications for entity={}", guid);
    }
    AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ_CLASSIFICATION, entityHeader), "get classifications: guid=", guid);
    return entityHeader.getClassifications();
}
Also used : AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 8 with AtlasEntityAccessRequest

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

the class EntityLineageService method getSchemaForHiveTableByGuid.

@Override
@GraphTransaction
public SchemaDetails getSchemaForHiveTableByGuid(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST);
    }
    SchemaDetails ret = new SchemaDetails();
    AtlasEntityType hive_column = atlasTypeRegistry.getEntityTypeByName("hive_column");
    ret.setDataType(AtlasTypeUtil.toClassTypeDefinition(hive_column));
    AtlasEntityWithExtInfo entityWithExtInfo = entityRetriever.toAtlasEntityWithExtInfo(guid);
    AtlasEntity entity = entityWithExtInfo.getEntity();
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity schema: guid=", guid);
    Map<String, AtlasEntity> referredEntities = entityWithExtInfo.getReferredEntities();
    List<String> columnIds = getColumnIds(entity);
    if (MapUtils.isNotEmpty(referredEntities)) {
        List<Map<String, Object>> rows = referredEntities.entrySet().stream().filter(e -> isColumn(columnIds, e)).map(e -> AtlasTypeUtil.toMap(e.getValue())).collect(Collectors.toList());
        ret.setRows(rows);
    }
    return ret;
}
Also used : AtlasPrivilege(org.apache.atlas.authorize.AtlasPrivilege) StringUtils(org.apache.commons.lang.StringUtils) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeUtil(org.apache.atlas.type.AtlasTypeUtil) LoggerFactory(org.slf4j.LoggerFactory) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) HashMap(java.util.HashMap) Constants(org.apache.atlas.repository.Constants) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) GraphTransaction(org.apache.atlas.annotation.GraphTransaction) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) LineageDirection(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityGraphRetriever(org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) Logger(org.slf4j.Logger) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) MapUtils(org.apache.commons.collections.MapUtils) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Set(java.util.Set) AtlasGremlinQuery(org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery) AtlasAuthorizationUtils(org.apache.atlas.authorize.AtlasAuthorizationUtils) Collectors(java.util.stream.Collectors) AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasGraphUtilsV1(org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1) List(java.util.List) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasClient(org.apache.atlas.AtlasClient) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGremlinQueryProvider(org.apache.atlas.util.AtlasGremlinQueryProvider) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) HashMap(java.util.HashMap) Map(java.util.Map) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 9 with AtlasEntityAccessRequest

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

the class EntityLineageService method getAtlasLineageInfo.

@Override
@GraphTransaction
public AtlasLineageInfo getAtlasLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    AtlasLineageInfo lineageInfo;
    AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, entity), "read entity lineage: guid=", guid);
    AtlasEntityType entityType = atlasTypeRegistry.getEntityTypeByName(entity.getTypeName());
    if (entityType == null || !entityType.getTypeAndAllSuperTypes().contains(AtlasClient.DATA_SET_SUPER_TYPE)) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_DATASET, guid);
    }
    if (direction != null) {
        if (direction.equals(LineageDirection.INPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.INPUT, depth);
        } else if (direction.equals(LineageDirection.OUTPUT)) {
            lineageInfo = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
        } else if (direction.equals(LineageDirection.BOTH)) {
            lineageInfo = getBothLineageInfo(guid, depth);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", direction.toString());
        }
    } else {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", null);
    }
    return lineageInfo;
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 10 with AtlasEntityAccessRequest

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

the class AdminResource method getUserProfile.

@GET
@Path("session")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getUserProfile() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AdminResource.getUserProfile()");
    }
    Response response;
    boolean isEntityUpdateAccessAllowed = false;
    boolean isEntityCreateAccessAllowed = false;
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String userName = null;
    Set<String> groups = new HashSet<>();
    if (auth != null) {
        userName = auth.getName();
        Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
        for (GrantedAuthority c : authorities) {
            groups.add(c.getAuthority());
        }
        isEntityUpdateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE));
        isEntityCreateAccessAllowed = AtlasAuthorizationUtils.isAccessAllowed(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE));
    }
    Map<String, Object> responseData = new HashMap<>();
    responseData.put(isCSRF_ENABLED, AtlasCSRFPreventionFilter.isCSRF_ENABLED);
    responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT);
    responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT);
    responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT);
    responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed);
    responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed);
    responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties));
    responseData.put("userName", userName);
    responseData.put("groups", groups);
    response = Response.ok(AtlasJson.toV1Json(responseData)).build();
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AdminResource.getUserProfile()");
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) HashMap(java.util.HashMap) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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