コード例 #1
0
        // Token: 0x0600143B RID: 5179 RVA: 0x0004A334 File Offset: 0x00048534
        private static void SendAuthenticationDataToWinRM(HttpContext httpContext, UserToken userToken)
        {
            WinRMInfo winRMInfo = httpContext.Items["X-RemotePS-WinRMInfo"] as WinRMInfo;

            if (ProxySecurityContextModule.NeedSendDataToWinRM(winRMInfo))
            {
                userToken.UniformCommonAccessToken();
                if (winRMInfo != null && "New-PSSession".Equals(winRMInfo.Action, StringComparison.OrdinalIgnoreCase))
                {
                    HttpLogger.SafeAppendGenericInfo("WinRMCAT", userToken.GetReadableCommonAccessToken());
                }
                LatencyTracker latencyTracker = HttpContext.Current.Items["Logging-HttpRequest-Latency"] as LatencyTracker;
                using (WinRMDataSender winRMDataSender = new WinRMDataSender(httpContext, latencyTracker))
                {
                    winRMDataSender.SessionId = winRMInfo.FomattedSessionId;
                    if (HttpLogger.ActivityScope != null)
                    {
                        Guid activityId = HttpLogger.ActivityScope.ActivityId;
                        winRMDataSender.RequestId = HttpLogger.ActivityScope.ActivityId.ToString();
                    }
                    winRMDataSender.UserToken = userToken;
                    winRMDataSender.Send();
                }
            }
        }
コード例 #2
0
        private void OnAuthenticateRequest(object source, EventArgs e)
        {
            HttpContext httpContext = HttpContext.Current;

            if (!(httpContext.User.Identity is WindowsIdentity))
            {
                return;
            }
            WindowsIdentity windowsIdentity = (WindowsIdentity)httpContext.User.Identity;

            if (windowsIdentity.User == null)
            {
                string value = string.Format("UnExpected: WindowsIdentity.User = null, AuthNType = {0}, Name = {1}", windowsIdentity.AuthenticationType, windowsIdentity.Name);
                HttpLogger.SafeAppendGenericError("WindowsIdentityToGenericIdentityModule", value, true);
                HttpApplication httpApplication = (HttpApplication)source;
                httpContext.Response.StatusCode = 401;
                httpApplication.CompleteRequest();
                return;
            }
            ExAssert.RetailAssert(httpContext.User != null && httpContext.User.Identity != null && httpContext.User.Identity.Name != null, "HttpContext.User.Identity.Name should not be null.");
            GenericIdentity identity = new GenericIdentity(httpContext.User.Identity.Name.ToLower(), "Converted-" + httpContext.User.Identity.AuthenticationType);

            httpContext.User = new GenericPrincipal(identity, new string[0]);
            using (WinRMDataSender winRMDataSender = new WinRMDataSender(httpContext, null))
            {
                WinRMInfo winRMInfo = httpContext.Items["X-RemotePS-WinRMInfo"] as WinRMInfo;
                if (winRMInfo != null)
                {
                    winRMDataSender.SessionId = winRMInfo.FomattedSessionId;
                }
                winRMDataSender.RequestId = HttpLogger.ActivityScope.ActivityId.ToString();
                winRMDataSender.UserToken = new UserToken(AuthenticationType.Kerberos, null, null, windowsIdentity.Name, windowsIdentity.User, null, OrganizationId.ForestWideOrgId, null, false, new CommonAccessToken(windowsIdentity));
                winRMDataSender.Send();
            }
        }
コード例 #3
0
        private void ReviseAction(string funcName)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction <string>((long)this.GetHashCode(), "[PingDetectionModule::{0}] Enter", funcName);
            HttpContext  httpContext = HttpContext.Current;
            HttpResponse response    = httpContext.Response;

            if (response == null)
            {
                return;
            }
            if (httpContext.Items["ActionHasBeenRevised"] != null)
            {
                return;
            }
            httpContext.Items["ActionHasBeenRevised"] = "Y";
            WinRMInfo winRMInfoFromHttpHeaders = WinRMInfo.GetWinRMInfoFromHttpHeaders(httpContext.Request.Headers);
            string    text;

            if (WinRMRequestTracker.TryReviseAction(winRMInfoFromHttpHeaders, response.StatusCode, response.SubStatusCode, out text))
            {
                HttpLogger.SafeSetLogger(RpsHttpMetadata.Action, text);
                string headerValue = "Ping".Equals(text) ? "Ping" : "Non-Ping";
                this.SafeSetResponseHeader(response, "X-RemotePS-Ping", headerValue);
                this.SafeSetResponseHeader(response, "X-RemotePS-RevisedAction", text);
            }
            ExTraceGlobals.HttpModuleTracer.TraceFunction <string>((long)this.GetHashCode(), "[PingDetectionModule::{0}] Exit.", funcName);
        }
        // Token: 0x0600000C RID: 12 RVA: 0x000022C8 File Offset: 0x000004C8
        private void OnAuthenticateRequest(object source, EventArgs args)
        {
            Logger.EnterFunction(ExTraceGlobals.RemotePowershellBackendCmdletProxyModuleTracer, "OnAuthenticateOrPostAuthenticateRequest");
            HttpContext httpContext = HttpContext.Current;

            if (httpContext.Request.IsAuthenticated)
            {
                Logger.TraceDebug(ExTraceGlobals.RemotePowershellBackendCmdletProxyModuleTracer, "[RemotePowershellBackendCmdletProxyModule::OnAuthenticateOrPostAuthenticateRequest] Current authenticated user is {0} of type {1}.", new object[]
                {
                    httpContext.User.Identity,
                    httpContext.User.Identity.GetType()
                });
                string value = httpContext.Request.Headers["X-CommonAccessToken"];
                if (string.IsNullOrEmpty(value))
                {
                    Uri               url = httpContext.Request.Url;
                    Exception         ex  = null;
                    CommonAccessToken commonAccessToken = RemotePowershellBackendCmdletProxyModule.CommonAccessTokenFromUrl(httpContext.User.Identity.ToString(), url, out ex);
                    if (ex != null)
                    {
                        WinRMInfo.SetFailureCategoryInfo(httpContext.Response.Headers, FailureCategory.BackendCmdletProxy, ex.GetType().Name);
                        httpContext.Response.StatusCode = 500;
                        httpContext.ApplicationInstance.CompleteRequest();
                    }
                    else if (commonAccessToken != null)
                    {
                        httpContext.Request.Headers["X-CommonAccessToken"] = commonAccessToken.Serialize();
                        Logger.TraceDebug(ExTraceGlobals.RemotePowershellBackendCmdletProxyModuleTracer, "[RemotePowershellBackendCmdletProxyModule::OnAuthenticateOrPostAuthenticateRequest] The CommonAccessToken has been successfully stampped in request HTTP header.", new object[0]);
                    }
                }
            }
            Logger.ExitFunction(ExTraceGlobals.RemotePowershellBackendCmdletProxyModuleTracer, "OnAuthenticateOrPostAuthenticateRequest");
        }
