Пример #1
0
        // Token: 0x06001BC9 RID: 7113 RVA: 0x0006B100 File Offset: 0x00069300
        private bool LocalizeFolders(CultureInfo culture)
        {
            MailboxSession mailboxSession = null;
            bool           result         = false;

            try
            {
                OwaIdentity logonIdentity = RequestContext.Current.UserContext.LogonIdentity;
                mailboxSession = logonIdentity.CreateMailboxSession(RequestContext.Current.UserContext.ExchangePrincipal, culture);
                Exception[] array;
                mailboxSession.LocalizeDefaultFolders(out array);
                mailboxSession.SetMailboxLocale(culture);
                if (array != null && array.Length > 0)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "Exception Message-{0}", array[0].Message);
                }
                else
                {
                    result = true;
                }
            }
            finally
            {
                if (mailboxSession != null)
                {
                    UserContextUtilities.DisconnectStoreSession(mailboxSession);
                    mailboxSession.Dispose();
                    mailboxSession = null;
                }
            }
            return(result);
        }
        // Token: 0x0600223F RID: 8767 RVA: 0x0007EA34 File Offset: 0x0007CC34
        private void GetListItemChangesSinceToken(IClientContext context, OwaIdentity identity, string listName, string location, out string changeToken, out bool hasChanges, DataProviderCallLogEvent logEvent)
        {
            changeToken = null;
            hasChanges  = false;
            DownloadResult downloadResult = OneDriveProUtilities.SendRestRequest("POST", string.Format("{0}/_vti_bin/client.svc/web/lists/getByTitle('{1}')/GetListItemChangesSinceToken", context.Url, listName), identity, this.GetRequestStream(location, this.ChangeToken), logEvent, "GetListItemChangesSinceToken");

            if (!downloadResult.IsSucceeded)
            {
                OneDriveProItemsPagingMetadata.TraceError(OneDriveProItemsPagingMetadata.LogMetadata.GetListItemChangesSinceToken, downloadResult.Exception);
                hasChanges = true;
                return;
            }
            using (XmlReader xmlReader = XmlReader.Create(downloadResult.ResponseStream))
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        if (xmlReader.LocalName == "Changes")
                        {
                            changeToken = xmlReader.GetAttribute("LastChangeToken");
                        }
                        else if (xmlReader.LocalName == "row" && xmlReader.NamespaceURI == "#RowsetSchema")
                        {
                            hasChanges = true;
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        internal static OwaIdentity CreateOwaIdentityFromExplicitLogonAddress(string smtpAddress)
        {
            OwaIdentity result = OwaMiniRecipientIdentity.CreateFromProxyAddress(smtpAddress);

            ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "The request is under explicit logon: {0}", smtpAddress);
            return(result);
        }
Пример #4
0
 public virtual void Refresh(OwaIdentity identity)
 {
     if (identity.GetType() != base.GetType())
     {
         throw new OwaInvalidOperationException(string.Format("Type of passed in identity does not match current identity.  Expected {0} but got {1}.", base.GetType(), identity.GetType()));
     }
 }
        private ICollection <string> ExtractSmtpAddresses(OwaIdentity requestor)
        {
            if (requestor == null)
            {
                return(Array <string> .Empty);
            }
            OWAMiniRecipient owaminiRecipient = requestor.OwaMiniRecipient ?? requestor.GetOWAMiniRecipient();

            if (owaminiRecipient == null)
            {
                this.tracer.TraceDebug((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  cannot extract SMTP addresses because recipient information has NOT been initialized or computed for requestor.");
                return(Array <string> .Empty);
            }
            HashSet <string> hashSet            = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            SmtpAddress      primarySmtpAddress = requestor.PrimarySmtpAddress;

            hashSet.Add(requestor.PrimarySmtpAddress.ToString());
            if (owaminiRecipient.EmailAddresses != null && owaminiRecipient.EmailAddresses.Count > 0)
            {
                hashSet.UnionWith(from a in owaminiRecipient.EmailAddresses
                                  where OwaPhotoRequestorWriter.IsNonBlankSmtpAddress(a)
                                  select a.ValueString);
            }
            return(hashSet);
        }
        // Token: 0x06000677 RID: 1655 RVA: 0x000137A0 File Offset: 0x000119A0
        internal static OwaIdentity CreateFromAuthZClientInfo(AuthZClientInfo authZClientInfo)
        {
            if (authZClientInfo == null)
            {
                throw new ArgumentNullException("authZClientInfo", "You must specify the source AuthZClientInfo.");
            }
            OwaIdentity owaIdentity = OwaClientSecurityContextIdentity.CreateFromClientSecurityContext(authZClientInfo.ClientSecurityContext, authZClientInfo.PrimarySmtpAddress, "OverrideClientSecurityContext");

            if (owaIdentity == null)
            {
                ExTraceGlobals.CoreCallTracer.TraceError(0L, "[OwaIdentity::CreateFromAuthZClientInfo] - was unable to create the security context for " + authZClientInfo.PrimarySmtpAddress);
                throw new OwaIdentityException("Cannot create security context for the specified identity. Failed to resolve the identity " + authZClientInfo.PrimarySmtpAddress);
            }
            if (authZClientInfo.SecondaryClientInfoItems.Count > 0)
            {
                OwaIdentity[] array = new OwaIdentity[authZClientInfo.SecondaryClientInfoItems.Count];
                int           num   = 0;
                foreach (AuthZClientInfo authZClientInfo2 in authZClientInfo.SecondaryClientInfoItems)
                {
                    array[num] = OwaClientSecurityContextIdentity.CreateFromClientSecurityContext(authZClientInfo2.ClientSecurityContext, authZClientInfo2.PrimarySmtpAddress, "OverrideClientSecurityContext");
                    if (array[num] == null)
                    {
                        ExTraceGlobals.CoreCallTracer.TraceError(0L, "[OwaIdentity::CreateFromAuthZClientInfo] - was unable to create the security context for composite identity. Failed to resolve secondary identity " + authZClientInfo2.PrimarySmtpAddress);
                        throw new OwaIdentityException(string.Format("Cannot create security context for the specified composite identity. Failed to resolve the secondary identity {0}: {1}.", num, authZClientInfo2.PrimarySmtpAddress));
                    }
                    num++;
                }
                owaIdentity = new OwaCompositeIdentity(owaIdentity, array);
            }
            return(owaIdentity);
        }
        // Token: 0x06000676 RID: 1654 RVA: 0x000136BC File Offset: 0x000118BC
        public static OwaCompositeIdentity CreateFromCompositeIdentity(CompositeIdentity compositeIdentity)
        {
            if (compositeIdentity == null)
            {
                throw new ArgumentNullException("compositeIdentity", "You must specify the source CompositeIdentity.");
            }
            OwaIdentity owaIdentity = OwaIdentity.GetOwaIdentity(compositeIdentity.PrimaryIdentity);

            if (owaIdentity == null)
            {
                ExTraceGlobals.CoreCallTracer.TraceError(0L, "[OwaIdentity::CreateFromCompositeIdentity] - failed to resolve primary identity.");
                throw new OwaIdentityException("Cannot create security context for the specified composite identity. Failed to resolve the primary identity.");
            }
            OwaIdentity[] array = new OwaIdentity[compositeIdentity.SecondaryIdentitiesCount];
            int           num   = 0;

            foreach (IIdentity identity in compositeIdentity.SecondaryIdentities)
            {
                array[num] = OwaIdentity.GetOwaIdentity(identity);
                if (array[num] == null)
                {
                    ExTraceGlobals.CoreCallTracer.TraceError(0L, string.Format("[OwaIdentity::CreateFromCompositeIdentity] - failed to resolve secondary identity {0}.", num));
                    throw new OwaIdentityException(string.Format("Cannot create security context for the specified composite identity. Failed to resolve a secondary identity {0}.", num));
                }
                num++;
            }
            return(new OwaCompositeIdentity(owaIdentity, array));
        }
        // Token: 0x06000685 RID: 1669 RVA: 0x00013980 File Offset: 0x00011B80
        public override bool IsEqualsTo(OwaIdentity otherIdentity)
        {
            OwaCompositeIdentity owaCompositeIdentity = otherIdentity as OwaCompositeIdentity;

            if (owaCompositeIdentity == null)
            {
                return(false);
            }
            bool flag = otherIdentity.UserSid.Equals(this.UserSid);

            if (flag)
            {
                if (this.secondaryIdentities.Count != this.secondaryIdentities.Count)
                {
                    return(false);
                }
                for (int i = 0; i < this.secondaryIdentities.Count; i++)
                {
                    if (!this.secondaryIdentities[i].IsEqualsTo(owaCompositeIdentity.secondaryIdentities[i]))
                    {
                        return(false);
                    }
                }
            }
            return(flag);
        }
        public static SerializedClientSecurityContext CreateFromOwaIdentity(OwaIdentity owaIdentity)
        {
            SerializedClientSecurityContext serializedClientSecurityContext = new SerializedClientSecurityContext();

            owaIdentity.ClientSecurityContext.SetSecurityAccessToken(serializedClientSecurityContext);
            serializedClientSecurityContext.LogonName          = owaIdentity.GetLogonName();
            serializedClientSecurityContext.AuthenticationType = owaIdentity.AuthenticationType;
            return(serializedClientSecurityContext);
        }
Пример #10
0
 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");
 }
        public HttpContext Write(HttpContext authenticatedUserContext, HttpContext output)
        {
            ArgumentValidator.ThrowIfNull("authenticatedUserContext", authenticatedUserContext);
            ArgumentValidator.ThrowIfNull("output", output);
            HttpContext result;

            try
            {
                using (new StopwatchPerformanceTracker("PhotoRequestorWriterResolveIdentity", this.perfLogger))
                {
                    using (new ADPerformanceTracker("PhotoRequestorWriterResolveIdentity", this.perfLogger))
                    {
                        using (OwaIdentity owaIdentity = OwaIdentity.ResolveLogonIdentity(authenticatedUserContext, null))
                        {
                            if (owaIdentity == null)
                            {
                                this.tracer.TraceDebug((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  requestor could NOT be resolved.");
                                return(output);
                            }
                            OrganizationId organization = OwaPhotoRequestorWriter.GetOrganization(owaIdentity);
                            if (organization == null)
                            {
                                this.tracer.TraceError((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  could NOT determine requestor's organization.");
                                return(output);
                            }
                            output.Items["Photo.Requestor"] = new PhotoPrincipal
                            {
                                OrganizationId = organization,
                                EmailAddresses = this.ExtractSmtpAddresses(owaIdentity)
                            };
                            output.Items["Photo.Requestor.EnabledInFasterPhotoFlightHttpContextKey"] = OwaPhotoRequestorWriter.InPhotoFasterPhotoFlight(owaIdentity.OwaMiniRecipient);
                        }
                    }
                }
                result = output;
            }
            catch (OwaADObjectNotFoundException arg)
            {
                this.tracer.TraceError <OwaADObjectNotFoundException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  requestor NOT found.  Exception: {0}", arg);
                result = output;
            }
            catch (TransientException arg2)
            {
                this.tracer.TraceError <TransientException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  failed to resolve requestor with a transient error.  Exception: {0}", arg2);
                result = output;
            }
            catch (ADOperationException arg3)
            {
                this.tracer.TraceError <ADOperationException>((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  failed to resolve requestor with permanent directory error.  Exception: {0}", arg3);
                result = output;
            }
            return(result);
        }
        // Token: 0x06000693 RID: 1683 RVA: 0x00013B28 File Offset: 0x00011D28
        public override bool IsEqualsTo(OwaIdentity otherIdentity)
        {
            if (otherIdentity == null)
            {
                return(false);
            }
            OwaMiniRecipientIdentity owaMiniRecipientIdentity = otherIdentity as OwaMiniRecipientIdentity;

            if (owaMiniRecipientIdentity == null)
            {
                throw new OwaInvalidOperationException("Comparing OwaMiniRecipientIdentity with identities of another type is not supported");
            }
            return(owaMiniRecipientIdentity.ProxyAddress == this.proxyAddress);
        }
        private static OrganizationId GetOrganization(OwaIdentity requestor)
        {
            if (requestor.UserOrganizationId != null)
            {
                return(requestor.UserOrganizationId);
            }
            OWAMiniRecipient owaminiRecipient = requestor.OwaMiniRecipient ?? requestor.GetOWAMiniRecipient();

            if (owaminiRecipient != null)
            {
                return(owaminiRecipient.OrganizationId);
            }
            return(null);
        }
 private OwaClientSecurityContextIdentity(ClientSecurityContext clientSecurityContext, string logonName, string authenticationType, OrganizationId userOrganizationId)
 {
     if (clientSecurityContext == null)
     {
         throw new ArgumentNullException("clientSecurityContext");
     }
     if (string.IsNullOrEmpty(logonName))
     {
         throw new ArgumentNullException("logonName", "logonName cannot be null or empty.");
     }
     if (userOrganizationId == null && !OwaIdentity.IsLogonNameFullyQualified(logonName))
     {
         throw new ArgumentException("logonName", string.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid logon name.", new object[]
         {
             logonName
         }));
     }
     if (string.IsNullOrEmpty(authenticationType))
     {
         throw new ArgumentNullException("authenticationType", "authenticationType cannot be null or empty.");
     }
     this.logonName          = logonName;
     this.authenticationType = authenticationType;
     base.UserOrganizationId = userOrganizationId;
     if (!SyncUtilities.IsDatacenterMode())
     {
         this.clientSecurityContext = clientSecurityContext;
         OWAMiniRecipient owaminiRecipient = base.GetOWAMiniRecipient();
         if (owaminiRecipient != null && owaminiRecipient.MasterAccountSid != null)
         {
             try
             {
                 this.clientSecurityContext = OwaClientSecurityContextIdentity.TokenMunger.MungeToken(clientSecurityContext, OrganizationId.ForestWideOrgId);
                 return;
             }
             catch (TokenMungingException ex)
             {
                 ExTraceGlobals.CoreCallTracer.TraceError(0L, "OwaClientSecurityContextIdentity.TokenMunger.MungeToken for LogonName='{0}', AuthenticationType='{1}', UserOrgId='{2}' failed with exception: {3}", new object[]
                 {
                     this.logonName,
                     this.authenticationType,
                     base.UserOrganizationId,
                     ex.Message
                 });
             }
         }
     }
     this.clientSecurityContext = clientSecurityContext.Clone();
 }
        private static string GetPrimarySmtpAddress(IMailboxContext userContext)
        {
            OwaIdentity mailboxIdentity = userContext.MailboxIdentity;

            if (mailboxIdentity == null)
            {
                return(null);
            }
            string text = (string)mailboxIdentity.PrimarySmtpAddress;

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            return(text);
        }
Пример #16
0
        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);
        }
        // Token: 0x0600020D RID: 525 RVA: 0x00008150 File Offset: 0x00006350
        internal static IClientContext CreateAndConfigureClientContext(OwaIdentity identity, string url)
        {
            ICredentials   oneDriveProCredentials = OneDriveProUtilities.GetOneDriveProCredentials(identity);
            IClientContext clientContext          = ClientContextFactory.Create(url);

            clientContext.Credentials = oneDriveProCredentials;
            clientContext.FormDigestHandlingEnabled = false;
            clientContext.ExecutingWebRequest      += delegate(object sender, WebRequestEventArgs args)
            {
                if (args != null)
                {
                    args.WebRequestExecutor.RequestHeaders.Add(OneDriveProUtilities.GetOAuthRequestHeaders());
                    args.WebRequestExecutor.WebRequest.PreAuthenticate = true;
                    args.WebRequestExecutor.WebRequest.UserAgent       = OneDriveProUtilities.UserAgentString;
                }
            };
            return(clientContext);
        }
Пример #18
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);
        }
        // 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);
        }
        // Token: 0x06001AD6 RID: 6870 RVA: 0x00065F4C File Offset: 0x0006414C
        private static WacAttachmentType CreateWacAttachmentType(OwaIdentity identity, AttachmentIdType attachmentIdType, string webServiceUrl, string contentUrl, bool isEdit, bool isInDraft)
        {
            string wacUrl;

            try
            {
                wacUrl = OneDriveProUtilities.GetWacUrl(identity, webServiceUrl, contentUrl, isEdit);
            }
            catch (Exception ex)
            {
                ex.ToString();
                throw;
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = wacUrl,
                Status = WacAttachmentStatus.Success
            });
        }
Пример #21
0
        internal static OwaIdentity ResolveLogonIdentity(HttpContext httpContext, AuthZClientInfo effectiveCaller)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            OwaIdentity owaIdentity;

            if (effectiveCaller != null && effectiveCaller.ClientSecurityContext != null)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>(0L, "[OwaIdentity::ResolveLogonIdentity] - Taking identity from overrideClientSecurityContext. User: {0}.", effectiveCaller.PrimarySmtpAddress);
                owaIdentity = OwaCompositeIdentity.CreateFromAuthZClientInfo(effectiveCaller);
            }
            else
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[OwaIdentity::ResolveLogonIdentity] - Looking for identity on httpContext.");
                IIdentity userIdentity = CompositeIdentityBuilder.GetUserIdentity(httpContext);
                if (userIdentity == null)
                {
                    ExTraceGlobals.CoreCallTracer.TraceError(0L, "[OwaIdentity::ResolveLogonIdentity] - httpContext was passed without an identity");
                    throw new OwaIdentityException("The httpContext must have an identity associated with it.");
                }
                owaIdentity = OwaIdentity.GetOwaIdentity(userIdentity);
            }
            if (owaIdentity != null)
            {
                string logonName = owaIdentity.GetLogonName();
                ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[OwaIdentity::ResolveLogonIdentity] Successfully resolved logon identity. Type={0}, AuthType={1}, Name={2}, IsPartial={3}", new object[]
                {
                    owaIdentity.GetType(),
                    owaIdentity.AuthenticationType ?? string.Empty,
                    logonName ?? string.Empty,
                    owaIdentity.IsPartial
                });
                return(owaIdentity);
            }
            ExTraceGlobals.CoreCallTracer.TraceError(0L, "[OwaIdentity::ResolveLogonIdentity] - was unable to create the security context.");
            throw new OwaIdentityException("Cannot create security context for the specified identity.");
        }
