//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); } }
public BoltStateMachineV1Context(BoltStateMachine machine, BoltChannel boltChannel, BoltStateMachineSPI spi, MutableConnectionState connectionState, Clock clock) { this._machine = machine; this._boltChannel = boltChannel; this._spi = spi; this._connectionState = connectionState; this._clock = clock; }
public BoltStateMachineV1(BoltStateMachineSPI spi, BoltChannel boltChannel, Clock clock) { this._id = boltChannel.Id(); this._boltChannel = boltChannel; this._spi = spi; this.ConnectionStateConflict = new MutableConnectionState(); this._context = new BoltStateMachineV1Context(this, boltChannel, spi, ConnectionStateConflict, clock); States states = BuildStates(); this._state = states.Initial; this._failedState = states.Failed; }
//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))); }
private static BoltStateMachineV1Context NewContext(BoltStateMachine machine, BoltStateMachineSPI boltSPI) { BoltChannel boltChannel = new BoltChannel("bolt-1", "bolt", mock(typeof(Channel))); return(new BoltStateMachineV1Context(machine, boltChannel, boltSPI, new MutableConnectionState(), Clock.systemUTC())); }