Beispiel #1
0
//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()));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCacheAuthorizationInfo() throws org.neo4j.kernel.api.security.exception.InvalidAuthTokenException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCacheAuthorizationInfo()
        {
            // Given
            EnterpriseLoginContext mike = _authManager.login(authToken("mike", "123"));

            mike.Authorize(_token, GraphDatabaseSettings.DEFAULT_DATABASE_NAME).mode().allowsReads();
            assertThat("Test realm did not receive a call", _testRealm.takeAuthorizationFlag(), @is(true));

            // When
            mike.Authorize(_token, GraphDatabaseSettings.DEFAULT_DATABASE_NAME).mode().allowsWrites();

            // Then
            assertThat("Test realm received a call", _testRealm.takeAuthorizationFlag(), @is(false));
        }
Beispiel #3
0
//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'"));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCacheAuthenticationInfo() throws org.neo4j.kernel.api.security.exception.InvalidAuthTokenException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCacheAuthenticationInfo()
        {
            // Given
            EnterpriseLoginContext mike = _authManager.login(authToken("mike", "123"));

            assertThat(mike.Subject().AuthenticationResult, equalTo(AuthenticationResult.SUCCESS));
            assertThat("Test realm did not receive a call", _testRealm.takeAuthenticationFlag(), @is(true));

            // When
            mike = _authManager.login(authToken("mike", "123"));
            assertThat(mike.Subject().AuthenticationResult, equalTo(AuthenticationResult.SUCCESS));

            // Then
            assertThat("Test realm did not receive a call", _testRealm.takeAuthenticationFlag(), @is(true));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInvalidateAuthorizationCacheAfterTTL() throws org.neo4j.kernel.api.security.exception.InvalidAuthTokenException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldInvalidateAuthorizationCacheAfterTTL()
        {
            // Given
            EnterpriseLoginContext mike = _authManager.login(authToken("mike", "123"));

            mike.Authorize(_token, GraphDatabaseSettings.DEFAULT_DATABASE_NAME).mode().allowsReads();
            assertThat("Test realm did not receive a call", _testRealm.takeAuthorizationFlag(), @is(true));

            // When
            _fakeTicker.advance(99, TimeUnit.MILLISECONDS);
            mike.Authorize(_token, GraphDatabaseSettings.DEFAULT_DATABASE_NAME).mode().allowsWrites();

            // Then
            assertThat("Test realm received a call", _testRealm.takeAuthorizationFlag(), @is(false));

            // When
            _fakeTicker.advance(2, TimeUnit.MILLISECONDS);
            mike.Authorize(_token, GraphDatabaseSettings.DEFAULT_DATABASE_NAME).mode().allowsWrites();

            // Then
            assertThat("Test realm did not received a call", _testRealm.takeAuthorizationFlag(), @is(true));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogCustomUserName() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogCustomUserName()
        {
            // turn on query logging
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<String, String> config = stringMap(logs_directory.name(), logsDirectory.getPath(), log_queries.name(), org.neo4j.kernel.configuration.Settings.TRUE);
            IDictionary <string, string> config = stringMap(logs_directory.name(), _logsDirectory.Path, log_queries.name(), Settings.TRUE);

            _db = new EmbeddedInteraction(_databaseBuilder, config);

            // create users
            _db.LocalUserManager.newUser("mats", password("neo4j"), false);
            _db.LocalUserManager.newUser("andres", password("neo4j"), false);
            _db.LocalUserManager.addRoleToUser("architect", "mats");
            _db.LocalUserManager.addRoleToUser("reader", "andres");

            EnterpriseLoginContext mats = _db.login("mats", "neo4j");

            // run query
            _db.executeQuery(mats, "UNWIND range(0, 10) AS i CREATE (:Foo {p: i})", Collections.emptyMap(), ResourceIterator.close);
            _db.executeQuery(mats, "CREATE (:Label)", Collections.emptyMap(), ResourceIterator.close);

            // switch user, run query
            EnterpriseLoginContext andres = _db.login("andres", "neo4j");

            _db.executeQuery(andres, "MATCH (n:Label) RETURN n", Collections.emptyMap(), ResourceIterator.close);

            _db.tearDown();

            // THEN
            IList <string> logLines = ReadAllLines(_logFilename);

            assertThat(logLines, hasSize(3));
            assertThat(logLines[0], containsString("mats"));
            assertThat(logLines[1], containsString("mats"));
            assertThat(logLines[2], containsString("andres"));
        }