Search in sources :

Example 11 with AccessMode

use of org.neo4j.internal.kernel.api.security.AccessMode in project neo4j by neo4j.

the class AllStoreHolder method relationshipExists.

@Override
public boolean relationshipExists(long reference) {
    ktx.assertOpen();
    if (hasTxStateWithChanges()) {
        TransactionState txState = txState();
        if (txState.relationshipIsDeletedInThisTx(reference)) {
            return false;
        } else if (txState.relationshipIsAddedInThisTx(reference)) {
            return true;
        }
    }
    AccessMode mode = ktx.securityContext().mode();
    CursorContext cursorContext = ktx.cursorContext();
    boolean existsInRelStore = storageReader.relationshipExists(reference, cursorContext);
    if (mode.allowsTraverseAllRelTypes()) {
        return existsInRelStore;
    } else if (!existsInRelStore) {
        return false;
    } else {
        // DefaultNodeCursor already contains traversal checks within next()
        try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext)) {
            ktx.dataRead().singleRelationship(reference, rels);
            return rels.next();
        }
    }
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) AdminAccessMode(org.neo4j.internal.kernel.api.security.AdminAccessMode) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 12 with AccessMode

use of org.neo4j.internal.kernel.api.security.AccessMode in project neo4j by neo4j.

the class BuiltInProcedures method listLabels.

@SystemProcedure
@Description("List all available labels in the database.")
@Procedure(name = "db.labels", mode = READ)
public Stream<LabelResult> listLabels() {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    AccessMode mode = kernelTransaction.securityContext().mode();
    TokenRead tokenRead = kernelTransaction.tokenRead();
    List<LabelResult> labelsInUse;
    try (KernelTransaction.Revertable ignore = kernelTransaction.overrideWith(SecurityContext.AUTH_DISABLED)) {
        // Get all labels that are in use as seen by a super user
        labelsInUse = stream(LABELS.inUse(kernelTransaction)).filter(label -> mode.allowsTraverseNode(tokenRead.nodeLabel(label.name()))).map(LabelResult::new).collect(Collectors.toList());
    }
    return labelsInUse.stream();
}
Also used : Mode(org.neo4j.procedure.Mode) Arrays(java.util.Arrays) StoreIdProvider(org.neo4j.storageengine.api.StoreIdProvider) SCHEMA(org.neo4j.procedure.Mode.SCHEMA) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) TokenNameLookup(org.neo4j.common.TokenNameLookup) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Value(org.neo4j.values.storable.Value) ProceduresTimeFormatHelper.formatTime(org.neo4j.procedure.builtin.ProceduresTimeFormatHelper.formatTime) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Transaction(org.neo4j.graphdb.Transaction) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Procedure(org.neo4j.procedure.Procedure) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) LABELS(org.neo4j.kernel.impl.api.TokenAccess.LABELS) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) List(java.util.List) Stream(java.util.stream.Stream) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) StoreIdDecodeUtils.decodeId(org.neo4j.procedure.builtin.StoreIdDecodeUtils.decodeId) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Admin(org.neo4j.procedure.Admin) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Label(org.neo4j.graphdb.Label) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) Context(org.neo4j.procedure.Context) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) Iterators.stream(org.neo4j.internal.helpers.collection.Iterators.stream) DependencyResolver(org.neo4j.common.DependencyResolver) RELATIONSHIP_TYPES(org.neo4j.kernel.impl.api.TokenAccess.RELATIONSHIP_TYPES) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) TimeUnit(java.util.concurrent.TimeUnit) PROPERTY_KEYS(org.neo4j.kernel.impl.api.TokenAccess.PROPERTY_KEYS) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) Relationship(org.neo4j.graphdb.Relationship) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Comparator(java.util.Comparator) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Aggregations

AccessMode (org.neo4j.internal.kernel.api.security.AccessMode)12 AdminAccessMode (org.neo4j.internal.kernel.api.security.AdminAccessMode)6 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 OverriddenAccessMode (org.neo4j.kernel.impl.api.security.OverriddenAccessMode)6 RestrictedAccessMode (org.neo4j.kernel.impl.api.security.RestrictedAccessMode)6 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)5 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)5 KernelException (org.neo4j.exceptions.KernelException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 IntSupplier (java.util.function.IntSupplier)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ZoneId (java.time.ZoneId)2 Arrays (java.util.Arrays)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Map (java.util.Map)2 TimeUnit (java.util.concurrent.TimeUnit)2