Search in sources :

Example 6 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ConfiguredProceduresTestBase method shouldNotSetProcedureAllowedIfSettingNotSetForUDF.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldNotSetProcedureAllowedIfSettingNotSetForUDF() throws Throwable {
    configuredSetup(defaultConfiguration());
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    UserFunctionSignature funcSig = procedures.function(new QualifiedName(new String[] { "test" }, "nonAllowedFunc")).get();
    assertThat(Arrays.asList(funcSig.allowed()), empty());
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Test(org.junit.Test)

Example 7 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ConfiguredProceduresTestBase method shouldNotRunProcedureWithMismatchingWildCardAllowed.

@Test
public void shouldNotRunProcedureWithMismatchingWildCardAllowed() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.procedure_roles.name(), "tes.*:role1"));
    userManager.newRole("role1", "noneSubject");
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    ProcedureSignature numNodes = procedures.procedure(new QualifiedName(new String[] { "test" }, "numNodes"));
    assertThat(Arrays.asList(numNodes.allowed()), empty());
    assertFail(noneSubject, "CALL test.numNodes", "Read operations are not allowed");
}
Also used : ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

Example 8 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ConfiguredProceduresTestBase method shouldNotSetProcedureAllowedIfSettingNotSet.

@Test
public void shouldNotSetProcedureAllowedIfSettingNotSet() throws Throwable {
    configuredSetup(defaultConfiguration());
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    ProcedureSignature numNodes = procedures.procedure(new QualifiedName(new String[] { "test" }, "numNodes"));
    assertThat(Arrays.asList(numNodes.allowed()), empty());
}
Also used : ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

Example 9 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ProcedureRegistry method register.

/**
     * Register a new procedure.
     *
     * @param proc the procedure.
     */
public void register(CallableProcedure proc, boolean overrideCurrentImplementation) throws ProcedureException {
    ProcedureSignature signature = proc.signature();
    QualifiedName name = signature.name();
    String descriptiveName = signature.toString();
    validateSignature(descriptiveName, signature.inputSignature(), "input");
    validateSignature(descriptiveName, signature.outputSignature(), "output");
    if (!signature.isVoid() && signature.outputSignature().isEmpty()) {
        throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Procedures with zero output fields must be declared as VOID");
    }
    CallableProcedure oldImplementation = procedures.get(name);
    if (oldImplementation == null) {
        procedures.put(name, proc);
    } else {
        if (overrideCurrentImplementation) {
            procedures.put(name, proc);
        } else {
            throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name);
        }
    }
}
Also used : ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException)

Example 10 with QualifiedName

use of org.neo4j.kernel.api.proc.QualifiedName in project neo4j by neo4j.

the class ReflectiveProcedureCompiler method compileAggregationFunction.

List<CallableUserAggregationFunction> compileAggregationFunction(Class<?> fcnDefinition) throws KernelException {
    try {
        List<Method> methods = Arrays.stream(fcnDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(UserAggregationFunction.class)).collect(Collectors.toList());
        if (methods.isEmpty()) {
            return emptyList();
        }
        MethodHandle constructor = constructor(fcnDefinition);
        ArrayList<CallableUserAggregationFunction> out = new ArrayList<>(methods.size());
        for (Method method : methods) {
            String valueName = method.getAnnotation(UserAggregationFunction.class).value();
            String definedName = method.getAnnotation(UserAggregationFunction.class).name();
            QualifiedName funcName = extractName(fcnDefinition, method, valueName, definedName);
            if (config.isWhitelisted(funcName.toString())) {
                out.add(compileAggregationFunction(fcnDefinition, constructor, method, funcName));
            } else {
                log.warn(String.format("The function '%s' is not on the whitelist and won't be loaded.", funcName.toString()));
            }
        }
        out.sort(Comparator.comparing(a -> a.signature().name().toString()));
        return out;
    } catch (KernelException e) {
        throw e;
    } catch (Exception e) {
        throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile function defined in `%s`: %s", fcnDefinition.getSimpleName(), e.getMessage());
    }
}
Also used : FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) Mode(org.neo4j.procedure.Mode) MethodHandle(java.lang.invoke.MethodHandle) Arrays(java.util.Arrays) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) UserAggregationResult(org.neo4j.procedure.UserAggregationResult) Status(org.neo4j.kernel.api.exceptions.Status) UserAggregationUpdate(org.neo4j.procedure.UserAggregationUpdate) FailedLoadFunction(org.neo4j.kernel.api.proc.FailedLoadFunction) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) FailedLoadAggregatedFunction(org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Procedure(org.neo4j.procedure.Procedure) Method(java.lang.reflect.Method) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Iterator(java.util.Iterator) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Description(org.neo4j.procedure.Description) Collections.emptyIterator(java.util.Collections.emptyIterator) Collectors(java.util.stream.Collectors) KernelException(org.neo4j.kernel.api.exceptions.KernelException) FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) UserFunction(org.neo4j.procedure.UserFunction) List(java.util.List) Stream(java.util.stream.Stream) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) PerformsWrites(org.neo4j.procedure.PerformsWrites) Comparator(java.util.Comparator) Context(org.neo4j.kernel.api.proc.Context) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)13 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)8 Test (org.junit.Test)7 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)7 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)5 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)4 MethodHandle (java.lang.invoke.MethodHandle)3 MethodHandles (java.lang.invoke.MethodHandles)3 Method (java.lang.reflect.Method)3 Modifier (java.lang.reflect.Modifier)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections.emptyIterator (java.util.Collections.emptyIterator)3 Collections.emptyList (java.util.Collections.emptyList)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Optional (java.util.Optional)3 Supplier (java.util.function.Supplier)3