internal static UserContextKey CreateNew(SecurityIdentifier sid)
        {
            string text  = null;
            string text2 = sid.ToString();

            return(UserContextKey.Create(UserContextUtilities.GetNewGuid(), text2, text));
        }
Beispiel #2
0
 internal UserContext(UserContextKey key, string userAgent) : base(key, userAgent)
 {
     this.themeKey           = key + "Theme";
     this.LogEventCommonData = LogEventCommonData.NullInstance;
     if (!Globals.Owa2ServerUnitTestsHook)
     {
         this.lastUserRequestTime = Globals.ApplicationTime;
         this.signIntoIMTime      = Globals.ApplicationTime;
     }
 }
        internal static UserContextKey Parse(string keyString)
        {
            ArgumentValidator.ThrowIfNull("keyString", keyString);
            UserContextKey result;

            if (!UserContextKey.TryParse(keyString, out result))
            {
                throw new ArgumentException(string.Format("Invalid UserContextKey string - '{0}'", keyString), "keyString");
            }
            return(result);
        }
        // Token: 0x0600105C RID: 4188 RVA: 0x0003EDF8 File Offset: 0x0003CFF8
        private bool TryParseUserContextKey(string contextKey, out UserContextKey contextKeyObj)
        {
            bool flag = UserContextKey.TryParse(contextKey, out contextKeyObj);

            if (!flag)
            {
                ExTraceGlobals.NotificationsCallTracer.TraceError <string>((long)this.GetHashCode(), "RemoteNotificationManager.TryParseUserContextKey - couldn't parse UserContextKey {0}, skipping cleanup", contextKey);
                ExWatson.SendReport(new ArgumentException(string.Format("RemoteNotificationManager::TryParseUserContextKey - TryParse failed for UserContextKey string - '{0}'", contextKey)), ReportOptions.None, null);
            }
            return(flag);
        }
 internal MailboxContextBase(UserContextKey key, string userAgent)
 {
     ExAssert.RetailAssert(key != null, "[MailboxContextBase::ctor] key is null");
     ExAssert.RetailAssert(!string.IsNullOrEmpty(userAgent), "[MailboxContextBase::ctor] userAgent is null");
     this.key       = key;
     this.UserAgent = userAgent;
     this.syncRoot  = new object();
     if (!Globals.Owa2ServerUnitTestsHook && !Globals.DisableBreadcrumbs)
     {
         this.breadcrumbBuffer = new BreadcrumbBuffer(Globals.MaxBreadcrumbs);
     }
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        internal static IMailboxContext GetMailboxContext(HttpContext httpContext, AuthZClientInfo effectiveCaller = null, bool create = true)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            ClientSecurityContext overrideClientSecurityContext = (effectiveCaller == null) ? null : effectiveCaller.ClientSecurityContext;
            UserContextCookie     userContextCookie;
            UserContextKey        userContextKey = UserContextManager.GetUserContextKey(httpContext, overrideClientSecurityContext, out userContextCookie);

            if (!create)
            {
                return(UserContextManager.GetMailboxContextFromCache(userContextKey));
            }
            return(UserContextManager.AcquireUserContext(httpContext, effectiveCaller, userContextKey, userContextCookie));
        }
        private static void DoLogoffCleanup(RequestContext requestContext)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DoLogoff] entry.");
            HttpContext    httpContext = requestContext.HttpContext;
            UserContext    userContext = requestContext.UserContext as UserContext;
            UserContextKey key         = userContext.Key;

            try
            {
                ExTraceGlobals.UserContextTracer.TraceDebug <UserContext>(0L, "[RequestDispatcher::DoLogoffCleanup] Found user context in the cache, User context instance={0}.", userContext);
                userContext.State = UserContextState.MarkedForLogoff;
                userContext.LogBreadcrumb("MarkedForLogoff");
                userContext.DoLogoffCleanup();
                userContext.LogBreadcrumb("DoLogoffCleanup completed");
            }
            finally
            {
                UserContextCookie userContextCookie = UserContextCookie.GetUserContextCookie(requestContext.HttpContext);
                if (userContextCookie != null)
                {
                    HttpUtilities.DeleteCookie(httpContext.Response, userContextCookie.CookieName);
                }
                HttpUtilities.DeleteCookie(httpContext.Response, Canary15Profile.Owa.Name);
                if (key.UserContextId == null)
                {
                    string message = "User context id couldn't be retrieved. Logoff can't be performed";
                    ExTraceGlobals.UserContextTracer.TraceDebug(0L, message);
                    userContext.LogBreadcrumb(message);
                    userContext.Dispose();
                    userContext = null;
                }
                else
                {
                    userContext.LogBreadcrumb("Logoff invoking Cache.Remove");
                    object obj = HttpRuntime.Cache.Remove(key.ToString());
                    userContext.LogBreadcrumb("Logoff invoked Cache.Remove");
                    string message2 = (obj == null) ? "The userContext was already deleted from the cache" : "Context successfully deleted from the cache";
                    ExTraceGlobals.UserContextTracer.TraceDebug(0L, message2);
                    userContext.LogBreadcrumb(message2);
                }
            }
        }
        internal static UserContextKey CreateNew(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, HttpContext httpContext)
        {
            if (logonIdentity == null)
            {
                throw new ArgumentNullException("logonIdentity");
            }
            string        uniqueId      = logonIdentity.UniqueId;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("userContextLogonIdentityName=<PII>{0}</PII>", logonIdentity.SafeGetRenderableName());
            if (logonIdentity.UserSid != null)
            {
                stringBuilder.AppendFormat("userContextLogonIdentitySid=<PII>{0}</PII>", logonIdentity.UserSid.ToString());
            }
            string text = null;

            if (mailboxIdentity != null)
            {
                text = mailboxIdentity.UniqueId;
                stringBuilder.AppendFormat("userContextMbIdentityName=<PII>{0}</PII>", mailboxIdentity.SafeGetRenderableName());
                if (mailboxIdentity.UserSid != null)
                {
                    stringBuilder.AppendFormat("userContextMbIdentitySid=<PII>{0}</PII>", mailboxIdentity.UserSid.ToString());
                }
            }
            try
            {
                string text2 = stringBuilder.ToString();
                if (LiveIdAuthenticationModule.IdentityTracingEnabled && !string.IsNullOrWhiteSpace(text2))
                {
                    httpContext.Response.AppendToLog(text2);
                }
            }
            catch (Exception)
            {
            }
            return(UserContextKey.Create(UserContextUtilities.GetNewGuid(), uniqueId, text));
        }
        internal static bool TryParse(string keyString, out UserContextKey userContextKey)
        {
            ArgumentValidator.ThrowIfNull("keyString", keyString);
            userContextKey = null;
            string[] array = keyString.Split(new char[]
            {
                ':'
            });
            if (array.Length < 2 || array.Length > 3)
            {
                return(false);
            }
            string text  = array[0];
            string text2 = array[1];
            string text3 = null;

            if (array.Length == 3)
            {
                text3 = array[2];
            }
            userContextKey = new UserContextKey(text, text2, text3);
            return(true);
        }
