Exemplo n.º 1
0
        /// <summary>
        /// Один проход обработки. Диспетчер блокирует очередь от других
        /// потоков на время просмотра заявок.
        /// </summary>
        private void CheckRequests()
        {
            lock (_requests)
            {
                //Если очередь заявок пуста, дополнительные действия не требуются
                if (_requests.Count == 0)
                {
                    return;
                }

                //Иначе достаём из очереди заявку и отправляем её на обработку в отделения
                var request = _requests.Dequeue();
                if (_departments.HandleRequest(request))
                {
                    ContextProvider.GetInstance().Context.Send(obj => RequestProcessed?.Invoke(obj as Request), request);
                    RequestCounter++;
                }
                else
                {
                    //Если обработать не получилось (соответствующее заявке отделение занято),
                    //заявка уходит обратно в очередь
                    ContextProvider.GetInstance().Context.Send(obj => RequestPostponed?.Invoke(obj as Request), request);
                    _requests.Enqueue(request);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The fiddler application on before request.
        /// </summary>
        /// <param name="session">
        /// The session.
        /// </param>
        private static void FiddlerApplicationOnBeforeRequest(Session session)
        {
            // Autopilot.Logger.WriteDebug("Proxy Request PID:{1} {0}", oSession.host, oSession.LocalProcessID);
            if (session.oRequest.headers["Accept"] != null &&
                session.oRequest.headers["Accept"].ContainsAnyOi(ResponseContentTypeFilter))
            {
                session.bBufferResponse = true;
            }

            if (InstanceHeaders.ContainsKey(session.LocalProcessID))
            {
                foreach (var header in InstanceHeaders[session.LocalProcessID].ToList())
                {
                    if (session.bBufferResponse)
                    {
                        // This is a "page" class of request, apply all overrides.
                        session.oRequest[header.Key] = header.Value;
                    }
                    else if (!session.bBufferResponse &&
                             (header.Key.EqualsOi("User-Agent") || header.Key.EqualsOi("Accept-Language")))
                    {
                        // This is a secondary (e.g image or script) request, only override certain headers
                        session.oRequest[header.Key] = header.Value;
                    }
                }
            }

            foreach (var header in HeaderPairs)
            {
                session.oRequest[header.Key] = header.Value;
            }

            RequestProcessed?.Invoke(session.host);
        }
Exemplo n.º 3
0
        public HouseManagement()
        {
            _requests = new Queue <Request>();

            _departments = CreateDepartments();
            _departments.Subscribe((request, employee) => RequestFinished?.Invoke(request, employee));

            _committee = new RequestCommittee(_requests);
            _committee.RequestAdded += request => RequestAdded?.Invoke(request);

            _dispatcher = new Dispatcher(_departments, _requests);
            _dispatcher.RequestProcessed   += request => RequestProcessed?.Invoke(request);
            _dispatcher.RequestPostponed   += request => RequestPostponed?.Invoke(request);
            _dispatcher.SimulationFinished += () => SimulationFinished?.Invoke();
        }
Exemplo n.º 4
0
        public async Task HandleRequest(PendingRequest request, ClientConfiguration clientConfig)
        {
            try
            {
                if (request.RequestPacket.Code == PacketCode.StatusServer)
                {
                    //status
                    var uptime = (DateTime.Now - _startedAt);
                    request.ReplyMessage = $"Server up {uptime.Days} days {uptime.ToString("hh\\:mm\\:ss")}";
                    request.ResponseCode = PacketCode.AccessAccept;
                    RequestProcessed?.Invoke(this, request);
                    return;
                }

                if (request.RequestPacket.Code != PacketCode.AccessRequest)
                {
                    _logger.Warning("Unprocessable packet type: {code}", request.RequestPacket.Code);
                    return;
                }

                if (request.RequestPacket.Attributes.ContainsKey("State")) //Access-Challenge response
                {
                    var receivedState = request.RequestPacket.GetString("State");

                    if (_stateChallengePendingRequests.ContainsKey(receivedState))
                    {
                        //second request with Multifactor challenge
                        request.ResponseCode = await ProcessChallenge(request, clientConfig, receivedState);

                        request.State = receivedState;  //state for Access-Challenge message if otp is wrong (3 times allowed)

                        RequestProcessed?.Invoke(this, request);
                        return; //stop authentication process after otp code verification
                    }
                }

                var firstFactorAuthenticationResultCode = await ProcessFirstAuthenticationFactor(request, clientConfig);

                if (firstFactorAuthenticationResultCode != PacketCode.AccessAccept)
                {
                    //first factor authentication rejected
                    request.ResponseCode = firstFactorAuthenticationResultCode;
                    RequestProcessed?.Invoke(this, request);

                    //stop authencation process
                    return;
                }

                if (request.Bypass2Fa)
                {
                    //second factor not trquired
                    var userName = request.RequestPacket.UserName;
                    _logger.Information("Bypass second factor for user '{user:l}'", userName);

                    request.ResponseCode = PacketCode.AccessAccept;
                    RequestProcessed?.Invoke(this, request);

                    //stop authencation process
                    return;
                }

                var secondFactorAuthenticationResultCode = await ProcessSecondAuthenticationFactor(request, clientConfig);

                request.ResponseCode = secondFactorAuthenticationResultCode;

                if (request.ResponseCode == PacketCode.AccessChallenge)
                {
                    AddStateChallengePendingRequest(request.State, request);
                }

                RequestProcessed?.Invoke(this, request);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "HandleRequest");
            }
        }
Exemplo n.º 5
0
        public void HandleRequest(PendingRequest request)
        {
            try
            {
                if (request.RequestPacket.Code != PacketCode.AccessRequest)
                {
                    _logger.Warning($"Unprocessable packet type: {request.RequestPacket.Code}");
                    return;
                }

                if (request.RequestPacket.Attributes.ContainsKey("State")) //Access-Challenge response
                {
                    var receivedState = request.RequestPacket.GetString("State");

                    if (_stateChallengePendingRequests.ContainsKey(receivedState))
                    {
                        //second request with Multifactor challenge
                        request.ResponseCode = ProcessChallenge(request, receivedState);
                        request.State        = receivedState; //state for Access-Challenge message if otp is wrong (3 times allowed)

                        RequestProcessed?.Invoke(this, request);
                        return; //stop authentication process after otp code verification
                    }
                }

                var firstFactorAuthenticationResultCode = ProcessFirstAuthenticationFactor(request);
                if (firstFactorAuthenticationResultCode != PacketCode.AccessAccept)
                {
                    //first factor authentication rejected
                    request.ResponseCode = firstFactorAuthenticationResultCode;
                    RequestProcessed?.Invoke(this, request);

                    //stop authencation process
                    return;
                }

                if (request.Bypass2Fa)
                {
                    //second factor not trquired
                    var userName = request.RequestPacket.UserName;
                    _logger.Information($"Bypass second factor for user {userName}");

                    request.ResponseCode = PacketCode.AccessAccept;
                    RequestProcessed?.Invoke(this, request);

                    //stop authencation process
                    return;
                }

                var secondFactorAuthenticationResultCode = ProcessSecondAuthenticationFactor(request);

                request.ResponseCode = secondFactorAuthenticationResultCode;

                if (request.ResponseCode == PacketCode.AccessChallenge)
                {
                    AddStateChallengePendingRequest(request.State, request);
                }

                RequestProcessed?.Invoke(this, request);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "HandleRequest");
            }
        }