コード例 #5
0
        internal static string GetDiagnosticsInfo(HttpContext context)
        {
            RequestDetailsLogger current = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(context);

            Guid           guid          = Guid.Empty;
            IActivityScope activityScope = null;

            if (current != null)
            {
                guid          = current.ActivityId;
                activityScope = current.ActivityScope;
            }
            string text = string.Format("[ClientAccessServer={0},BackEndServer={1},RequestId={2},TimeStamp={3}] ", new object[]
            {
                Environment.MachineName,
                (activityScope == null) ? "UnKown" : activityScope.GetProperty(HttpProxyMetadata.TargetServer),
                guid,
                DateTime.UtcNow
            });
            string text2 = string.Empty;

            if (context != null)
            {
                text2 = WinRMInfo.GetFailureCategoryInfo(context);
            }
            if (!string.IsNullOrEmpty(text2))
            {
                text += string.Format("[FailureCategory={0}] ", text2);
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[WinRMHelper::GetDiagnosticsInfo] diagnosticsInfo = {0}.", text);
            return(text);
        }
コード例 #6
0
        // Token: 0x060006F3 RID: 1779 RVA: 0x00028E60 File Offset: 0x00027060
        protected override void ExposeExceptionToClientResponse(Exception ex)
        {
            if (!WinRMHelper.FriendlyErrorEnabled.Value)
            {
                base.ExposeExceptionToClientResponse(ex);
                return;
            }
            if (ex is WebException)
            {
                WebException ex2 = (WebException)ex;
                if (WinRMHelper.IsPingRequest(ex2))
                {
                    if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::ExposeExceptionToClientResponse]: Context={0}, Ping found.", base.TraceContext);
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(base.Logger, 21, "Ping");

                    base.ClientResponse.Headers["X-RemotePS-Ping"] = "Ping";
                    return;
                }
                if (WinRMHelper.CouldBePingRequest(ex2))
                {
                    if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::ExposeExceptionToClientResponse]: Context={0}, Could be Ping request.", base.TraceContext);
                    }
                    base.ClientResponse.Headers["X-RemotePS-Ping"] = "Possible-Ping";
                    return;
                }
                if (ex2.Status != WebExceptionStatus.ProtocolError)
                {
                    WinRMInfo.SetFailureCategoryInfo(base.ClientResponse.Headers, 3, ex2.Status.ToString());
                }
                if (ex2.Response != null)
                {
                    string text = ex2.Response.Headers["X-BasicAuthToOAuthConversionDiagnostics"];
                    if (!string.IsNullOrWhiteSpace(text))
                    {
                        base.ClientResponse.Headers["X-BasicAuthToOAuthConversionDiagnostics"] = text + " ";
                    }
                }
            }
            if (ex is HttpProxyException && !string.IsNullOrWhiteSpace(ex.Message) && !WinRMHelper.DiagnosticsInfoHasBeenWritten(base.ClientResponse.Headers))
            {
                WinRMInfo.SetFailureCategoryInfo(base.ClientResponse.Headers, 3, ex.GetType().Name);
                string diagnosticsInfo = WinRMHelper.GetDiagnosticsInfo(base.HttpContext);
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int, string>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::ExposeExceptionToClientResponse]: Context={0}, Write Message {1} to client response.", base.TraceContext, ex.Message);
                }
                WinRMHelper.SetDiagnosticsInfoWrittenFlag(base.ClientResponse.Headers);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(base.Logger, "FriendlyError", "ExposeException");

                base.ClientResponse.Write(diagnosticsInfo + ex.Message);
                return;
            }
            base.ExposeExceptionToClientResponse(ex);
        }
コード例 #7
0
 // Token: 0x060006ED RID: 1773 RVA: 0x000287E3 File Offset: 0x000269E3
 protected override void ResetForRetryOnError()
 {
     if (base.ClientResponse != null && base.ClientResponse.Headers != null)
     {
         WinRMInfo.ClearFailureCategoryInfo(base.ClientResponse.Headers);
     }
     base.ResetForRetryOnError();
 }
