Beispiel #1
0
		private static string GetUserTenant(HttpContext context, string userToken)
		{
			string text = null;
			if (context.Request != null)
			{
				text = context.Request.Headers["msExchTargetTenant"];
			}
			if (string.IsNullOrEmpty(text))
			{
				FailFastModule.TryParseEmailDomain(userToken, out text);
			}
			return text;
		}
Beispiel #2
0
		static FailFastModule()
		{
			FailFastUserCache.IsPrimaryUserCache = true;
			bool flag = false;
			if (!bool.TryParse(ConfigurationManager.AppSettings["FailFastEnabled"], out flag))
			{
				flag = false;
			}
			FailFastUserCache.FailFastEnabled = flag;
			ExTraceGlobals.FailFastModuleTracer.Information<bool>(0L, "FailFast Enabled:", flag);
			Logger.LogEvent(TaskEventLogConstants.Tuple_LogFailFastEnabledFlag, null, new object[]
			{
				flag
			});
			FailFastModule.perfCounter = FailFastModule.CreatePerfCounter();
		}
Beispiel #3
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");
		}