Search in sources :

Example 1 with SystemGraphComponents

use of org.neo4j.dbms.database.SystemGraphComponents in project neo4j by neo4j.

the class BuiltInProceduresTest method setup.

@BeforeEach
void setup() throws Exception {
    procs.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
    procs.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
    procs.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
    procs.registerComponent(Transaction.class, Context::internalTransaction, true);
    procs.registerComponent(SecurityContext.class, Context::securityContext, true);
    procs.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
    procs.registerComponent(SystemGraphComponents.class, ctx -> systemGraphComponents, false);
    procs.registerComponent(Log.class, ctx -> log, false);
    procs.registerType(Node.class, NTNode);
    procs.registerType(Relationship.class, NTRelationship);
    procs.registerType(Path.class, NTPath);
    new SpecialBuiltInProcedures("1.3.37", Edition.COMMUNITY.toString()).accept(procs);
    procs.registerProcedure(BuiltInProcedures.class);
    procs.registerProcedure(BuiltInDbmsProcedures.class);
    when(transaction.kernelTransaction()).thenReturn(tx);
    when(tx.tokenRead()).thenReturn(tokens);
    when(tx.dataRead()).thenReturn(read);
    when(tx.schemaRead()).thenReturn(schemaRead);
    when(tx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
    when(callContext.isCalledFromCypher()).thenReturn(false);
    when(schemaRead.snapshot()).thenReturn(schemaReadCore);
    when(tokens.propertyKeyGetAllTokens()).thenAnswer(asTokens(propKeys));
    when(tokens.labelsGetAllTokens()).thenAnswer(asTokens(labels));
    when(tokens.relationshipTypesGetAllTokens()).thenAnswer(asTokens(relTypes));
    when(schemaReadCore.indexesGetAll()).thenAnswer(i -> Iterators.concat(indexes.iterator(), uniqueIndexes.iterator()));
    when(schemaReadCore.index(any(SchemaDescriptor.class))).thenAnswer((Answer<IndexDescriptor>) invocationOnMock -> {
        SchemaDescriptor schema = invocationOnMock.getArgument(0);
        return getIndexReference(schema);
    });
    when(schemaReadCore.constraintsGetAll()).thenAnswer(i -> constraints.iterator());
    when(tokens.propertyKeyName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
    when(tokens.nodeLabelName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
    when(tokens.relationshipTypeName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
    when(tokens.propertyKeyGetName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
    when(tokens.labelGetName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
    when(tokens.relationshipTypeGetName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
    when(tokens.entityTokensGetNames(any(), any())).then(invocation -> {
        EntityType type = invocation.getArgument(0);
        int[] ids = invocation.getArgument(1);
        Map<Integer, String> mapping = type == EntityType.NODE ? labels : relTypes;
        return Arrays.stream(ids).mapToObj(mapping::get).toArray(String[]::new);
    });
    when(schemaReadCore.constraintsGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.indexesGetForLabel(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.indexesGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
    when(schemaReadCore.constraintsGetForLabel(anyInt())).thenReturn(emptyIterator());
    when(read.countsForNode(anyInt())).thenReturn(1L);
    when(read.countsForRelationship(anyInt(), anyInt(), anyInt())).thenReturn(1L);
    when(schemaReadCore.indexGetState(any(IndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
}
Also used : SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) SystemGraphComponent(org.neo4j.dbms.database.SystemGraphComponent) MapUtil(org.neo4j.internal.helpers.collection.MapUtil) Log(org.neo4j.logging.Log) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EMPTY(org.neo4j.kernel.api.index.IndexProvider.EMPTY) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Value(org.neo4j.values.storable.Value) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Statement(org.neo4j.kernel.api.Statement) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Collections.singletonList(java.util.Collections.singletonList) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) EMPTY_RESOURCE_TRACKER(org.neo4j.kernel.api.ResourceTracker.EMPTY_RESOURCE_TRACKER) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) Map(java.util.Map) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Transaction(org.neo4j.graphdb.Transaction) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) SettingValueParsers(org.neo4j.configuration.SettingValueParsers) TextValue(org.neo4j.values.storable.TextValue) Collections.emptyIterator(java.util.Collections.emptyIterator) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Test(org.junit.jupiter.api.Test) Path(org.neo4j.graphdb.Path) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Mockito.mock(org.mockito.Mockito.mock) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnyValue(org.neo4j.values.AnyValue) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor) SettingImpl(org.neo4j.configuration.SettingImpl) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TokenRead(org.neo4j.internal.kernel.api.TokenRead) HashMap(java.util.HashMap) NTNode(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTNode) Node(org.neo4j.graphdb.Node) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) Values(org.neo4j.values.storable.Values) DefaultValueMapper(org.neo4j.kernel.impl.util.DefaultValueMapper) Answer(org.mockito.stubbing.Answer) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) TestSystemGraphComponent(org.neo4j.dbms.database.TestSystemGraphComponent) DependencyResolver(org.neo4j.common.DependencyResolver) IndexConfig(org.neo4j.internal.schema.IndexConfig) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) IntSupplier(java.util.function.IntSupplier) ValueUtils(org.neo4j.kernel.impl.util.ValueUtils) Iterator(java.util.Iterator) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) Edition(org.neo4j.common.Edition) Setting(org.neo4j.graphdb.config.Setting) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Mockito.when(org.mockito.Mockito.when) Context(org.neo4j.kernel.api.procedure.Context) NTPath(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTPath) GlobalProceduresRegistry(org.neo4j.procedure.impl.GlobalProceduresRegistry) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) Relationship(org.neo4j.graphdb.Relationship) NTRelationship(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTRelationship) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NamedToken(org.neo4j.token.api.NamedToken) ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) EntityType(org.neo4j.common.EntityType) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SystemGraphComponents

use of org.neo4j.dbms.database.SystemGraphComponents in project neo4j by neo4j.

the class BasicSystemGraphRealmIT method startSystemGraphRealm.

private void startSystemGraphRealm() throws Exception {
    Config config = Config.defaults(DatabaseManagementSystemSettings.auth_store_directory, testDirectory.directory("data/dbms"));
    var systemGraphComponents = new SystemGraphComponents();
    systemGraphComponents.register(new DefaultSystemGraphComponent(config));
    systemGraphComponents.register(new UserSecurityGraphComponent(Mockito.mock(AbstractSecurityLog.class), oldUsers, initialPassword, config));
    var systemGraphSupplier = SystemGraphRealmHelper.makeSystemSupplier(dbManager);
    systemGraphInitializer = new DefaultSystemGraphInitializer(systemGraphSupplier, systemGraphComponents);
    systemGraphInitializer.start();
    RateLimitedAuthenticationStrategy authStrategy = new RateLimitedAuthenticationStrategy(Clock.systemUTC(), config);
    realm = new BasicSystemGraphRealm(realmHelper, authStrategy);
}
Also used : SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) DefaultSystemGraphInitializer(org.neo4j.dbms.database.DefaultSystemGraphInitializer) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) DefaultSystemGraphComponent(org.neo4j.dbms.database.DefaultSystemGraphComponent) UserSecurityGraphComponent(org.neo4j.server.security.systemgraph.UserSecurityGraphComponent) Config(org.neo4j.configuration.Config) BasicSystemGraphRealm(org.neo4j.server.security.systemgraph.BasicSystemGraphRealm)

