private static DispatchStepResult SendAppCacheRedirect(RequestContext requestContext, Uri originalUri) { HttpContext httpContext = requestContext.HttpContext; HttpApplication applicationInstance = httpContext.ApplicationInstance; string explicitLogonUser = UserContextUtilities.GetExplicitLogonUser(httpContext); if (string.IsNullOrEmpty(explicitLogonUser)) { RequestDispatcher.BindDefaultForceAppcacheCookieToSession(applicationInstance, httpContext); if (RequestDispatcher.RedirectBecauseClientForgotTrailingSlashOnRoot(applicationInstance, httpContext, originalUri)) { ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::SendAppCacheRedirect] OwaModule redirected because client forgot the trailing slash on the root and that's in the appcache."); return(DispatchStepResult.Stop); } if (RequestDispatcher.RedirectBecauseClientRequestedOwaRootSlashRealm(applicationInstance, httpContext, originalUri)) { ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::SendAppCacheRedirect] OwaModule redirected because the client requested /realm and that's in the appcache."); return(DispatchStepResult.Stop); } if (RequestDispatcher.RedirectBecauseClientRequestedWebsiteRoot(applicationInstance, httpContext, originalUri)) { ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::SendAppCacheRedirect] OwaModule redirected because the client requested the website root and that's in the appcache."); return(DispatchStepResult.Stop); } if (RequestDispatcher.RedirectBecauseIE10RequiresReloadFromAppcache(applicationInstance, httpContext, originalUri)) { ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::SendAppCacheRedirect] OwaModule told IE10 to reload so it can use the appcache."); return(DispatchStepResult.Stop); } } return(DispatchStepResult.Continue); }
// Token: 0x06000594 RID: 1428 RVA: 0x00010BA4 File Offset: 0x0000EDA4 internal static CallContext CreateAndSetCallContext(Message request, WorkloadType workloadType, bool duplicatedActionDetectionEnabled, string owaUserContextKey = "") { CallContext callContext = CallContextUtilities.CreateCallContext(request, null, duplicatedActionDetectionEnabled, owaUserContextKey); callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current); callContext.WorkloadType = workloadType; CallContext.SetCurrent(callContext); return(callContext); }
private static UserContextKey GetUserContextKey(HttpContext httpContext, ClientSecurityContext overrideClientSecurityContext, out UserContextCookie userContextCookie) { UserContextKey userContextKey = null; string explicitLogonUser = UserContextUtilities.GetExplicitLogonUser(httpContext); if (string.IsNullOrEmpty(explicitLogonUser)) { userContextCookie = UserContextCookie.GetUserContextCookie(httpContext); if (userContextCookie != null) { ExTraceGlobals.UserContextCallTracer.TraceDebug <UserContextCookie>(0L, "Found cookie in the request: {0}", userContextCookie); if (overrideClientSecurityContext == null) { userContextKey = UserContextKey.CreateFromCookie(userContextCookie, httpContext); } else { userContextKey = UserContextKey.CreateFromCookie(userContextCookie, overrideClientSecurityContext.UserSid); } } } else { userContextCookie = null; if (UserContextManager.RequestRequiresSharedContext(httpContext)) { userContextKey = UserContextKey.Create("D894745CADD64DB9B00309200288E1E7", "SharedAdmin", explicitLogonUser); } else { SecurityIdentifier securityIdentifier = httpContext.User.Identity.GetSecurityIdentifier(); if (securityIdentifier == null) { ExTraceGlobals.UserContextCallTracer.TraceDebug <IIdentity>(0L, "UserContextManager.GetUserContextKey: current user has no security identifier - '{0}'", httpContext.User.Identity); ExWatson.SendReport(new InvalidOperationException(string.Format("UserContextManager.GetUserContextKey: current user has no security identifier - '{0}'", httpContext.User.Identity)), ReportOptions.None, null); return(null); } string logonUniqueKey = securityIdentifier.ToString(); string text = httpContext.Request.Headers["X-OWA-Test-ExplicitLogonUserId"]; if (string.IsNullOrEmpty(text) || !AppConfigLoader.GetConfigBoolValue("Test_OwaAllowHeaderOverride", false)) { text = "B387FD19C8C4416694EB79909BED70B5"; } userContextKey = UserContextKey.Create(text, logonUniqueKey, explicitLogonUser); ExTraceGlobals.UserContextCallTracer.TraceDebug <UserContextKey>(0L, "Cookie not found but this is explicit logon. Generated Key: {0}", userContextKey); } } return(userContextKey); }
// Token: 0x06000793 RID: 1939 RVA: 0x0001834C File Offset: 0x0001654C internal static UserContextCookie GetUserContextCookie(HttpContext httpContext) { HttpRequest request = httpContext.Request; for (int i = 0; i < request.Cookies.Count; i++) { HttpCookie httpCookie = request.Cookies[i]; if (httpCookie.Name != null && httpCookie.Name.StartsWith(UserContextCookie.UserContextCookiePrefix, StringComparison.OrdinalIgnoreCase)) { UserContextCookie userContextCookie = UserContextCookie.TryCreateFromHttpCookie(httpCookie); if (userContextCookie == null) { ExTraceGlobals.UserContextTracer.TraceDebug <string, string, string>(0L, "Invalid user context cookie received. Name={0}, Value={1}, httpContext.Request.RawUrl={2}", httpCookie.Name, httpCookie.Value, request.RawUrl); return(null); } if (userContextCookie.MailboxUniqueKey == null) { if (!UserContextUtilities.IsDifferentMailbox(httpContext)) { return(userContextCookie); } } else { string explicitLogonUser = UserContextUtilities.GetExplicitLogonUser(httpContext); if (!string.IsNullOrEmpty(explicitLogonUser)) { using (OwaIdentity owaIdentity = OwaIdentity.CreateOwaIdentityFromExplicitLogonAddress(explicitLogonUser)) { if (string.Equals(userContextCookie.MailboxUniqueKey, owaIdentity.UniqueId, StringComparison.Ordinal)) { return(userContextCookie); } } } } } } return(null); }
private object InternalAfterReceiveRequest(ref Message request, RequestDetailsLogger logger) { try { Globals.UpdateErrorTracingConfiguration(); IActivityScope activityScope = OwaApplication.GetRequestDetailsLogger.ActivityScope; HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; string value = httpRequestMessageProperty.Headers[OWADispatchOperationSelector.Action]; activityScope.SetProperty(ExtensibleLoggerMetadata.EventId, value); string value2 = httpRequestMessageProperty.Headers["X-OWA-ClientBuildVersion"]; if (!string.IsNullOrEmpty(value2)) { activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, value2); } else { activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, "NA"); } string value3 = httpRequestMessageProperty.Headers["X-EWS-TargetVersion"]; if (!string.IsNullOrEmpty(value3)) { activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, value3); } else { activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, "NA"); } JsonMessageHeaderProcessor jsonMessageHeaderProcessor = new JsonMessageHeaderProcessor(); string methodName = OWAMessageInspector.GetMethodName(request); bool flag = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName); bool flag2 = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName); bool flag3 = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName); if (flag || flag2 || flag3) { using (MessageBuffer messageBuffer = request.CreateBufferedCopy(int.MaxValue)) { Message request2 = messageBuffer.CreateMessage(); if (flag) { jsonMessageHeaderProcessor.ProcessMessageHeaders(request2); jsonMessageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(request); } else if (flag2) { jsonMessageHeaderProcessor.ProcessMessageHeadersFromQueryString(request2); } else if (flag3) { jsonMessageHeaderProcessor.ProcessHttpHeaders(request, ExchangeVersion.Exchange2013); } request = messageBuffer.CreateMessage(); } } request.Properties["MessageHeaderProcessor"] = jsonMessageHeaderProcessor; request.Properties["ConnectionCostType"] = 0; WebMethodEntry jsonWebMethodEntry; if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry)) { jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry; } request.Properties["WebMethodEntry"] = jsonWebMethodEntry; MessageHeaderProcessor messageHeaderProcessor = (MessageHeaderProcessor)request.Properties["MessageHeaderProcessor"]; messageHeaderProcessor.MarkMessageHeaderAsUnderstoodIfExists(request, "RequestServerVersion", "http://schemas.microsoft.com/exchange/services/2006/types"); RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitBegin); Message requestRef = request; CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(requestRef, messageHeaderProcessor, true, "")); RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitEnd); callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0); bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request)); if (flag4 != null) { callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0); } callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current); if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser)) { OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext); OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext); OWAMessageInspector.CheckClientVersion(callContext); OWAMessageInspector.CheckMowaDisabled(callContext); OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext); } OWAMessageInspector.MarkResponseNonCacheable(methodName); callContext.WorkloadType = WorkloadType.Owa; callContext.UsingWcfDispatcher = true; callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 1); if (ExchangeVersion.Current == ExchangeVersion.Exchange2007) { ExchangeVersion.Current = ExchangeVersion.Exchange2013; } if (OWAMessageInspector.ShouldCreateUserContext(callContext)) { UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext; if (userContext != null) { callContext.OwaCulture = userContext.UserCulture; if (userContext.FeaturesManager != null) { callContext.FeaturesManager = userContext.FeaturesManager; if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled) { callContext.OwaUserContextKey = userContext.Key.ToString(); } } } } } catch (LocalizedException ex) { Microsoft.Exchange.Diagnostics.Components.Services.ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, string>((long)this.GetHashCode(), "[OWAMessageInspector::AfterReceiveRequest] Caught localized exception trying to create callcontext. Class: {0}, Message: {1}", ex.GetType().FullName, ex.Message); OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex))); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException"); throw OwaFaultExceptionUtilities.CreateFault(ex); } return(null); }
private static void CreateUserContext(HttpContext httpContext, UserContextKey userContextKey, AuthZClientInfo effectiveCaller, out IMailboxContext userContext, out UserContextStatistics userContextStats) { Stopwatch stopwatch = Stopwatch.StartNew(); userContextStats = new UserContextStatistics(); userContext = null; OwaIdentity owaIdentity = null; OwaIdentity owaIdentity2 = null; OwaIdentity owaIdentity3 = null; try { try { OwaIdentity owaIdentity4 = OwaIdentity.ResolveLogonIdentity(httpContext, effectiveCaller); owaIdentity2 = owaIdentity4; string explicitLogonUser = UserContextUtilities.GetExplicitLogonUser(httpContext); if (!string.IsNullOrEmpty(explicitLogonUser)) { ExTraceGlobals.UserContextTracer.TraceDebug <string>(0L, "Created partial mailbox identity from SMTP address={0}", explicitLogonUser); owaIdentity = OwaIdentity.CreateOwaIdentityFromExplicitLogonAddress(explicitLogonUser); owaIdentity3 = owaIdentity; } if (userContextKey == null) { userContextKey = UserContextKey.CreateNew(owaIdentity4, owaIdentity, httpContext); ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "Creating new user context key: {0}", userContextKey); } else { ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "Reusing user context key: {0}", userContextKey); } OwaRWLockWrapper userContextKeyLock = UserContextManager.GetUserContextKeyLock(userContextKey.ToString()); if (userContextKeyLock == null) { userContextStats.Error = UserContextCreationError.UnableToAcquireOwaRWLock; throw new OwaLockException("UserContextManger::CreateUserContext was not able to create a lock"); } if (userContextKeyLock.LockWriterElastic(6000)) { try { userContext = UserContextManager.GetMailboxContextFromCache(userContextKey, false); if (userContext != null && userContext.TerminationStatus == UserContextTerminationStatus.TerminatePending) { UserContextManager.TerminateSession(userContext, userContext.AbandonedReason); userContext = null; } if (userContext == null) { userContextStats.Created = true; ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "User context was not found in the cache, creating one. UserContextKey: {0}", userContextKey); bool flag = false; try { if (UserContextManager.IsSharedContextKey(userContextKey)) { userContext = new SharedContext(userContextKey, httpContext.Request.UserAgent); } else { userContext = new UserContext(userContextKey, httpContext.Request.UserAgent); } Stopwatch stopwatch2 = Stopwatch.StartNew(); userContext.Load(owaIdentity4, owaIdentity, userContextStats); userContextStats.LoadTime = (int)stopwatch2.ElapsedMilliseconds; UserContextManager.InsertIntoCache(httpContext, userContext); owaIdentity2 = null; owaIdentity3 = null; string userName = userContext.LogonIdentity.UserSid.ToString(); PerformanceCounterManager.UpdatePerfCounteronUserContextCreation(userName, false, false, Globals.ArePerfCountersEnabled); flag = true; } finally { if (!flag) { ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "User context creation failed. UserContextKey: {0}", userContextKey); if (userContext != null) { ExTraceGlobals.UserContextTracer.TraceDebug <UserContextKey>(0L, "Disposing user context. UserContextKey: {0}", userContextKey); userContext.Dispose(); userContext.State = UserContextState.Abandoned; } } } } goto IL_1EA; } finally { userContextKeyLock.ReleaseWriterLock(); } goto IL_1D4; IL_1EA: goto IL_237; } IL_1D4: userContextStats.Error = UserContextCreationError.UnableToAcquireOwaRWLock; throw new OwaLockTimeoutException("UserContextManger::CreateUserContext was not able to acquire a rw lock", null, null); } catch (OwaIdentityException ex) { userContextStats.Error = UserContextCreationError.UnableToResolveLogonIdentity; OwaServerTraceLogger.AppendToLog(new TraceLogEvent("UserContext", userContext, "UserContextManager.CreateUserContext", ex.ToString())); throw; } catch (Exception ex2) { OwaServerTraceLogger.AppendToLog(new TraceLogEvent("UserContext", userContext, "UserContextManager.CreateUserContext", ex2.ToString())); throw; } IL_237 :; } finally { if (owaIdentity2 != null) { owaIdentity2.Dispose(); } if (owaIdentity3 != null) { owaIdentity3.Dispose(); } stopwatch.Stop(); userContextStats.AcquireLatency = (int)stopwatch.ElapsedMilliseconds; httpContext.Items["UserContextStatistics"] = userContextStats; } }
private void InternalAfterReceiveRequest(HttpRequest httpRequest, string methodName, object request) { try { ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] called for method name: {0}", methodName); CallContext.ClearCallContextForCurrentThread(); Globals.UpdateErrorTracingConfiguration(); OwaApplication.GetRequestDetailsLogger.ActivityScope.SetProperty(ExtensibleLoggerMetadata.EventId, methodName); OwaServiceMessage message = new OwaServiceMessage(httpRequest, request); message.Headers.Action = methodName; message.Properties["HttpOperationName"] = methodName; OwaMessageHeaderProcessor messageHeaderProcessor = new OwaMessageHeaderProcessor(); bool flag = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName); bool flag2 = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName); bool flag3 = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName); ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] processing message headers"); if (flag || flag2 || flag3) { if (flag) { messageHeaderProcessor.ProcessMessageHeaders(message); messageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(message); } else if (flag2) { messageHeaderProcessor.ProcessMessageHeadersFromQueryString(message); } else if (flag3) { messageHeaderProcessor.ProcessHttpHeaders(message, ExchangeVersion.Exchange2013); } } message.Properties["MessageHeaderProcessor"] = messageHeaderProcessor; message.Properties["ConnectionCostType"] = 0; WebMethodEntry jsonWebMethodEntry; if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry)) { jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry; } message.Properties["WebMethodEntry"] = jsonWebMethodEntry; ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] creating CallContext"); CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(message, messageHeaderProcessor, true, "")); callContext.IsOwa = true; ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] CallContext created"); callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0); bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request)); if (flag4 != null) { callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0); } callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current); if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser)) { OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext); OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext); OWAMessageInspector.CheckClientVersion(callContext); OWAMessageInspector.CheckMowaDisabled(callContext); OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext); } OWAMessageInspector.MarkResponseNonCacheable(methodName); callContext.WorkloadType = WorkloadType.Owa; callContext.UsingWcfDispatcher = false; callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 0); if (ExchangeVersion.Current == ExchangeVersion.Exchange2007) { ExchangeVersion.Current = ExchangeVersion.Exchange2013; } if (OWAMessageInspector.ShouldCreateUserContext(callContext)) { UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext; if (userContext != null) { callContext.OwaCulture = userContext.UserCulture; if (userContext.FeaturesManager != null) { callContext.FeaturesManager = userContext.FeaturesManager; if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled) { callContext.OwaUserContextKey = userContext.Key.ToString(); } } } } } catch (LocalizedException ex) { ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, LocalizedException>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught localized exception trying to process message. Type: {0} Exception: {1}", ex.GetType().Name, ex); OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex))); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException"); throw OwaFaultExceptionUtilities.CreateFault(ex); } catch (Exception ex2) { ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, Exception>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught exception trying to process message. Type: {0} Exception: {1}", ex2.GetType().Name, ex2); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex2, "OwaServiceFaultException_InnerException"); throw; } ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] completed"); }
// Token: 0x060007C9 RID: 1993 RVA: 0x000198B9 File Offset: 0x00017AB9 public static bool IsDifferentMailbox(HttpContext httpContext) { return(!string.IsNullOrEmpty(UserContextUtilities.GetExplicitLogonUser(httpContext))); }