コード例 #8
0
        // Token: 0x06001439 RID: 5177 RVA: 0x0004A0D8 File Offset: 0x000482D8
        private void OnAuthenticateRequest(object source, EventArgs e)
        {
            ExTraceGlobals.AccessCheckTracer.TraceDebug(0L, "Start OnAuthenticateRequest");
            HttpApplication httpApplication = (HttpApplication)source;
            HttpContext     context         = httpApplication.Context;
            UserToken       userToken       = context.CurrentUserToken();

            if (this.IsDelegatedAuth(context))
            {
                ExTraceGlobals.AccessCheckTracer.TraceDebug(0L, "Delegated auth, let delegated auth module handle the request");
            }
            else
            {
                if (context.Request.IsAuthenticated && userToken.HasCommonAccessToken)
                {
                    try
                    {
                        if (userToken.HasCommonAccessToken && ProxySecurityContextModule.AuthenticationTypes.ContainsKey(userToken.AuthenticationType))
                        {
                            string text = ProxySecurityContextModule.AuthenticationTypes[userToken.AuthenticationType];
                            if (context.User != null && context.User.Identity != null)
                            {
                                context.Items["AuthType"] = context.User.Identity.AuthenticationType;
                                if (!context.Items.Contains("AuthenticatedUser"))
                                {
                                    context.Items["AuthenticatedUser"] = context.User.Identity.Name;
                                }
                                else
                                {
                                    HttpLogger.SafeAppendGenericInfo("User.Identity", context.User.Identity.Name);
                                }
                            }
                            ExTraceGlobals.AccessCheckTracer.TraceDebug <AuthenticationType, string>(0L, "Token Type = {0}, AuthenticationType = {1}.", userToken.AuthenticationType, text);
                            ExAssert.RetailAssert(context.User != null && context.User.Identity != null && context.User.Identity.Name != null, "HttpContext.User.Identity.Name should not be null.");
                            GenericIdentity identity = new GenericIdentity(context.User.Identity.Name.ToLower(), text);
                            context.User = new GenericPrincipal(identity, new string[0]);
                            ProxySecurityContextModule.SendAuthenticationDataToWinRM(context, userToken);
                        }
                        goto IL_201;
                    }
                    catch (Exception ex)
                    {
                        HttpModuleHelper.EndPowerShellRequestWithFriendlyError(context, FailureCategory.ProxySecurityContext, "Exception", ex.ToString(), "ProxySecurityContextModule", KnownException.IsUnhandledException(ex));
                        goto IL_201;
                    }
                }
                ExTraceGlobals.AccessCheckTracer.TraceDebug(0L, "Request is Unauthorized.");
                WinRMInfo.SetFailureCategoryInfo(context.Response.Headers, FailureCategory.ProxySecurityContext, "Unauthorized");
                context.Response.StatusCode = 401;
                httpApplication.CompleteRequest();
            }
IL_201:
            ExTraceGlobals.AccessCheckTracer.TraceDebug(0L, "Exit OnAuthenticateRequest");
        }
コード例 #9
0
 // Token: 0x0600148C RID: 5260 RVA: 0x0004CC08 File Offset: 0x0004AE08
 internal static string GetIdentityForWinRMAPI(string originalIdentity, WinRMInfo winRMInfo)
 {
     if (winRMInfo == null || string.IsNullOrEmpty(winRMInfo.FomattedSessionId))
     {
         return(originalIdentity);
     }
     return(string.Concat(new object[]
     {
         "908C5F03-5125-46BF-8746-A47994D0DA77",
         winRMInfo.FomattedSessionId,
         ',',
         originalIdentity
     }));
 }
コード例 #10
0
ファイル: WinRMHelper.cs プロジェクト: happygitty/codediff
        // Token: 0x0600046E RID: 1134 RVA: 0x00018BF0 File Offset: 0x00016DF0
        internal static string GetDiagnosticsInfo(HttpContext context)
        {
            RequestDetailsLogger current = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(context);

            Guid           guid          = Guid.Empty;
            IActivityScope activityScope = null;

            if (current != null)
            {
                guid          = current.ActivityId;
                activityScope = current.ActivityScope;
            }
            string text = string.Format("[ClientAccessServer={0},BackEndServer={1},RequestId={2},TimeStamp={3}] ", new object[]
            {
                Environment.MachineName,
                (activityScope == null) ? "UnKnown" : activityScope.GetProperty(13),
                guid,
                DateTime.UtcNow
            });
            string text2 = string.Empty;

            if (context != null)
            {
                text2 = WinRMInfo.GetFailureCategoryInfo(context);
            }
            if (!string.IsNullOrEmpty(text2))
            {
                text += string.Format("[FailureCategory={0}] ", text2);
            }
            string text3 = context.Response.Headers["X-BasicAuthToOAuthConversionDiagnostics"];

            if (!string.IsNullOrWhiteSpace(text3))
            {
                text += string.Format("BasicAuthToOAuthConversionDiagnostics={0}", text3);
            }
            if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[WinRMHelper::GetDiagnosticsInfo] diagnosticsInfo = {0}.", text);
            }
            return(text);
        }
コード例 #11
0
        // Token: 0x06000380 RID: 896 RVA: 0x00013F04 File Offset: 0x00012104
        private bool TryGetUpdatedBufferToSend(ArraySegment <byte> buffer, out byte[] updatedBuffer, out string failureHint)
        {
            HttpContext context = base.RequestContext.HttpContext;

            updatedBuffer = null;
            failureHint   = null;
            if (context.Response == null)
            {
                failureHint = "Response Null";
                return(false);
            }
            int statusCode = context.Response.StatusCode;

            if (statusCode < 400)
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int, int>((long)this.GetHashCode(), "[RpsOutDataResponseStreamProxy::TryGetUpdatedBufferToSend] Context={0}, StatusCode={1}.", base.RequestContext.TraceContext, statusCode);
                }
                return(false);
            }
            if (WinRMHelper.DiagnosticsInfoHasBeenWritten(context.Response.Headers))
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[RpsOutDataResponseStreamProxy::TryGetUpdatedBufferToSend] Context={0}, diagnostics info has been written.", base.RequestContext.TraceContext);
                }
                failureHint = "BeenWritten";
                return(false);
            }
            if (WinRMHelper.TryInsertDiagnosticsInfo(buffer, () => WinRMHelper.GetDiagnosticsInfo(context), out updatedBuffer, out failureHint, delegate(string winRMFaultMessage)
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(this.RequestContext.Logger, "WinRMFaultMessage", winRMFaultMessage);
                WinRMInfo.SetWSManFailureCategory(context.Response.Headers, winRMFaultMessage);
            }))
            {
                WinRMHelper.SetDiagnosticsInfoWrittenFlag(context.Response.Headers);
                return(true);
            }
            return(false);
        }