Example 3 with SystemGraphComponents

use of org.neo4j.dbms.database.SystemGraphComponents in project neo4j by neo4j.

the class CommunityEditionModule method setupSecurityGraphInitializer.

private void setupSecurityGraphInitializer(GlobalModule globalModule) {
    Config config = globalModule.getGlobalConfig();
    FileSystemAbstraction fileSystem = globalModule.getFileSystem();
    LogProvider logProvider = globalModule.getLogService().getUserLogProvider();
    AbstractSecurityLog securityLog = new CommunitySecurityLog((LogExtended) logProvider.getLog(UserSecurityGraphComponent.class));
    var communityComponent = CommunitySecurityModule.createSecurityComponent(securityLog, config, fileSystem, logProvider);
    Dependencies dependencies = globalModule.getGlobalDependencies();
    SystemGraphComponents systemGraphComponents = dependencies.resolveDependency(SystemGraphComponents.class);
    systemGraphComponents.register(communityComponent);
}
Also used : SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) LogProvider(org.neo4j.logging.LogProvider) CommunitySecurityLog(org.neo4j.internal.kernel.api.security.CommunitySecurityLog) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.configuration.Config) AbstractSecurityLog(org.neo4j.internal.kernel.api.security.AbstractSecurityLog) Dependencies(org.neo4j.collection.Dependencies)

Example 4 with SystemGraphComponents

use of org.neo4j.dbms.database.SystemGraphComponents in project neo4j by neo4j.

the class UserSecurityGraphComponentTest method setup.

