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