コード例 #12
0
        private void OnEndRequest(object sender, EventArgs e)
        {
            HttpContext  context  = ((HttpApplication)sender).Context;
            HttpResponse response = context.Response;
            WinRMInfo    winRMInfoFromHttpHeaders = WinRMInfo.GetWinRMInfoFromHttpHeaders(context.Request.Headers);
            string       text = (winRMInfoFromHttpHeaders != null) ? winRMInfoFromHttpHeaders.SessionUniqueId : null;

            if (response == null || winRMInfoFromHttpHeaders == null || text == null)
            {
                return;
            }
            if ("Remove-PSSession".Equals(winRMInfoFromHttpHeaders.Action, StringComparison.OrdinalIgnoreCase))
            {
                RpsHttpDatabaseValidationModule.ActiveSessionCache.Remove(text);
                return;
            }
            if (response.StatusCode == 200 && !RpsHttpDatabaseValidationModule.ActiveSessionCache.Contains(text))
            {
                RpsHttpDatabaseValidationModule.ActiveSessionCache.TryInsertSliding(text, 0, RpsHttpDatabaseValidationModule.SlidingTimeSpanForActiveSession);
            }
        }
コード例 #13
0
        private void OnPostAuthenticateRequest(object sender, EventArgs e)
        {
            HttpContextBase context = new HttpContextWrapper(((HttpApplication)sender).Context);
            WinRMInfo       winRMInfoFromHttpHeaders = WinRMInfo.GetWinRMInfoFromHttpHeaders(context.Request.Headers);

            if (winRMInfoFromHttpHeaders != null)
            {
                string sessionUniqueId = winRMInfoFromHttpHeaders.SessionUniqueId;
                int    num             = 0;
                if (!string.IsNullOrEmpty(sessionUniqueId) && RpsHttpDatabaseValidationModule.ActiveSessionCache.TryGetValue(sessionUniqueId, out num))
                {
                    HttpLogger.SafeAppendGenericInfo("CachedSessionId", sessionUniqueId);
                    return;
                }
            }
            using (new MonitoredScope("RpsHttpDatabaseValidationModule", "RpsHttpDatabaseValidationModule", HttpModuleHelper.HttpPerfMonitors))
            {
                HttpDatabaseValidationHelper.ValidateHttpDatabaseHeader(context, delegate
                {
                }, delegate(string routingError)
                {
                    if (context.Request.Headers[WellKnownHeader.XCafeLastRetryHeaderKey] != null)
                    {
                        HttpLogger.SafeAppendGenericInfo("IgnoreRoutingError", "Cafe last retry");
                        return;
                    }
                    HttpLogger.SafeAppendGenericError("ServerRoutingError", routingError, false);
                    WinRMInfo.SetFailureCategoryInfo(context.Response.Headers, FailureCategory.DatabaseValidation, "ServerRoutingError");
                    this.SendErrorResponse(context, 555, 0, routingError, delegate(HttpResponseBase response)
                    {
                        response.Headers[WellKnownHeader.BEServerRoutingError] = routingError;
                    }, false);
                }, delegate
                {
                    HttpLogger.SafeAppendGenericError("InvalidMailboxDatabaseGuid", "Cannot Parse MailboxDatabaseGuid From Header", false);
                    WinRMInfo.SetFailureCategoryInfo(context.Response.Headers, FailureCategory.DatabaseValidation, "InvalidDatabaseGuid");
                    this.SendErrorResponse(context, 400, 0, "Invalid database guid", null, false);
                });
            }
        }
コード例 #14
0
        private static void ReportCustomError(HttpResponse response, HttpStatusCode status, int subStatus, string errorMessage)
        {
            Logger.LogVerbose("Reporting HTTP error: Status - {0}, SubStatus - {1}, Message - {2}", new object[]
            {
                status,
                subStatus,
                errorMessage
            });
            string fcSubInfo = "Unknown";

            if (subStatus != 102)
            {
                switch (subStatus)
                {
                case 200:
                    fcSubInfo = "UnknownInternalError";
                    break;

                case 201:
                    fcSubInfo = "TransientServerError";
                    break;
                }
            }
            else
            {
                fcSubInfo = "UserNotFound";
            }
            WinRMInfo.SetFailureCategoryInfo(response.Headers, FailureCategory.Certificate, fcSubInfo);
            response.Clear();
            response.StatusCode             = (int)status;
            response.SubStatusCode          = subStatus;
            response.ContentType            = "application/soap+xml;charset=UTF-8";
            response.TrySkipIisCustomErrors = true;
            if (!string.IsNullOrEmpty(errorMessage))
            {
                response.Write(errorMessage);
            }
            response.End();
        }
コード例 #15
0
 // Token: 0x060006EF RID: 1775 RVA: 0x00028A04 File Offset: 0x00026C04
 protected override bool ShouldCopyHeaderToServerRequest(string headerName)
 {
     return(!string.Equals(headerName, "X-RemotePS-GenericIdentity", StringComparison.OrdinalIgnoreCase) && !string.Equals(headerName, "X-RemotePS-WindowsIdentity", StringComparison.OrdinalIgnoreCase) && !string.Equals(headerName, "msExchCafeForceRouteToLogonAccount", StringComparison.OrdinalIgnoreCase) && !string.Equals(headerName, "X-DatabaseGuid", StringComparison.OrdinalIgnoreCase) && !string.Equals(headerName, "X-Cafe-Last-Retry", StringComparison.OrdinalIgnoreCase) && !WinRMInfo.IsHeaderReserverd(headerName) && base.ShouldCopyHeaderToServerRequest(headerName));
 }
