Search in sources :

Example 6 with Procedures

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

the class EnterpriseSecurityModule method setup.

@Override
public void setup(Dependencies dependencies) throws KernelException {
    Config config = dependencies.config();
    Procedures procedures = dependencies.procedures();
    LogProvider logProvider = dependencies.logService().getUserLogProvider();
    JobScheduler jobScheduler = dependencies.scheduler();
    FileSystemAbstraction fileSystem = dependencies.fileSystem();
    LifeSupport life = dependencies.lifeSupport();
    SecurityLog securityLog = SecurityLog.create(config, dependencies.logService().getInternalLog(GraphDatabaseFacade.class), fileSystem, jobScheduler);
    life.add(securityLog);
    boolean allowTokenCreate = config.get(SecuritySettings.allow_publisher_create_token);
    PredefinedRolesBuilder.setAllowPublisherTokenCreate(allowTokenCreate);
    procedures.writerCreateToken(allowTokenCreate);
    EnterpriseAuthAndUserManager authManager = newAuthManager(config, logProvider, securityLog, fileSystem, jobScheduler);
    life.add(dependencies.dependencySatisfier().satisfyDependency(authManager));
    // Register procedures
    procedures.registerComponent(SecurityLog.class, (ctx) -> securityLog, false);
    procedures.registerComponent(EnterpriseAuthManager.class, ctx -> authManager, false);
    procedures.registerComponent(EnterpriseSecurityContext.class, ctx -> asEnterprise(ctx.get(SECURITY_CONTEXT)), true);
    if (config.get(SecuritySettings.native_authentication_enabled) || config.get(SecuritySettings.native_authorization_enabled)) {
        procedures.registerComponent(EnterpriseUserManager.class, ctx -> authManager.getUserManager(asEnterprise(ctx.get(SECURITY_CONTEXT))), true);
        if (config.get(SecuritySettings.auth_providers).size() > 1) {
            procedures.registerProcedure(UserManagementProcedures.class, true, Optional.of("%s only applies to native users."));
        } else {
            procedures.registerProcedure(UserManagementProcedures.class, true);
        }
    } else {
        procedures.registerComponent(EnterpriseUserManager.class, ctx -> EnterpriseUserManager.NOOP, true);
    }
    procedures.registerProcedure(SecurityProcedures.class, true);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Procedures(org.neo4j.kernel.impl.proc.Procedures) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Example 7 with Procedures

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

the class ProcedureInteractionTestBase method configuredSetup.

void configuredSetup(Map<String, String> config) throws Throwable {
    neo = setUpNeoServer(config);
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    procedures.registerProcedure(ClassWithProcedures.class);
    procedures.registerFunction(ClassWithFunctions.class);
    userManager = neo.getLocalUserManager();
    userManager.newUser("noneSubject", "abc", false);
    userManager.newUser("pwdSubject", "abc", true);
    userManager.newUser("adminSubject", "abc", false);
    userManager.newUser("schemaSubject", "abc", false);
    userManager.newUser("writeSubject", "abc", false);
    userManager.newUser("readSubject", "123", false);
    // Currently admin role is created by default
    userManager.addRoleToUser(ADMIN, "adminSubject");
    userManager.addRoleToUser(ARCHITECT, "schemaSubject");
    userManager.addRoleToUser(PUBLISHER, "writeSubject");
    userManager.addRoleToUser(READER, "readSubject");
    userManager.newRole(EMPTY_ROLE);
    noneSubject = neo.login("noneSubject", "abc");
    pwdSubject = neo.login("pwdSubject", "abc");
    readSubject = neo.login("readSubject", "123");
    writeSubject = neo.login("writeSubject", "abc");
    schemaSubject = neo.login("schemaSubject", "abc");
    adminSubject = neo.login("adminSubject", "abc");
    assertEmpty(schemaSubject, "CREATE (n) SET n:A:Test:NEWNODE:VeryUniqueLabel:Node " + "SET n.id = '2', n.square = '4', n.name = 'me', n.prop = 'a', n.number = '1' DELETE n");
    assertEmpty(writeSubject, "UNWIND range(0,2) AS number CREATE (:Node {number:number, name:'node'+number})");
}
Also used : EnterpriseBuiltInDbmsProcedures(org.neo4j.kernel.enterprise.builtinprocs.EnterpriseBuiltInDbmsProcedures) Procedures(org.neo4j.kernel.impl.proc.Procedures)

Example 8 with Procedures

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

the class ConfiguredProceduresTestBase method shouldSetAllowedToConfigSetting.

@Test
public void shouldSetAllowedToConfigSetting() throws Throwable {
    configuredSetup(stringMap(SecuritySettings.default_allowed.name(), "nonEmpty"));
    Procedures procedures = neo.getLocalGraph().getDependencyResolver().resolveDependency(Procedures.class);
    ProcedureSignature numNodes = procedures.procedure(new QualifiedName(new String[] { "test" }, "numNodes"));
    assertThat(Arrays.asList(numNodes.allowed()), containsInAnyOrder("nonEmpty"));
}
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 Procedures

use of org.neo4j.kernel.impl.proc.Procedures 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"));
}
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 10 with Procedures

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

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