Search in sources :

Example 11 with Procedures

use of org.neo4j.kernel.impl.proc.Procedures in project neo4j by neo4j.

the class CommunitySecurityModule method setup.

@Override
public void setup(Dependencies dependencies) throws KernelException {
    Config config = dependencies.config();
    Procedures procedures = dependencies.procedures();
    LogProvider logProvider = dependencies.logService().getUserLogProvider();
    FileSystemAbstraction fileSystem = dependencies.fileSystem();
    final UserRepository userRepository = getUserRepository(config, logProvider, fileSystem);
    final UserRepository initialUserRepository = getInitialUserRepository(config, logProvider, fileSystem);
    final PasswordPolicy passwordPolicy = new BasicPasswordPolicy();
    procedures.writerCreateToken(true);
    BasicAuthManager authManager = new BasicAuthManager(userRepository, passwordPolicy, Clocks.systemClock(), initialUserRepository);
    dependencies.lifeSupport().add(dependencies.dependencySatisfier().satisfyDependency(authManager));
    procedures.registerComponent(UserManager.class, ctx -> authManager, false);
    procedures.registerProcedure(AuthProcedures.class);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) Procedures(org.neo4j.kernel.impl.proc.Procedures)

Example 12 with Procedures

use of org.neo4j.kernel.impl.proc.Procedures 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 13 with Procedures

use of org.neo4j.kernel.impl.proc.Procedures 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 14 with Procedures

use of org.neo4j.kernel.impl.proc.Procedures in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction.

@Test
public void shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction() throws Exception {
    // given procedure that produces a point
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Procedures procedures = ((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(Procedures.class);
    procedures.registerProcedure(PointProcs.class);
    // when calling procedure that produces a point
    Result result = graphDb.execute("CALL spatial.point(144.317718, -37.031738) YIELD point " + "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}), point) AS dist");
    // then
    Double dist = (Double) result.next().get("dist");
    assertThat(dist, equalTo(0.0));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Procedures(org.neo4j.kernel.impl.proc.Procedures) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 15 with Procedures

use of org.neo4j.kernel.impl.proc.Procedures in project neo4j by neo4j.

the class DataSourceModule method setupProcedures.

private Procedures setupProcedures(PlatformModule platform, EditionModule editionModule) {
    File pluginDir = platform.config.get(GraphDatabaseSettings.plugin_dir);
    Log internalLog = platform.logging.getInternalLog(Procedures.class);
    Procedures procedures = new Procedures(new SpecialBuiltInProcedures(Version.getNeo4jVersion(), platform.databaseInfo.edition.toString()), pluginDir, internalLog, new ProcedureConfig(platform.config));
    platform.life.add(procedures);
    platform.dependencies.satisfyDependency(procedures);
    procedures.registerType(Node.class, new SimpleConverter(NTNode, Node.class));
    procedures.registerType(Relationship.class, new SimpleConverter(NTRelationship, Relationship.class));
    procedures.registerType(Path.class, new SimpleConverter(NTPath, Path.class));
    procedures.registerType(Geometry.class, new SimpleConverter(NTGeometry, Geometry.class));
    procedures.registerType(Point.class, new SimpleConverter(NTPoint, Point.class));
    // Register injected public API components
    Log proceduresLog = platform.logging.getUserLog(Procedures.class);
    procedures.registerComponent(Log.class, (ctx) -> proceduresLog, true);
    Guard guard = platform.dependencies.resolveDependency(Guard.class);
    procedures.registerComponent(ProcedureTransaction.class, new ProcedureTransactionProvider(), true);
    procedures.registerComponent(TerminationGuard.class, new TerminationGuardProvider(guard), true);
    // Below components are not public API, but are made available for internal
    // procedures to call, and to provide temporary workarounds for the following
    // patterns:
    //  - Batch-transaction imports (GDAPI, needs to be real and passed to background processing threads)
    //  - Group-transaction writes (same pattern as above, but rather than splitting large transactions,
    //                              combine lots of small ones)
    //  - Bleeding-edge performance (KernelTransaction, to bypass overhead of working with Core API)
    procedures.registerComponent(DependencyResolver.class, (ctx) -> platform.dependencies, false);
    procedures.registerComponent(KernelTransaction.class, (ctx) -> ctx.get(KERNEL_TRANSACTION), false);
    procedures.registerComponent(GraphDatabaseAPI.class, (ctx) -> platform.graphDatabaseFacade, false);
    // Security procedures
    procedures.registerComponent(SecurityContext.class, ctx -> ctx.get(SECURITY_CONTEXT), true);
    // Edition procedures
    try {
        editionModule.registerProcedures(procedures);
    } catch (KernelException e) {
        internalLog.error("Failed to register built-in edition procedures at start up: " + e.getMessage());
    }
    return procedures;
}
Also used : NTPath(org.neo4j.kernel.api.proc.Neo4jTypes.NTPath) Path(org.neo4j.graphdb.Path) Log(org.neo4j.logging.Log) SimpleConverter(org.neo4j.kernel.impl.proc.TypeMappers.SimpleConverter) NTNode(org.neo4j.kernel.api.proc.Neo4jTypes.NTNode) Node(org.neo4j.graphdb.Node) SpecialBuiltInProcedures(org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures) Procedures(org.neo4j.kernel.impl.proc.Procedures) NTPoint(org.neo4j.kernel.api.proc.Neo4jTypes.NTPoint) Point(org.neo4j.graphdb.spatial.Point) TerminationGuardProvider(org.neo4j.kernel.impl.proc.TerminationGuardProvider) NTGeometry(org.neo4j.kernel.api.proc.Neo4jTypes.NTGeometry) Geometry(org.neo4j.graphdb.spatial.Geometry) NTRelationship(org.neo4j.kernel.api.proc.Neo4jTypes.NTRelationship) Relationship(org.neo4j.graphdb.Relationship) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) Guard(org.neo4j.kernel.guard.Guard) TerminationGuard(org.neo4j.procedure.TerminationGuard) TimeoutGuard(org.neo4j.kernel.guard.TimeoutGuard) ProcedureTransactionProvider(org.neo4j.kernel.impl.proc.ProcedureTransactionProvider) KernelException(org.neo4j.kernel.api.exceptions.KernelException) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) ProcedureConfig(org.neo4j.kernel.impl.proc.ProcedureConfig) SpecialBuiltInProcedures(org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures)

Aggregations

Procedures (org.neo4j.kernel.impl.proc.Procedures)16 Test (org.junit.Test)9 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)3 Config (org.neo4j.kernel.configuration.Config)3 CanWrite (org.neo4j.kernel.impl.factory.CanWrite)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Result (org.neo4j.graphdb.Result)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)2 SchemaWriteGuard (org.neo4j.kernel.impl.api.SchemaWriteGuard)2 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 LogProvider (org.neo4j.logging.LogProvider)2 StorageStatement (org.neo4j.storageengine.api.StorageStatement)2 File (java.io.File)1 Supplier (java.util.function.Supplier)1 Before (org.junit.Before)1 Pool (org.neo4j.collection.pool.Pool)1