コード例 #16
0
        // Token: 0x060000D4 RID: 212 RVA: 0x00005FE8 File Offset: 0x000041E8
        private void OnBeginRequest(object sender, EventArgs e)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[LoggingStartModule::OnBeginRequest] Enter");
            LatencyTracker latencyTracker = new LatencyTracker(Constants.IsPowerShellWebService ? "Psws.HttpModule" : "Rps.HttpModule", null);

            latencyTracker.Start();
            HttpContext         httpContext = HttpContext.Current;
            HttpRequest         request     = httpContext.Request;
            NameValueCollection headers     = httpContext.Request.Headers;

            httpContext.Items["Logging-HttpRequest-Latency"] = latencyTracker;
            HttpLogger.InitializeRequestLogger();
            if (HttpLogger.ActivityScope != null)
            {
                HttpLogger.ActivityScope.UpdateFromMessage(HttpContext.Current.Request);
                HttpLogger.ActivityScope.SerializeTo(HttpContext.Current.Response);
            }
            if (Constants.IsRemotePS && HttpLogger.ActivityScope != null && request.Url.Port == 444)
            {
                Uri url = request.Url;
                NameValueCollection urlProperties = url.GetUrlProperties();
                string text = urlProperties["RequestId48CD6591-0506-4D6E-9131-797489A3260F"];
                Guid   guid;
                if (text != null && Guid.TryParse(text, out guid))
                {
                    LoggerHelper.UpdateActivityScopeRequestIdFromUrl(url.ToString());
                }
            }
            HttpLogger.SafeSetLogger(ServiceCommonMetadata.HttpMethod, request.HttpMethod);
            WinRMInfo winRMInfoFromHttpHeaders = WinRMInfo.GetWinRMInfoFromHttpHeaders(headers);

            if (winRMInfoFromHttpHeaders != null)
            {
                HttpLogger.SafeSetLogger(RpsHttpMetadata.Action, winRMInfoFromHttpHeaders.Action);
                HttpLogger.SafeSetLogger(RpsCommonMetadata.SessionId, winRMInfoFromHttpHeaders.SessionId);
                HttpLogger.SafeSetLogger(RpsHttpMetadata.ShellId, winRMInfoFromHttpHeaders.ShellId);
                HttpLogger.SafeSetLogger(RpsHttpMetadata.CommandId, winRMInfoFromHttpHeaders.CommandId);
                HttpLogger.SafeSetLogger(RpsHttpMetadata.CommandName, winRMInfoFromHttpHeaders.CommandName);
                httpContext.Items["X-RemotePS-WinRMInfo"] = winRMInfoFromHttpHeaders;
            }
            string sourceCafeServer = CafeHelper.GetSourceCafeServer(request);

            if (sourceCafeServer != null)
            {
                HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.FrontEndServer, sourceCafeServer);
            }
            Uri url2 = request.Url;

            if (url2.IsAbsoluteUri)
            {
                HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.UrlHost, url2.DnsSafeHost);
                HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.UrlStem, url2.LocalPath);
                HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.UrlQuery, url2.Query);
            }
            else
            {
                HttpLogger.SafeAppendGenericError("InvalidRelativeUri", url2.ToString(), false);
            }
            NameValueCollection urlProperties2 = url2.GetUrlProperties();

            if (urlProperties2 != null)
            {
                string text2;
                if (!string.IsNullOrWhiteSpace(text2 = urlProperties2["Organization"]))
                {
                    HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.ManagedOrganization, text2);
                }
                else if (!string.IsNullOrWhiteSpace(text2 = urlProperties2["DelegatedOrg"]))
                {
                    HttpLogger.SafeSetLogger(ConfigurationCoreMetadata.ManagedOrganization, "Delegate:" + text2);
                }
            }
            if (HttpLogger.ActivityScope != null)
            {
                using (new MonitoredScope("RequestMonitor.Register", "RequestMonitor.Register", HttpModuleHelper.HttpPerfMonitors))
                {
                    RequestMonitor.Instance.RegisterRequest(HttpLogger.ActivityScope.ActivityId);
                    string text3 = headers[WellKnownHeader.WLIDMemberName] ?? headers[WellKnownHeader.LiveIdMemberName];
                    if (!string.IsNullOrEmpty(text3))
                    {
                        SmtpAddress smtpAddress = new SmtpAddress(text3);
                        RequestMonitor.Instance.Log(HttpLogger.ActivityScope.ActivityId, RequestMonitorMetadata.AuthenticatedUser, text3);
                        RequestMonitor.Instance.Log(HttpLogger.ActivityScope.ActivityId, RequestMonitorMetadata.Organization, smtpAddress.Domain);
                    }
                    RequestMonitor.Instance.Log(HttpLogger.ActivityScope.ActivityId, RequestMonitorMetadata.FrontEndServer, sourceCafeServer);
                    RequestMonitor.Instance.Log(HttpLogger.ActivityScope.ActivityId, RequestMonitorMetadata.ProtocolAction, HttpLogger.ActivityScope.GetProperty(RpsHttpMetadata.Action));
                }
            }
            ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[LoggingStartModule::OnBeginRequest] Exit");
        }
