コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static boolean processAuthentication(String userAgent, java.util.Map<String,Object> authToken, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        public static bool ProcessAuthentication(string userAgent, IDictionary <string, object> authToken, StateMachineContext context)
        {
            try
            {
                BoltStateMachineSPI boltSpi = context.BoltSpi();

                AuthenticationResult authResult = boltSpi.Authenticate(authToken);
                string username = authResult.LoginContext.subject().username();
                context.AuthenticatedAsUser(username, userAgent);

                StatementProcessor statementProcessor        = new TransactionStateMachine(boltSpi.TransactionSpi(), authResult, context.Clock());
                context.ConnectionState().StatementProcessor = statementProcessor;

                if (authResult.CredentialsExpired())
                {
                    context.ConnectionState().onMetadata("credentials_expired", Values.TRUE);
                }
                context.ConnectionState().onMetadata("server", Values.stringValue(boltSpi.Version()));
                boltSpi.UdcRegisterClient(userAgent);

                return(true);
            }
            catch (Exception t)
            {
                context.HandleFailure(t, true);
                return(false);
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.bolt.runtime.BoltStateMachineState processRunMessage(org.neo4j.bolt.v1.messaging.request.RunMessage message, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        private BoltStateMachineState ProcessRunMessage(RunMessage message, StateMachineContext context)
        {
            try
            {
                long start = context.Clock().millis();
                StatementMetadata statementMetadata = ProcessRunMessage(message, context.ConnectionState().StatementProcessor);
                long end = context.Clock().millis();

                context.ConnectionState().onMetadata("fields", stringArray(statementMetadata.FieldNames()));
                context.ConnectionState().onMetadata("result_available_after", Values.longValue(end - start));

                return(_streamingState);
            }
            catch (AuthorizationExpiredException e)
            {
                context.HandleFailure(e, true);
                return(_failedState);
            }
            catch (Exception t)
            {
                context.HandleFailure(t, false);
                return(_failedState);
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddServerVersionMetadataOnHelloMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldAddServerVersionMetadataOnHelloMessage()
        {
            // Given
            // hello message
            IDictionary <string, object> meta = map("user_agent", "3.0", PRINCIPAL, "neo4j", CREDENTIALS, "password");
            HelloMessage helloMessage         = new HelloMessage(meta);

            // setup state machine
            ConnectedState        state      = new ConnectedState();
            BoltStateMachineState readyState = mock(typeof(BoltStateMachineState));

            StateMachineContext    context         = mock(typeof(StateMachineContext));
            BoltStateMachineSPI    boltSpi         = mock(typeof(BoltStateMachineSPI), RETURNS_MOCKS);
            MutableConnectionState connectionState = new MutableConnectionState();

            state.ReadyState = readyState;

            when(context.BoltSpi()).thenReturn(boltSpi);
            when(context.ConnectionState()).thenReturn(connectionState);

            when(boltSpi.Version()).thenReturn("42.42.42");
            MutableConnectionState connectionStateMock = mock(typeof(MutableConnectionState));

            when(context.ConnectionState()).thenReturn(connectionStateMock);
            when(context.ConnectionId()).thenReturn("connection-uuid");

            when(boltSpi.Authenticate(meta)).thenReturn(AuthenticationResult.AUTH_DISABLED);

            // When
            BoltStateMachineState newState = state.Process(helloMessage, context);

            // Then
            assertEquals(readyState, newState);
            verify(connectionStateMock).onMetadata("server", stringValue("42.42.42"));
            verify(connectionStateMock).onMetadata(eq("connection_id"), any(typeof(StringValue)));
        }
コード例 #4
0
ファイル: StreamingState.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.bolt.runtime.BoltStateMachineState processStreamResultMessage(boolean pull, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        private BoltStateMachineState ProcessStreamResultMessage(bool pull, StateMachineContext context)
        {
            try
            {
                context.ConnectionState().StatementProcessor.streamResult(recordStream => context.ConnectionState().ResponseHandler.onRecords(recordStream, pull));

                return(_readyState);
            }
            catch (AuthorizationExpiredException e)
            {
                context.HandleFailure(e, true);
                return(_failedState);
            }
            catch (Exception e)
            {
                context.HandleFailure(e, false);
                return(_failedState);
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.bolt.runtime.BoltStateMachineState process(org.neo4j.bolt.messaging.RequestMessage message, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        public override BoltStateMachineState Process(RequestMessage message, StateMachineContext context)
        {
            AssertInitialized();
            if (message is HelloMessage)
            {
                HelloMessage helloMessage = ( HelloMessage )message;
                string       userAgent    = helloMessage.UserAgent();
                IDictionary <string, object> authToken = helloMessage.AuthToken();

                if (processAuthentication(userAgent, authToken, context))
                {
                    context.ConnectionState().onMetadata(CONNECTION_ID_KEY, Values.stringValue(context.ConnectionId()));
                    return(_readyState);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }