Search in sources :

Example 46 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class AuthProcedures method listUsers.

@SystemProcedure
@Deprecated
@Description("List all native users.")
@Procedure(name = "dbms.security.listUsers", mode = READ, deprecatedBy = "Administration command: SHOW USERS")
public Stream<UserResult> listUsers() throws ProcedureException {
    var query = "SHOW USERS";
    List<UserResult> result = new ArrayList<>();
    try {
        Result execute = transaction.execute(query);
        execute.accept(row -> {
            var username = row.getString("user");
            var changeRequired = row.getBoolean("passwordChangeRequired");
            result.add(new UserResult(username, changeRequired));
            return true;
        });
    } catch (Exception e) {
        translateException(e, "dbms.security.listUsers");
    }
    if (result.isEmpty()) {
        return showCurrentUser();
    }
    return result.stream();
}
Also used : ArrayList(java.util.ArrayList) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Result(org.neo4j.graphdb.Result) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 47 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT method listAllLabels.

@Test
void listAllLabels() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    long nodeId = transaction.dataWrite().nodeCreate();
    int labelId = transaction.tokenWrite().labelGetOrCreateForName("MyLabel");
    transaction.dataWrite().nodeAddLabel(nodeId, labelId);
    commit();
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "labels")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyLabel") });
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 48 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT method listRelationshipTypes.

@Test
void listRelationshipTypes() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    int relType = transaction.tokenWrite().relationshipTypeGetOrCreateForName("MyRelType");
    long startNodeId = transaction.dataWrite().nodeCreate();
    long endNodeId = transaction.dataWrite().nodeCreate();
    transaction.dataWrite().relationshipCreate(startNodeId, relType, endNodeId);
    commit();
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "relationshipTypes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyRelType") });
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 49 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class AllStoreHolder method callProcedure.

private RawIterator<AnyValue[], ProcedureException> callProcedure(int id, AnyValue[] input, final AccessMode.Static procedureMode, ProcedureCallContext procedureCallContext) throws ProcedureException {
    ktx.assertOpen();
    AccessMode mode = ktx.securityContext().mode();
    if (!mode.allowsExecuteProcedure(id)) {
        String message = format("Executing procedure is not allowed for %s.", ktx.securityContext().description());
        throw ktx.securityAuthorizationHandler().logAndGetAuthorizationException(ktx.securityContext(), message);
    }
    final SecurityContext procedureSecurityContext = mode.shouldBoostProcedure(id) ? ktx.securityContext().withMode(new OverriddenAccessMode(mode, procedureMode)).withMode(AdminAccessMode.FULL) : ktx.securityContext().withMode(new RestrictedAccessMode(mode, procedureMode));
    final RawIterator<AnyValue[], ProcedureException> procedureCall;
    try (KernelTransaction.Revertable ignore = ktx.overrideWith(procedureSecurityContext);
        Statement statement = ktx.acquireStatement()) {
        procedureCall = globalProcedures.callProcedure(prepareContext(procedureSecurityContext, procedureCallContext), id, input, statement);
    }
    return createIterator(procedureSecurityContext, procedureCall);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) Statement(org.neo4j.kernel.api.Statement) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) 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) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

Example 50 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ProcedureOutputSignatureCompilerTest method shouldGiveHelpfulErrorOnMapWithNonStringKeyMap.

@Test
void shouldGiveHelpfulErrorOnMapWithNonStringKeyMap() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> signatures(RecordWithNonStringKeyMap.class));
    assertThat(exception.getMessage()).isEqualTo("Field `wat` in record `RecordWithNonStringKeyMap` cannot be converted " + "to a Neo4j type: Maps are required to have `String` keys - but this map " + "has `org.neo4j.procedure.impl.ProcedureOutputSignatureCompilerTest$RecordWithNonStringKeyMap` keys.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)124 Test (org.junit.jupiter.api.Test)95 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)21 AnyValue (org.neo4j.values.AnyValue)19 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)14 KernelException (org.neo4j.exceptions.KernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)9 Arrays (java.util.Arrays)8 List (java.util.List)8 RawIterator (org.neo4j.collection.RawIterator)8 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)8 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)8 Collectors (java.util.stream.Collectors)7 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)6 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)6