コード例 #17
0
        private void ThrottleRequest(HttpContext context)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Enter");
            WinRMInfo winRMInfo = context.Items["X-RemotePS-WinRMInfo"] as WinRMInfo;

            if (winRMInfo == null)
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo = null.");
                return;
            }
            string action = winRMInfo.Action;

            if (string.IsNullOrEmpty(action))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] WinRMInfo.Action = null.");
                return;
            }
            if (!action.EndsWith(":Command", StringComparison.OrdinalIgnoreCase) && !action.Equals("Command", StringComparison.OrdinalIgnoreCase))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <string>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Not Command Request. WinRMInfo.Action = {0}.", action);
                return;
            }
            IPowerShellBudget   powerShellBudget = null;
            OverBudgetException ex = null;

            try
            {
                try
                {
                    using (new MonitoredScope("ThrottlingHttpModule", "GetBudget", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget = this.GetBudget(context);
                    }
                    if (powerShellBudget == null)
                    {
                        ExTraceGlobals.HttpModuleTracer.TraceDebug((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] budget = null.");
                        return;
                    }
                    using (new MonitoredScope("ThrottlingHttpModule", "CheckBudgetAndStartCmdlet", HttpModuleHelper.HttpPerfMonitors))
                    {
                        powerShellBudget.StartCmdlet(null);
                        powerShellBudget.TryCheckOverBudget(CostType.CMDLET, out ex);
                    }
                }
                finally
                {
                    if (powerShellBudget != null)
                    {
                        powerShellBudget.Dispose();
                    }
                }
                if (ex != null)
                {
                    string windowsLiveId = context.CurrentUserToken().WindowsLiveId;
                    if (windowsLiveId != null)
                    {
                        FailFastUserCache.Instance.AddUserToCache(windowsLiveId, BlockedType.NewRequest, TimeSpan.Zero);
                        HttpLogger.SafeAppendColumn(RpsCommonMetadata.ContributeToFailFast, "AuthZ-UserSelf", LoggerHelper.GetContributeToFailFastValue("User", windowsLiveId, BlockedType.NewRequest.ToString(), -1.0));
                    }
                    HttpModuleHelper.EndPowerShellRequestWithFriendlyError(context, FailureCategory.AuthZ, ex.GetType().Name, Strings.ErrorOperationTarpitting(ex.BackoffTime / 1000) + string.Format("{2}Policy: {0}; {2}Snapshot: {1}", ex.ThrottlingPolicyDN, ex.Snapshot, Environment.NewLine), "ThrottlingHttpModule", false);
                }
            }
            catch (Exception ex2)
            {
                if (!(ex2 is ThreadAbortException))
                {
                    HttpLogger.SafeAppendGenericError("ThrottlingHttpModule", ex2, new Func <Exception, bool>(KnownException.IsUnhandledException));
                    ExTraceGlobals.HttpModuleTracer.TraceError <Exception>((long)this.GetHashCode(), "[ThrottlingHttpModule::ThrottleRequest] Get un-Excpected Exception. {0}", ex2);
                }
            }
        }
コード例 #18
0
        internal bool TryParseStream(Stream stream, out WinRMInfo winRMInfo, out string failureHint)
        {
            failureHint = null;
            winRMInfo   = null;
            if (stream == null)
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[WinRMParser::TryParseStream] Context={0}, stream = null.", this.TraceContext);
                failureHint = "Stream = null";
                return(false);
            }
            bool result;

            try
            {
                byte[] array = new byte[10000];
                int    num   = stream.Read(array, 0, array.Length);
                if (num <= 0)
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[WinRMParser::TryParseStream] Context={0}, bytesRead <= 0", this.TraceContext);
                    failureHint = "BytesRead <= 0";
                    result      = false;
                }
                else
                {
                    string @string     = Encoding.UTF8.GetString(array, 0, Math.Min(num, WinRMHelper.MaxBytesToPeekIntoRequestStream.Value));
                    string text        = null;
                    string text2       = null;
                    string text3       = null;
                    string text4       = null;
                    string commandName = null;
                    string text5       = null;
                    int    num2        = 0;
                    this.TryMatch(@string, WinRMParser.actionRegex, "action", ref num2, out text);
                    if (text == null)
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[WinRMParser::TryParseStream] No Action found in the input string", this.TraceContext);
                        failureHint = "RawAction = null";
                        result      = false;
                    }
                    else
                    {
                        this.TryMatch(@string, WinRMParser.sessionIdRegx, "sessionId", ref num2, out text2);
                        if (text2 == null)
                        {
                            ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[WinRMParser::TryParseStream] No SessionId found in the input string", this.TraceContext);
                        }
                        else if (text2.StartsWith("uuid:"))
                        {
                            text2 = text2.Substring(5);
                        }
                        this.TryMatch(@string, WinRMParser.shellIdRegx, "shellId", ref num2, out text3);
                        if (text3 == null && !"http://schemas.xmlsoap.org/ws/2004/09/transfer/Create".Equals(text, StringComparison.OrdinalIgnoreCase))
                        {
                            ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[WinRMParser::TryParseStream] No ShellId found in the input string and the current action is " + text, this.TraceContext);
                            failureHint = "ShellId = null";
                            result      = false;
                        }
                        else
                        {
                            this.TryMatch(@string, WinRMParser.commandIdRegx, "commandId", ref num2, out text4);
                            if (text4 != null)
                            {
                                this.TryMatch(@string, WinRMParser.commandNameRegx, "commandName", ref num2, out commandName);
                            }
                            if ("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Signal".Equals(text, StringComparison.OrdinalIgnoreCase))
                            {
                                this.TryMatch(@string, WinRMParser.signalCodeRegex, "signalCode", ref num2, out text5);
                            }
                            string text6 = this.GenerateUserFriendlyAction(text, text4, commandName, text5);
                            this.UpdateCommandIdToCommandNameCache(text, text4, commandName, text5);
                            ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[WinRMParser::TryParseStream] Context={0}, Action=\"{1}\", RawAction=\"{2}\", SessionId=\"{3}\", ShellId=\"{4}\", CommandId=\"{5}\", SignalCode=\"{6}\".", new object[]
                            {
                                this.TraceContext,
                                text6,
                                text,
                                text2,
                                text3,
                                text4,
                                text5
                            });
                            winRMInfo = new WinRMInfo
                            {
                                Action      = text6,
                                RawAction   = text,
                                SessionId   = text2,
                                ShellId     = text3,
                                CommandId   = text4,
                                CommandName = commandName,
                                SignalCode  = text5
                            };
                            result = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Diagnostics.ReportException(ex, FrontEndHttpProxyEventLogConstants.Tuple_InternalServerError, null, "Exception from WinRMParser::TryParseStream event: {0}");
                failureHint = ex.ToString();
                result      = false;
            }
            return(result);
        }
コード例 #19
0
 // Token: 0x0600143C RID: 5180 RVA: 0x0004A418 File Offset: 0x00048618
 private static bool NeedSendDataToWinRM(WinRMInfo winRMInfo)
 {
     return(winRMInfo == null || string.IsNullOrEmpty(winRMInfo.Action) || winRMInfo.Action.Equals("New-PSSession", StringComparison.OrdinalIgnoreCase));
 }
