public void Load(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, UserContextStatistics stats)
 {
     this.LogTrace("UserContextBase.Load", "starting");
     lock (this.syncRoot)
     {
         this.DoLoad(logonIdentity, mailboxIdentity, stats);
         this.AfterLoad();
     }
     this.LogTrace("UserContextBase.Load", "method finished");
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        protected override void DoLoad(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, UserContextStatistics stats)
        {
            HttpContext          httpContext = HttpContext.Current;
            RequestDetailsLogger current     = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);

            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.UserContextLoadBegin);
            base.DoLoad(logonIdentity, mailboxIdentity, stats);
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.GetOWAMiniRecipientBegin);
            Stopwatch        stopwatch        = Stopwatch.StartNew();
            OWAMiniRecipient owaminiRecipient = base.LogonIdentity.GetOWAMiniRecipient();

            stats.MiniRecipientCreationTime = (int)stopwatch.ElapsedMilliseconds;
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.GetOWAMiniRecipientEnd);
            base.LogTrace("UserContext.Load", "GetOWAMiniRecipient finished");
            this.sipUri = ADPersonToContactConverter.GetSipUri(owaminiRecipient);
            stopwatch.Restart();
            this.IsBposUser             = CapabilityHelper.HasBposSKUCapability(owaminiRecipient.PersistedCapabilities);
            stats.SKUCapabilityTestTime = (int)stopwatch.ElapsedMilliseconds;
            base.LogTrace("UserContext.Load", "HasBposSKUCapability finished");
            if (Globals.IsFirstReleaseFlightingEnabled)
            {
                this.CreateFeatureManagerFactory(owaminiRecipient);
            }
            else
            {
                RecipientTypeDetails recipientTypeDetails = base.ExchangePrincipal.RecipientTypeDetails;
                this.featuresManagerFactory = new FeaturesManagerFactory(owaminiRecipient, new ConfigurationContext(this), new ScopeFlightsSettingsProvider(), (VariantConfigurationSnapshot c) => new FeaturesStateOverride(c, recipientTypeDetails), string.Empty, false);
            }
            this.BposSkuCapability = string.Empty;
            if (this.IsBposUser)
            {
                Capability?skucapability = CapabilityHelper.GetSKUCapability(owaminiRecipient.PersistedCapabilities);
                if (skucapability != null)
                {
                    this.BposSkuCapability = skucapability.ToString();
                }
            }
            this.LogEventCommonData = new LogEventCommonData(this);
            this.IsGroupUserContext = (base.IsExplicitLogon && base.ExchangePrincipal.RecipientTypeDetails == RecipientTypeDetails.GroupMailbox);
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.UserContextLoadEnd);
        }
Esempio n. 4
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;
            }
        }
        protected virtual void DoLoad(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, UserContextStatistics stats)
        {
            if (logonIdentity == null)
            {
                throw new ArgumentNullException("logonIdentity");
            }
            this.logonIdentity = logonIdentity;
            if (mailboxIdentity != null)
            {
                this.isExplicitLogon = true;
                this.mailboxIdentity = mailboxIdentity;
            }
            else
            {
                this.mailboxIdentity = logonIdentity;
            }
            if (this.IsExplicitLogon)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "Created partial mailbox identity from SMTP address={0}", mailboxIdentity.SafeGetRenderableName());
                OwaMiniRecipientIdentity owaMiniRecipientIdentity = this.mailboxIdentity as OwaMiniRecipientIdentity;
                try
                {
                    owaMiniRecipientIdentity.UpgradePartialIdentity();
                }
                catch (DataValidationException ex)
                {
                    PropertyValidationError propertyValidationError = ex.Error as PropertyValidationError;
                    if (propertyValidationError == null || propertyValidationError.PropertyDefinition != MiniRecipientSchema.Languages)
                    {
                        throw;
                    }
                    OWAMiniRecipient owaminiRecipient = this.MailboxIdentity.FixCorruptOWAMiniRecipientCultureEntry();
                    if (owaminiRecipient != null)
                    {
                        this.mailboxIdentity = OwaMiniRecipientIdentity.CreateFromOWAMiniRecipient(owaminiRecipient);
                    }
                }
            }
            Stopwatch stopwatch = Stopwatch.StartNew();

            this.exchangePrincipal = this.mailboxIdentity.CreateExchangePrincipal();
            stats.ExchangePrincipalCreationTime = (int)stopwatch.ElapsedMilliseconds;
            this.LogTrace("UserContextBase.Load", "CreateExchangePrincipal finished");
            this.pendingRequestManager = new PendingRequestManager(this, ListenerChannelsManager.Instance);
        }