Beispiel #11
0
 // Token: 0x0600071C RID: 1820 RVA: 0x00015C54 File Offset: 0x00013E54
 internal SharedContext(UserContextKey key, string userAgent) : base(key, userAgent)
 {
 }
 // Token: 0x0600078F RID: 1935 RVA: 0x000181E9 File Offset: 0x000163E9
 internal static UserContextCookie CreateFromKey(string cookieId, UserContextKey userContextKey, bool isSecure)
 {
     return(UserContextCookie.Create(cookieId, userContextKey.UserContextId, userContextKey.MailboxUniqueKey, isSecure));
 }
Beispiel #13
0
 internal static IMailboxContext GetMailboxContextFromCache(UserContextKey userContextKey)
 {
     return(UserContextManager.GetMailboxContextFromCache(userContextKey, true));
 }
Beispiel #14
0
        private static IMailboxContext GetMailboxContextFromCache(UserContextKey userContextKey, bool lockUserContextKey)
        {
            ExTraceGlobals.UserContextCallTracer.TraceDebug(0L, "UserContextManager.TryGetUserContextFromCache");
            if (userContextKey == null)
            {
                ExTraceGlobals.UserContextCallTracer.TraceDebug(0L, "UserContextManager.TryGetUserContextFromCache: No UserContextKey provided, returning null.");
                return(null);
            }
            UserContextManager.UserContextCacheWrapper userContextCacheWrapper = null;
            IMailboxContext mailboxContext = null;
            bool            flag           = false;

            try
            {
                ExTraceGlobals.UserContextCallTracer.TraceDebug <UserContextKey>(0L, "Attempting to fetch user context from the cache.  Key={0}", userContextKey);
                userContextCacheWrapper = (UserContextManager.UserContextCacheWrapper)HttpRuntime.Cache.Get(userContextKey.ToString());
                if (userContextCacheWrapper != null && userContextCacheWrapper.UserContext != null)
                {
                    if (lockUserContextKey)
                    {
                        if (userContextCacheWrapper.Lock == null)
                        {
                            throw new OwaLockException("UserContextManager::GetUserContextFromCache cannot get a lock from UserContextCacheWrapper");
                        }
                        if (!userContextCacheWrapper.Lock.IsWriterLockHeld)
                        {
                            if (!userContextCacheWrapper.Lock.LockWriterElastic(3000))
                            {
                                throw new OwaLockTimeoutException("UserContextManager::GetUserContextFromCache cannot acquire a write lock in a time fashion");
                            }
                            flag           = true;
                            mailboxContext = userContextCacheWrapper.UserContext;
                            ExTraceGlobals.UserContextCallTracer.TraceDebug <UserContextKey, IMailboxContext>(0L, "User context found in cache. Key={0}, User context instance={1}", userContextKey, mailboxContext);
                        }
                    }
                    else
                    {
                        mailboxContext = userContextCacheWrapper.UserContext;
                        ExTraceGlobals.UserContextCallTracer.TraceDebug <UserContextKey, IMailboxContext>(0L, "User context found in cache. Key={0}, User context instance={1}", userContextKey, mailboxContext);
                    }
                }
                else
                {
                    ExTraceGlobals.UserContextCallTracer.TraceDebug <string>(0L, "An object for this user context ID value is not present in the cache (probably was expired), so we are going to reuse the user context ID value for the new session", userContextKey.UserContextId);
                }
            }
            finally
            {
                if (mailboxContext != null && mailboxContext.TerminationStatus == UserContextTerminationStatus.TerminatePending)
                {
                    UserContextManager.TerminateSession(mailboxContext, mailboxContext.AbandonedReason);
                    mailboxContext = null;
                }
                if (flag && userContextCacheWrapper != null && userContextCacheWrapper.Lock != null)
                {
                    userContextCacheWrapper.Lock.ReleaseWriterLock();
                }
                if (mailboxContext != null && mailboxContext.State != UserContextState.Active)
                {
                    mailboxContext = null;
                }
            }
            return(mailboxContext);
        }