コード例 #20
0
        // Token: 0x060000F6 RID: 246 RVA: 0x00006C50 File Offset: 0x00004E50
        internal static bool TryReviseAction(WinRMInfo winRMInfo, int status, int subStatus, out string revisedAction)
        {
            ExTraceGlobals.HttpModuleTracer.TraceFunction(0L, "[WinRMRequestTracker::TryReviseAction] Enter");
            revisedAction = null;
            if (status == 500 && subStatus == 687)
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <int, int>(0L, "[WinRMRequestTracker::TryReviseAction] Ping detected. Status = {0} SubStatus = {1}", status, subStatus);
                revisedAction = "Ping";
                return(true);
            }
            if (winRMInfo == null)
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug(0L, "[WinRMRequestTracker::TryReviseAction] winRMInfo = null.");
                return(false);
            }
            string text = winRMInfo.SessionId ?? winRMInfo.ShellId;

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            string action = winRMInfo.Action;

            if ("Remove-PSSession".Equals(action))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <string>(0L, "[WinRMRequestTracker::TryReviseAction] End tracking session {0} in cache.", text);
                WinRMRequestTracker.SessionIdToStateCache.InsertSliding(text, 20, WinRMRequestTracker.SlidingTimeSpanAfterRemoveSession, null);
                return(false);
            }
            if ("New-PSSession".Equals(action) || ("Receive".Equals(action) && !WinRMRequestTracker.SessionIdToStateCache.Contains(text)))
            {
                ExTraceGlobals.HttpModuleTracer.TraceDebug <string>(0L, "[WinRMRequestTracker::TryReviseAction] Start tracking session {0} in cache.", text);
                WinRMRequestTracker.SessionIdToStateCache.InsertSliding(text, 0, WinRMRequestTracker.SlidingTimeSpan, null);
            }
            string commandId = winRMInfo.CommandId;

            if (!string.IsNullOrEmpty(commandId))
            {
                int num;
                if (WinRMRequestTracker.SessionIdToStateCache.TryGetValue(text, out num) && num != 10)
                {
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <string>(0L, "[WinRMRequestTracker::TryReviseAction] Change session {0} state to command in cache.", text);
                    WinRMRequestTracker.SessionIdToStateCache.InsertSliding(text, 10, WinRMRequestTracker.SlidingTimeSpan, null);
                }
                if (!string.IsNullOrEmpty(action) && action.EndsWith("Terminate"))
                {
                    bool   result = false;
                    string arg;
                    if ("Terminate".Equals(action) && WinRMRequestTracker.CommandIdToCommandNameCache.TryGetValue(commandId, out arg))
                    {
                        revisedAction = arg + ':' + "Terminate";
                        result        = true;
                    }
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <string>(0L, "[WinRMRequestTracker::TryReviseAction] End tracking command {0} in cache.", commandId);
                    WinRMRequestTracker.CommandIdToCommandNameCache.Remove(commandId);
                    return(result);
                }
                if (!string.IsNullOrEmpty(winRMInfo.CommandName) && !WinRMRequestTracker.CommandIdToCommandNameCache.Contains(commandId))
                {
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <string, string>(0L, "[WinRMRequestTracker::TryReviseAction] Start tracking command {0} - {1} in cache.", commandId, winRMInfo.CommandName);
                    WinRMRequestTracker.CommandIdToCommandNameCache.InsertSliding(commandId, winRMInfo.CommandName, WinRMRequestTracker.SlidingTimeSpan, null);
                }
                string str;
                if (("Receive".Equals(action) || "Command:Receive".Equals(action)) && WinRMRequestTracker.CommandIdToCommandNameCache.TryGetValue(commandId, out str))
                {
                    revisedAction = str + ":Receive";
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <string, string>(0L, "[WinRMRequestTracker::TryReviseAction] Revise action from {0} to {1}.", action, revisedAction);
                    return(true);
                }
                return(false);
            }
            else
            {
                int num2;
                if ("Receive".Equals(action) && status == 500 && WinRMRequestTracker.SessionIdToStateCache.TryGetValue(text, out num2) && num2 >= 10)
                {
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <int, int>(0L, "[WinRMRequestTracker::TryReviseAction] Ping detected. Status = {0}, curSessionState = {1}", status, num2);
                    revisedAction = "Ping";
                    if (num2 == 20)
                    {
                        ExTraceGlobals.HttpModuleTracer.TraceDebug <string>(0L, "[WinRMRequestTracker::TryReviseAction] Remove session state. sessionId = {1}", text);
                        WinRMRequestTracker.SessionIdToStateCache.Remove(text);
                    }
                    return(true);
                }
                int num3;
                if ("Receive".Equals(action) && WinRMRequestTracker.SessionIdToStateCache.TryGetValue(text, out num3) && num3 < 10 && num3 < 3)
                {
                    revisedAction = "New-PSSession:Receive";
                    num3++;
                    WinRMRequestTracker.SessionIdToStateCache.InsertSliding(text, num3, WinRMRequestTracker.SlidingTimeSpan, null);
                    ExTraceGlobals.HttpModuleTracer.TraceDebug <string, string, int>(0L, "[WinRMRequestTracker::TryReviseAction] Revise session from {0} to {1}. curSessionState = {2}", action, revisedAction, num3);
                    return(true);
                }
                return(false);
            }
        }