@BeforeAll
static void setup() throws IOException, InvalidArgumentsException {
    Config cfg = Config.newBuilder().set(auth_enabled, TRUE).set(allow_single_automatic_upgrade, FALSE).build();
    dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).impermanent().setConfig(cfg).noOpSystemGraphInitializer().build();
    system = (GraphDatabaseFacade) dbms.database(SYSTEM_DATABASE_NAME);
    DependencyResolver resolver = system.getDependencyResolver();
    systemGraphComponents = resolver.resolveDependency(SystemGraphComponents.class);
    authManager = resolver.resolveDependency(AuthManager.class);
    // Insert a custom SecurityUserComponent instead of the default one,
    // in order to have a handle on it and to migrate a 3.5 user
    systemGraphComponents.deregister(SECURITY_USER_COMPONENT);
    UserRepository oldUsers = new InMemoryUserRepository();
    User oldUser = new User.Builder("alice", credentialFor("secret")).withRequiredPasswordChange(false).build();
    oldUsers.create(oldUser);
    UserRepository initialPassword = new InMemoryUserRepository();
    userSecurityGraphComponent = new UserSecurityGraphComponent(CommunitySecurityLog.NULL_LOG, oldUsers, initialPassword, Config.defaults());
    systemGraphComponents.register(userSecurityGraphComponent);
    // remove DBMS runtime component as it is not a subject of this test
    systemGraphComponents.deregister(DBMS_RUNTIME_COMPONENT);
}
Also used : SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) UserRepository(org.neo4j.server.security.auth.UserRepository) User(org.neo4j.kernel.impl.security.User) UserSecurityGraphComponent(org.neo4j.server.security.systemgraph.UserSecurityGraphComponent) AuthManager(org.neo4j.kernel.api.security.AuthManager) Config(org.neo4j.configuration.Config) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) DependencyResolver(org.neo4j.common.DependencyResolver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with SystemGraphComponents

use of org.neo4j.dbms.database.SystemGraphComponents in project neo4j by neo4j.

the class BuiltInDbmsProcedures method upgrade.

@Admin
@SystemProcedure
@Description("Upgrade the system database schema if it is not the current schema.")
@Procedure(name = "dbms.upgrade", mode = WRITE)
public Stream<SystemGraphComponentUpgradeResult> upgrade() throws ProcedureException {
    if (!callContext.isSystemDatabase()) {
        throw new ProcedureException(ProcedureCallFailed, "This is an administration command and it should be executed against the system database: dbms.upgrade");
    }
    SystemGraphComponents versions = systemGraphComponents;
    SystemGraphComponent.Status status = versions.detect(transaction);
    // New components are not currently initialised in cluster deployment when new binaries are booted on top of an existing database.
    // This is a known shortcoming of the lifecycle and a state transfer from UNINITIALIZED to CURRENT must be supported
    // as a workaround until it is fixed.
    var upgradableStatuses = List.of(REQUIRES_UPGRADE, UNINITIALIZED);
    if (upgradableStatuses.contains(status)) {
        ArrayList<String> failed = new ArrayList<>();
        versions.forEach(component -> {
            SystemGraphComponent.Status initialStatus = component.detect(transaction);
            if (upgradableStatuses.contains(initialStatus)) {
                try {
                    component.upgradeToCurrent(graph);
                } catch (Exception e) {
                    failed.add(String.format("[%s] %s", component.componentName(), e.getMessage()));
                }
            }
        });
        String upgradeResult = failed.isEmpty() ? "Success" : "Failed: " + String.join(", ", failed);
        return Stream.of(new SystemGraphComponentUpgradeResult(versions.detect(transaction).name(), upgradeResult));
    } else {
        return Stream.of(new SystemGraphComponentUpgradeResult(status.name(), status.resolution()));
    }
}
Also used : SystemGraphComponents(org.neo4j.dbms.database.SystemGraphComponents) SystemGraphComponent(org.neo4j.dbms.database.SystemGraphComponent) ArrayList(java.util.ArrayList) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidArgumentsException(org.neo4j.kernel.api.exceptions.InvalidArgumentsException) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure) Admin(org.neo4j.procedure.Admin)

Aggregations

SystemGraphComponents (org.neo4j.dbms.database.SystemGraphComponents)5 Config (org.neo4j.configuration.Config)4 ArrayList (java.util.ArrayList)2 DependencyResolver (org.neo4j.common.DependencyResolver)2 SystemGraphComponent (org.neo4j.dbms.database.SystemGraphComponent)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Arrays (java.util.Arrays)1 Collections.emptyIterator (java.util.Collections.emptyIterator)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 IntSupplier (java.util.function.IntSupplier)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1