//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotLogPassword() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotLogPassword() { _database = _databaseBuilder.setConfig(log_queries, Settings.TRUE).setConfig(logs_directory, _logsDirectory.Path).setConfig(GraphDatabaseSettings.auth_enabled, Settings.TRUE).newGraphDatabase(); GraphDatabaseFacade facade = ( GraphDatabaseFacade )this._database; EnterpriseAuthManager authManager = facade.DependencyResolver.resolveDependency(typeof(EnterpriseAuthManager)); EnterpriseLoginContext neo = authManager.Login(AuthToken.newBasicAuthToken("neo4j", "neo4j")); string query = "CALL dbms.security.changePassword('abc123')"; try { using (InternalTransaction tx = facade.BeginTransaction(KernelTransaction.Type.@explicit, neo)) { Result res = facade.Execute(tx, query, VirtualValues.EMPTY_MAP); res.Close(); tx.Success(); } } finally { facade.Shutdown(); } IList <string> logLines = ReadAllLines(_logFilename); assertEquals(1, logLines.Count); assertThat(logLines[0], containsString("CALL dbms.security.changePassword(******)")); assertThat(logLines[0], not(containsString("abc123"))); assertThat(logLines[0], containsString(neo.Subject().username())); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allClusterNodesShouldSupportTheBuiltInProcedures() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AllClusterNodesShouldSupportTheBuiltInProcedures() { ClusterManager.ManagedCluster cluster = ClusterRule.startCluster(); try { foreach (HighlyAvailableGraphDatabase gdb in cluster.AllMembers) { { // (1) BuiltInProcedures from community Result result = gdb.Execute("CALL dbms.procedures()"); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue(result.HasNext()); result.Close(); } // (2) BuiltInProcedures from enterprise using (InternalTransaction tx = gdb.BeginTransaction(KernelTransaction.Type.@explicit, EnterpriseLoginContext.AUTH_DISABLED)) { Result result = gdb.execute(tx, "CALL dbms.listQueries()", EMPTY_MAP); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertTrue(result.HasNext()); result.Close(); tx.Success(); } } } finally { cluster.Shutdown(); } }
public override void CommitAndRestartTx() { /* * This method is use by the Cypher runtime to cater for PERIODIC COMMIT, which allows a single query to * periodically, after x number of rows, to commit a transaction and spawn a new one. * * To still keep track of the running stream after switching transactions, we need to open the new transaction * before closing the old one. This way, a query will not disappear and appear when switching transactions. * * Since our transactions are thread bound, we must first unbind the old transaction from the thread before * creating a new one. And then we need to do that thread switching again to close the old transaction. */ CheckNotTerminated(); CollectTransactionExecutionStatistic(); // (1) Unbind current transaction QueryRegistryOperations oldQueryRegistryOperations = _statement.queryRegistration(); Statement oldStatement = _statement; InternalTransaction oldTransaction = _transaction; KernelTransaction oldKernelTx = _txBridge.getKernelTransactionBoundToThisThread(true); _txBridge.unbindTransactionFromCurrentThread(); // (2) Create, bind, register, and unbind new transaction _transaction = _graph.beginTransaction(TransactionType, SecurityContextConflict); _kernelTransaction = _txBridge.getKernelTransactionBoundToThisThread(true); _statement = _kernelTransaction.acquireStatement(); _statement.queryRegistration().registerExecutingQuery(_executingQuery); _txBridge.unbindTransactionFromCurrentThread(); // (3) Rebind old transaction just to commit and close it (and unregister as a side effect of that) _txBridge.bindTransactionToCurrentThread(oldKernelTx); oldQueryRegistryOperations.UnregisterExecutingQuery(_executingQuery); try { oldStatement.Close(); oldTransaction.Success(); oldTransaction.Close(); } catch (Exception t) { // Corner case: The old transaction might have been terminated by the user. Now we also need to // terminate the new transaction. _txBridge.bindTransactionToCurrentThread(_kernelTransaction); _transaction.failure(); _transaction.close(); _txBridge.unbindTransactionFromCurrentThread(); throw t; } // (4) Unbind the now closed old transaction and rebind the new transaction for continued execution _txBridge.unbindTransactionFromCurrentThread(); _txBridge.bindTransactionToCurrentThread(_kernelTransaction); }
private Result Execute(LoginContext subject, string query, IDictionary <string, object> @params) { Result result; using (InternalTransaction tx = _db.beginTransaction(@explicit, subject)) { result = _db.execute(tx, query, ValueUtils.asMapValue(@params)); result.ResultAsString(); tx.Success(); } return(result); }
private void Execute(LoginContext subject, string query, IDictionary <string, object> @params, System.Action <Result> consumer) { Result result; using (InternalTransaction tx = _db.beginTransaction(@explicit, subject)) { result = _db.execute(tx, query, ValueUtils.asMapValue(@params)); consumer(result); tx.Success(); result.Close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotListAnyQueriesIfNotAuthenticated() public virtual void ShouldNotListAnyQueriesIfNotAuthenticated() { EnterpriseLoginContext unAuthSubject = CreateFakeAnonymousEnterpriseLoginContext(); GraphDatabaseFacade graph = Neo.LocalGraph; using (InternalTransaction tx = graph.BeginTransaction(KernelTransaction.Type.@explicit, unAuthSubject)) { Result result = graph.execute(tx, "CALL dbms.listQueries", EMPTY_MAP); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: assertFalse(result.HasNext()); tx.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWarnWhenUsingInternalAndOtherProvider() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWarnWhenUsingInternalAndOtherProvider() { ConfiguredSetup(stringMap(SecuritySettings.auth_providers.name(), InternalSecurityName() + " ,LDAP")); AssertSuccess(AdminSubject, "CALL dbms.security.listUsers", r => assertKeyIsMap(r, "username", "roles", ValueOf(_userList))); GraphDatabaseFacade localGraph = Neo.LocalGraph; InternalTransaction transaction = localGraph.BeginTransaction(KernelTransaction.Type.@explicit, StandardEnterpriseLoginContext.AUTH_DISABLED); Result result = localGraph.execute(transaction, "EXPLAIN CALL dbms.security.listUsers", EMPTY_MAP); string description = string.Format("{0} ({1})", Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureWarning.code().description(), "dbms.security.listUsers only applies to native users."); assertThat(ContainsNotification(result, description), equalTo(true)); transaction.Success(); transaction.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLogTXMetaDataInQueryLog() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldLogTXMetaDataInQueryLog() { // turn on query logging _databaseBuilder.setConfig(logs_directory, _logsDirectory.Path); _databaseBuilder.setConfig(log_queries, Settings.TRUE); _db = new EmbeddedInteraction(_databaseBuilder, Collections.emptyMap()); GraphDatabaseFacade graph = _db.LocalGraph; _db.LocalUserManager.setUserPassword("neo4j", password("123"), false); EnterpriseLoginContext subject = _db.login("neo4j", "123"); _db.executeQuery(subject, "UNWIND range(0, 10) AS i CREATE (:Foo {p: i})", Collections.emptyMap(), ResourceIterator.close); // Set meta data and execute query in transaction using (InternalTransaction tx = _db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.@explicit)) { graph.Execute("CALL dbms.setTXMetaData( { User: '******' } )", Collections.emptyMap()); graph.Execute("CALL dbms.procedures() YIELD name RETURN name", Collections.emptyMap()).close(); graph.Execute("MATCH (n) RETURN n", Collections.emptyMap()).close(); graph.Execute(QUERY, Collections.emptyMap()); tx.Success(); } // Ensure that old meta data is not retained using (InternalTransaction tx = _db.beginLocalTransactionAsUser(subject, KernelTransaction.Type.@explicit)) { graph.Execute("CALL dbms.setTXMetaData( { Location: 'Sweden' } )", Collections.emptyMap()); graph.Execute("MATCH ()-[r]-() RETURN count(r)", Collections.emptyMap()).close(); tx.Success(); } _db.tearDown(); // THEN IList <string> logLines = ReadAllLines(_logFilename); assertThat(logLines, hasSize(7)); assertThat(logLines[0], not(containsString("User: '******'"))); // we don't care if setTXMetaData contains the meta data //assertThat( logLines.get( 1 ), containsString( "User: Johan" ) ); assertThat(logLines[2], containsString("User: '******'")); assertThat(logLines[3], containsString("User: '******'")); assertThat(logLines[4], containsString("User: '******'")); // we want to make sure that the new transaction does not carry old meta data assertThat(logLines[5], not(containsString("User: '******'"))); assertThat(logLines[6], containsString("Location: 'Sweden'")); }
public override Exception apply(S subject) { try { using (InternalTransaction tx = _outerInstance.neo.beginLocalTransactionAsUser(subject, _txType)) { Result result = null; try { if (_startEarly) { _outerInstance.latch.start(); } foreach (string query in _queries) { if (result != null) { result.Close(); } result = _outerInstance.neo.LocalGraph.execute(query); } if (!_startEarly) { _outerInstance.latch.startAndWaitForAllToStart(); } } finally { if (!_startEarly) { _outerInstance.latch.start(); } _outerInstance.latch.finishAndWaitForAllToFinish(); } result.Close(); tx.Success(); return(null); } } catch (Exception t) { return(t); } }