コード例 #21
0
        // Token: 0x060006EE RID: 1774 RVA: 0x00028810 File Offset: 0x00026A10
        protected override void AddProtocolSpecificHeadersToServerRequest(WebHeaderCollection headers)
        {
            if (base.ClientRequest.IsAuthenticated && base.ProxyToDownLevel)
            {
                IIdentity          callerIdentity     = this.GetCallerIdentity();
                WindowsIdentity    windowsIdentity    = callerIdentity as WindowsIdentity;
                GenericSidIdentity genericSidIdentity = callerIdentity as GenericSidIdentity;
                IPrincipal         user = base.HttpContext.User;
                if (windowsIdentity != null)
                {
                    string text;
                    if (HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text))
                    {
                        headers["X-RemotePS-GenericIdentity"] = windowsIdentity.User.ToString();
                    }
                    else
                    {
                        headers["X-RemotePS-WindowsIdentity"] = this.GetSerializedAccessTokenString();
                    }
                }
                else if (genericSidIdentity != null)
                {
                    headers["X-RemotePS-GenericIdentity"] = genericSidIdentity.Sid.ToString();
                }
                else
                {
                    headers["X-RemotePS-GenericIdentity"] = IIdentityExtensions.GetSafeName(base.HttpContext.User.Identity, true);
                }
            }
            if (this.isSyndicatedAdminManageDownLevelTarget)
            {
                headers["msExchCafeForceRouteToLogonAccount"] = "1";
            }
            if (LoggerHelper.IsProbePingRequest(base.ClientRequest))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(base.Logger, 21, "ProbePingBackend");
            }
            else if (WinRMHelper.WinRMParserEnabled.Value)
            {
                try
                {
                    this.winRMInfo = base.ParseClientRequest <WinRMInfo>(new Func <Stream, WinRMInfo>(this.ParseWinRMInfo), 10000);
                }
                catch (InvalidOperationException ex)
                {
                    if (ExTraceGlobals.ExceptionTracer.IsTraceEnabled(3))
                    {
                        ExTraceGlobals.ExceptionTracer.TraceError <InvalidOperationException>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::AddProtocolSpecificHeadersToServerRequest] ParseClientRequest throws exception {0}", ex);
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(base.Logger, "ParseClientRequestException", ex.ToString());
                }
                if (this.winRMInfo != null)
                {
                    WinRMInfo.StampToHttpHeaders(this.winRMInfo, headers);
                }
            }
            DatabaseBasedAnchorMailbox databaseBasedAnchorMailbox = base.AnchoredRoutingTarget.AnchorMailbox as DatabaseBasedAnchorMailbox;

            if (databaseBasedAnchorMailbox != null)
            {
                ADObjectId database = databaseBasedAnchorMailbox.GetDatabase();
                if (database != null)
                {
                    headers["X-DatabaseGuid"] = database.ObjectGuid.ToString();
                }
            }
            if (!base.ShouldRetryOnError)
            {
                headers["X-Cafe-Last-Retry"] = "Y";
            }
            base.AddProtocolSpecificHeadersToServerRequest(headers);
        }
コード例 #22
0
		private static void ApplicationBeginRequest(object sender, EventArgs e)
		{
			if (!FailFastUserCache.FailFastEnabled)
			{
				return;
			}
			Logger.EnterFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
			HttpApplication httpApplication = (HttpApplication)sender;
			HttpContext context = httpApplication.Context;
			string text = null;
			foreach (IUserTokenParser userTokenParser in FailFastModule.tokenParsers)
			{
				if (userTokenParser.TryParseUserToken(context, out text))
				{
					Logger.TraceInformation(ExTraceGlobals.FailFastModuleTracer, "{0} module parses the user token successfully. User token parsed: {1}.", new object[]
					{
						userTokenParser.GetType(),
						text
					});
					break;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "No usertoken is parsed, exit directly.", new object[0]);
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			if (context == null || context.Response == null)
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "context == null || context.Response == null", new object[0]);
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			context.Response.Headers[FailFastModule.headerKeyToStoreUserToken] = text;
			string userTenant = FailFastModule.GetUserTenant(context, text);
			Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Tenant for current user {0} is {1} (If not email domain, it is in Delegated scenario).", new object[]
			{
				text,
				userTenant
			});
			string text2;
			FailFastUserCacheValue failFastUserCacheValue;
			BlockedReason blockedReason;
			if (!FailFastUserCache.Instance.IsUserInCache(text, userTenant, out text2, out failFastUserCacheValue, out blockedReason))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is not handled by FailFastModule because it is not in FailFastUserCache.", new object[]
				{
					text
				});
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			if (!ConnectedUserManager.ShouldFailFastUserInCache(text, text2, failFastUserCacheValue, blockedReason))
			{
				Logger.TraceDebug(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is not considered to be FailFast case. CacheKey: {1}. CacheValue: {2}. BlockedReason {3}.", new object[]
				{
					text,
					text2,
					failFastUserCacheValue,
					blockedReason
				});
				Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
				return;
			}
			Logger.LogEvent(TaskEventLogConstants.Tuple_LogUserRequestIsFailed, text2, new object[]
			{
				text,
				text2,
				failFastUserCacheValue.ToString()
			});
			Logger.TraceError(ExTraceGlobals.FailFastModuleTracer, "Http request of User {0} is terminated in fail-fast module.", new object[]
			{
				text
			});
			FailFastModule.perfCounter.RequestsBeFailFasted.RawValue = FailFastModule.perfCounter.RequestsBeFailFasted.RawValue + 1L;
			HttpLogger.SafeSetLogger(RpsHttpMetadata.FailFast, string.Concat(new object[]
			{
				text,
				"+",
				blockedReason,
				"+",
				(failFastUserCacheValue == null) ? "Null" : failFastUserCacheValue.HitCount.ToString()
			}));
			ConnectedUserManager.RemoveUser(text);
			string responseErrorMessage = FailFastModule.GetResponseErrorMessage(blockedReason);
			context.Response.ContentType = "application/soap+xml;charset=UTF-8";
			context.Response.Write(responseErrorMessage);
			context.Response.StatusCode = 400;
			context.Response.SubStatusCode = 350;
			context.Response.TrySkipIisCustomErrors = true;
			WinRMInfo.SetFailureCategoryInfo(context.Response.Headers, FailureCategory.FailFast, blockedReason.ToString());
			Logger.TraceInformation(ExTraceGlobals.FailFastModuleTracer, "Sending 400.350 to the client.", new object[0]);
			context.Response.End();
			Logger.ExitFunction(ExTraceGlobals.FailFastModuleTracer, "FailFastModule.ApplicationBeginRequest");
		}