/// <summary> /// Returns true if the request is for a restricted path and the address is not allowed to access it. /// </summary> /// <param name="requestArgs"></param> /// <returns></returns> private bool IsRestricted(RequestReceivedEventArgs requestArgs) { var result = false; if (requestArgs.PathAndFile != null && requestArgs.Request != null && requestArgs.Request.RemoteEndPoint != null) { var path = requestArgs.PathAndFile.ToLower(); IAccessFilter filter = null; _RestrictedPathSpinLock.Lock(); try { for (var i = 0; i < _RestrictedPaths.Count; ++i) { var restrictedPath = _RestrictedPaths[i]; if (path.StartsWith(restrictedPath.NormalisedPath)) { filter = restrictedPath.Filter; break; } } } finally { _RestrictedPathSpinLock.Unlock(); } if (filter != null) { result = !filter.Allow(requestArgs.Request.RemoteEndPoint.Address); } } return(result); }
public void TestInitialise() { _Snapshot = Factory.TakeSnapshot(); _AccessConfiguration = TestUtilities.CreateMockSingleton <IAccessConfiguration>(); _Filter = Factory.Resolve <IAccessFilter>(); _Environment = new MockOwinEnvironment(); _Pipeline = new MockOwinPipeline(); }
/// <summary> /// Starts the passive mode listener. /// </summary> private void PassiveModeStartListening() { var inPassiveModeStartListening = false; lock (_SyncLock) { inPassiveModeStartListening = _InPassiveModeStartListening; if (!inPassiveModeStartListening) { _InPassiveModeStartListening = true; } } if (!inPassiveModeStartListening) { ConnectionStatus = ConnectionStatus.Connecting; var access = Access; _AccessFilter = access == null ? null : Factory.Singleton.Resolve <IAccessFilter>(); if (_AccessFilter != null) { _AccessFilter.Initialise(access); } Socket socket = null; try { while (socket == null && !_Closed) { try { socket = CreatePassiveModeListeningSocket(); ConnectionStatus = ConnectionStatus.Waiting; RecordMiscellaneousActivity("Listening for incoming connections on port {0}", Port); while (!_Closed) { using (var state = new SocketState(socket)) { socket.BeginAccept(PassiveModeAccept, state); while (!state.WaitHandle.WaitOne(250)) { if (_Closed) { break; } } } } } catch (Exception ex) { OnExceptionCaught(new EventArgs <Exception>(ex)); } if (socket == null && !_Closed) { PauseWhileTestingClosed(RetryConnectTimeout); } } } finally { AbandonAllConnections(); if (socket != null) { try { socket.Close(); ((IDisposable)socket).Dispose(); } catch { ; } } _InPassiveModeStartListening = false; ConnectionStatus = ConnectionStatus.Disconnected; } } }
public void TestInitialise() { _Filter = Factory.Resolve <IAccessFilter>(); _Access = new Access(); }