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());
}
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");
}
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());
}
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);
}
}
}
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());
}
}
Aggregations