Пример #22
0
        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));
        }
        // Token: 0x06000675 RID: 1653 RVA: 0x0001363C File Offset: 0x0001183C
        private OwaCompositeIdentity(OwaIdentity primaryIdentity, IEnumerable <OwaIdentity> secondaryIdentities)
        {
            if (primaryIdentity == null)
            {
                throw new ArgumentNullException("primaryIdentity", "The primary identity must not be null!");
            }
            this.primaryIdentity    = primaryIdentity;
            base.UserOrganizationId = primaryIdentity.UserOrganizationId;
            base.OwaMiniRecipient   = primaryIdentity.OwaMiniRecipient;
            IReadOnlyList <OwaIdentity> readOnlyList;

            if (secondaryIdentities != null)
            {
                readOnlyList = (from i in secondaryIdentities
                                orderby i.UserSid
                                select i).ToArray <OwaIdentity>();
            }
            else
            {
                readOnlyList = new OwaIdentity[0];
            }
            this.secondaryIdentities = readOnlyList;
        }
Пример #24
0
        private static bool ShouldBlockConnection(HttpContext httpContext, OwaIdentity logonIdentity)
        {
            if (!VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).OwaServer.OwaClientAccessRulesEnabled.Enabled)
            {
                return(false);
            }
            RequestDetailsLogger logger = OwaApplication.GetRequestDetailsLogger;
            Action <ClientAccessRulesEvaluationContext> blockLoggerDelegate = delegate(ClientAccessRulesEvaluationContext context)
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(logger, ClientAccessRulesConstants.ClientAccessRuleName, context.CurrentRule.Name);
            };
            Action <double> latencyLoggerDelegate = delegate(double latency)
            {
                if (latency > 50.0)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(logger, ClientAccessRulesConstants.ClientAccessRulesLatency, latency);
                }
            };
            OWAMiniRecipient owaminiRecipient          = logonIdentity.GetOWAMiniRecipient();
            string           usernameFromIdInformation = ClientAccessRulesUtils.GetUsernameFromIdInformation(owaminiRecipient.WindowsLiveID, owaminiRecipient.MasterAccountSid, owaminiRecipient.Sid, owaminiRecipient.ObjectId);

            return(ClientAccessRulesUtils.ShouldBlockConnection(logonIdentity.UserOrganizationId, usernameFromIdInformation, ClientAccessProtocol.OutlookWebApp, ClientAccessRulesUtils.GetRemoteEndPointFromContext(httpContext), httpContext.Request.IsAuthenticatedByAdfs() ? ClientAccessAuthenticationMethod.AdfsAuthentication : ClientAccessAuthenticationMethod.BasicAuthentication, owaminiRecipient, blockLoggerDelegate, latencyLoggerDelegate));
        }
        // Token: 0x0600020F RID: 527 RVA: 0x000081AC File Offset: 0x000063AC
        internal static DownloadResult SendRestRequest(string requestMethod, string requestUri, OwaIdentity identity, Stream requestStream, DataProviderCallLogEvent logEvent, string spCallName)
        {
            DownloadResult result;

            using (HttpClient httpClient = new HttpClient())
            {
                HttpSessionConfig httpSessionConfig = new HttpSessionConfig
                {
                    Method          = requestMethod,
                    Credentials     = OauthUtils.GetOauthCredential(identity.GetOWAMiniRecipient()),
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    RequestStream   = requestStream,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true
                };
                httpSessionConfig.Headers = OneDriveProUtilities.GetOAuthRequestHeaders();
                if (logEvent != null)
                {
                    logEvent.TrackSPCallBegin();
                }
                ICancelableAsyncResult cancelableAsyncResult = httpClient.BeginDownload(new Uri(requestUri), httpSessionConfig, null, null);
                cancelableAsyncResult.AsyncWaitHandle.WaitOne();
                DownloadResult downloadResult = httpClient.EndDownload(cancelableAsyncResult);
                if (logEvent != null)
                {
                    string correlationId = (downloadResult.ResponseHeaders == null) ? null : downloadResult.ResponseHeaders["SPRequestGuid"];
                    logEvent.TrackSPCallEnd(spCallName, correlationId);
                }
                result = downloadResult;
            }
            return(result);
        }
 // Token: 0x0600020E RID: 526 RVA: 0x0000819D File Offset: 0x0000639D
 internal static ICredentials GetOneDriveProCredentials(OwaIdentity identity)
 {
     return(OauthUtils.GetOauthCredential(identity.GetOWAMiniRecipient()));
 }
        // Token: 0x06000211 RID: 529 RVA: 0x000082BC File Offset: 0x000064BC
        internal static string GetWacUrl(OwaIdentity identity, string endPointUrl, string documentUrl, bool isEdit)
        {
            string arg  = isEdit ? "2" : "4";
            string text = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
            string result;

            using (HttpClient httpClient = new HttpClient())
            {
                OWAMiniRecipient    owaminiRecipient    = identity.GetOWAMiniRecipient();
                ICredentials        oauthCredential     = OauthUtils.GetOauthCredential(owaminiRecipient);
                WebHeaderCollection oauthRequestHeaders = OneDriveProUtilities.GetOAuthRequestHeaders();
                HttpSessionConfig   sessionConfig       = new HttpSessionConfig
                {
                    Method          = "GET",
                    Credentials     = oauthCredential,
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true,
                    Headers         = oauthRequestHeaders
                };
                DownloadResult downloadResult;
                try
                {
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                catch (WebException ex)
                {
                    if (!OneDriveProUtilities.IsDurableUrlFormat(documentUrl))
                    {
                        throw ex;
                    }
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Exception while trying to get wac token using durable url. : {0}", ex.StackTrace);
                    documentUrl = documentUrl.Substring(0, documentUrl.LastIndexOf("?", StringComparison.InvariantCulture));
                    text        = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Fallback to canonical url format: {0}", text);
                    OwaServerTraceLogger.AppendToLog(new TraceLogEvent("SP.GWT", null, "GetWacToken", string.Format("Error getting WAC Token fallback to canonical format:{0}", text)));
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(downloadResult.ResponseStream);
                string namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices";
                string text2        = null;
                string text3        = null;
                string text4        = null;
                foreach (object obj in xmlDocument.GetElementsByTagName("*", namespaceURI))
                {
                    XmlNode xmlNode = (XmlNode)obj;
                    if (xmlNode is XmlElement)
                    {
                        if (text2 != null && text3 != null && text4 != null)
                        {
                            break;
                        }
                        if (string.CompareOrdinal(xmlNode.LocalName, "AppUrl") == 0)
                        {
                            text2 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessToken") == 0)
                        {
                            text3 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessTokenTtl") == 0)
                        {
                            text4 = xmlNode.InnerText;
                        }
                    }
                }
                if (text2 == null || text3 == null || text4 == null)
                {
                    throw new OwaException("SharePoint's GetWacToken response is not usable.");
                }
                string text5 = isEdit ? "OwaEdit" : "OwaView";
                result = string.Format("{0}&access_token={1}&access_token_ttl={2}&sc={3}", new object[]
                {
                    text2,
                    text3,
                    text4,
                    text5
                });
            }
            return(result);
        }
Пример #28
0
        private OwaHelpUrlData ReadAggregatedOwaHelpUrlData(UserConfigurationManager.IAggregationContext ctx, CultureInfo cultureInfo, OwaIdentity mailboxIdentity, UserAgent userAgent)
        {
            return(UserContextUtilities.ReadAggregatedType <OwaHelpUrlData>(ctx, "OWA.OwaHelpUrlData", delegate
            {
                HelpProvider.RenderingMode mode = HelpProvider.RenderingMode.Mouse;
                switch (userAgent.Layout)
                {
                case LayoutType.TouchNarrow:
                    mode = HelpProvider.RenderingMode.TNarrow;
                    break;

                case LayoutType.TouchWide:
                    mode = HelpProvider.RenderingMode.TWide;
                    break;

                case LayoutType.Mouse:
                    mode = HelpProvider.RenderingMode.Mouse;
                    break;
                }
                OrganizationProperties organizationProperties = null;
                if (mailboxIdentity != null)
                {
                    organizationProperties = mailboxIdentity.UserOrganizationProperties;
                }
                string helpUrl = HelpProvider.ConstructHelpRenderingUrl(cultureInfo.LCID, HelpProvider.OwaHelpExperience.Premium, string.Empty, mode, null, organizationProperties).ToString();
                return new OwaHelpUrlData
                {
                    HelpUrl = helpUrl
                };
            }));
        }
Пример #29
0
        private static DispatchStepResult HandleLanguagePost(RequestContext requestContext, CultureInfo culture, string timeZoneKeyName, bool isOptimized, string destination)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::HandleLanguagePost] entry.");
            if (requestContext.UserContext == null)
            {
                throw new OwaInvalidOperationException("UserContext should be created by the time language post is handled");
            }
            requestContext.LanguagePostUserCulture = culture;
            requestContext.HttpContext.Response.Cookies.Set(new HttpCookie("mkt", culture.Name));
            if (!string.IsNullOrWhiteSpace(destination) && (destination.StartsWith("/ecp/", StringComparison.OrdinalIgnoreCase) || destination.StartsWith("/owa/", StringComparison.OrdinalIgnoreCase)))
            {
                requestContext.DestinationUrl = destination;
            }
            else
            {
                requestContext.DestinationUrl = string.Empty;
            }
            Culture.InternalSetThreadPreferredCulture(culture);
            MailboxSession mailboxSession = null;

            try
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <string, bool>(0L, "[RequestDispatcher::HandleLanguagePost] Attempting to save the timeZoneKeyName (tzid={0}) and isOptimized={1} in the mailbox.", timeZoneKeyName, isOptimized);
                OwaIdentity logonIdentity = requestContext.UserContext.LogonIdentity;
                mailboxSession = logonIdentity.CreateMailboxSession(requestContext.UserContext.ExchangePrincipal, culture);
                if (requestContext.UserContext.IsExplicitLogon && !mailboxSession.CanActAsOwner)
                {
                    throw new OwaExplicitLogonException("User has no access rights to the mailbox", "ErrorExplicitLogonAccessDenied");
                }
                try
                {
                    ExTraceGlobals.CoreCallTracer.TraceDebug <int>(0L, "[RequestDispatcher::HandleLanguagePost] Trying to save the culture to the AD (lcid={0})", culture.LCID);
                    PreferredCultures preferredCultures = new PreferredCultures(requestContext.UserContext.ExchangePrincipal.PreferredCultures);
                    preferredCultures.AddSupportedCulture(culture, new Predicate <CultureInfo>(ClientCultures.IsSupportedCulture));
                    Culture.SetPreferredCulture(requestContext.UserContext.ExchangePrincipal, preferredCultures, mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent));
                    requestContext.UserContext.ExchangePrincipal = requestContext.UserContext.ExchangePrincipal.WithPreferredCultures(preferredCultures);
                }
                catch (Exception ex)
                {
                    if (!(ex is ADOperationException) && !(ex is InvalidOperationException))
                    {
                        throw;
                    }
                    requestContext.FailedToSaveUserCulture = true;
                    if (ExTraceGlobals.CoreCallTracer.IsTraceEnabled(TraceType.ErrorTrace))
                    {
                        StringBuilder stringBuilder = new StringBuilder("Failed to save user's culture in the AD.");
                        stringBuilder.Append("\n\nException: ");
                        stringBuilder.Append(ex.GetType().ToString());
                        stringBuilder.Append("\n");
                        stringBuilder.Append(ex.Message);
                        stringBuilder.Append(")");
                        if (!string.IsNullOrEmpty(ex.StackTrace))
                        {
                            stringBuilder.Append("\n\nCallstack:\n");
                            stringBuilder.Append(ex.StackTrace);
                        }
                        ExTraceGlobals.CoreCallTracer.TraceError(0L, stringBuilder.ToString());
                    }
                }
                UserOptionsType userOptionsType = new UserOptionsType();
                bool            flag            = true;
                try
                {
                    userOptionsType.Load(mailboxSession, false, false);
                }
                catch (QuotaExceededException ex2)
                {
                    ExTraceGlobals.UserContextCallTracer.TraceDebug <string>(0L, "[RequestDispatcher::HandleLanguagePost] UserOptions.LoadAll failed. Exception: {0}.", ex2.Message);
                    flag = false;
                }
                userOptionsType.TimeZone = timeZoneKeyName;
                userOptionsType.IsOptimizedForAccessibility = isOptimized;
                userOptionsType.UserOptionsMigrationState   = UserOptionsMigrationState.WorkingHoursTimeZoneFixUp;
                if (flag)
                {
                    UserConfigurationPropertyDefinition propertyDefinition  = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.TimeZone);
                    UserConfigurationPropertyDefinition propertyDefinition2 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.IsOptimizedForAccessibility);
                    UserConfigurationPropertyDefinition propertyDefinition3 = UserOptionPropertySchema.Instance.GetPropertyDefinition(UserConfigurationPropertyId.UserOptionsMigrationState);
                    userOptionsType.Commit(mailboxSession, new UserConfigurationPropertyDefinition[]
                    {
                        propertyDefinition,
                        propertyDefinition2,
                        propertyDefinition3
                    });
                }
                RequestDispatcher.InitializeFavorites(mailboxSession);
            }
            finally
            {
                if (mailboxSession != null)
                {
                    UserContextUtilities.DisconnectStoreSession(mailboxSession);
                    mailboxSession.Dispose();
                    mailboxSession = null;
                }
            }
            return(DispatchStepResult.Continue);
        }
Пример #30
0
 public virtual bool IsEqualsTo(OwaIdentity otherIdentity)
 {
     return(otherIdentity != null && otherIdentity.UserSid.Equals(this.UserSid));
 }