use of org.neo4j.kernel.api.proc.UserFunctionSignature in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new function.
*
* @param function the function.
*/
public void register(CallableUserFunction function, boolean overrideCurrentImplementation) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
CallableUserFunction oldImplementation = functions.get(name);
if (oldImplementation == null) {
functions.put(name, function);
} else {
if (overrideCurrentImplementation) {
functions.put(name, function);
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register function, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.kernel.api.proc.UserFunctionSignature in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new function.
*
* @param function the function.
*/
public void register(CallableUserAggregationFunction function, boolean overrideCurrentImplementation) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
CallableUserFunction oldImplementation = functions.get(name);
if (oldImplementation == null) {
aggregationFunctions.put(name, function);
} else {
if (overrideCurrentImplementation) {
aggregationFunctions.put(name, function);
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register aggregation function, because the name `%s` is already in use.", name);
}
}
}
use of org.neo4j.kernel.api.proc.UserFunctionSignature in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldLoadUnsafeAllowedProcedureFromJar.
@Test
public void shouldLoadUnsafeAllowedProcedureFromJar() throws Throwable {
// Given
URL jar = createJarFor(ClassWithUnsafeConfiguredComponent.class);
// When
ProcedureJarLoader.Callables callables = jarloader.loadProcedures(jar);
List<CallableUserFunction> functions = callables.functions();
List<CallableProcedure> procedures = callables.procedures();
// Then
List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
assertThat(signatures, contains(procedureSignature("org", "neo4j", "kernel", "impl", "proc", "unsafeFullAccessProcedure").out("someNumber", NTInteger).build()));
assertThat(asList(procedures.get(0).apply(new BasicContext(), new Object[0])), contains(IsEqual.equalTo(new Object[] { 7331L })));
List<UserFunctionSignature> functionsSignatures = functions.stream().map(CallableUserFunction::signature).collect(toList());
assertThat(functionsSignatures, contains(functionSignature("org", "neo4j", "kernel", "impl", "proc", "unsafeFullAccessFunction").out(NTInteger).build()));
assertThat(functions.get(0).apply(new BasicContext(), new Object[0]), equalTo(7331L));
}
use of org.neo4j.kernel.api.proc.UserFunctionSignature in project neo4j by neo4j.
the class ConfiguredProceduresTestBase method shouldSetAllowedToConfigSettingForUDF.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void shouldSetAllowedToConfigSettingForUDF() throws Throwable {
configuredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty"));
Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
UserFunctionSignature funcSig = procedures.function(new QualifiedName(new String[] { "test" }, "nonAllowedFunc")).get();
assertThat(Arrays.asList(funcSig.allowed()), containsInAnyOrder("nonEmpty"));
}
use of org.neo4j.kernel.api.proc.UserFunctionSignature 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());
}
Aggregations