Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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)));
        }