Beispiel #15
0
        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;
            }
        }
Beispiel #16
0
        private static IMailboxContext AcquireUserContext(HttpContext httpContext, AuthZClientInfo effectiveCaller, UserContextKey userContextKey, UserContextCookie userContextCookie)
        {
            IMailboxContext       mailboxContext        = null;
            UserContextStatistics userContextStatistics = null;

            try
            {
                if (userContextKey != null)
                {
                    mailboxContext = UserContextManager.GetMailboxContextFromCache(userContextKey);
                    if (mailboxContext == null || mailboxContext.State == UserContextState.Abandoned)
                    {
                        UserContextManager.CreateUserContext(httpContext, userContextKey, effectiveCaller, out mailboxContext, out userContextStatistics);
                    }
                }
                else
                {
                    UserContextManager.CreateUserContext(httpContext, null, effectiveCaller, out mailboxContext, out userContextStatistics);
                    string cookieId = null;
                    if (mailboxContext != null)
                    {
                        userContextCookie = UserContextCookie.CreateFromKey(cookieId, mailboxContext.Key, httpContext.Request.IsSecureConnection);
                        httpContext.Response.Cookies.Set(userContextCookie.HttpCookie);
                        userContextStatistics.CookieCreated = true;
                    }
                }
            }
            finally
            {
                if (userContextStatistics != null)
                {
                    SignInLogEvent logEvent = new SignInLogEvent(mailboxContext, (userContextCookie != null) ? userContextCookie.CookieValue : string.Empty, userContextStatistics, httpContext.Request.Url);
                    OwaServerLogger.AppendToLog(logEvent);
                }
            }
            return(mailboxContext);
        }
Beispiel #17
0
 private static bool IsSharedContextKey(UserContextKey userContextKey)
 {
     return(userContextKey != null && userContextKey.UserContextId == "D894745CADD64DB9B00309200288E1E7");
 }