예제 #1
0
        private static CobaltStore GetCobaltStore(WacRequest wacRequest)
        {
            CachedAttachmentInfo attachmentInfo = WacRequestHandler.GetCachedAttachmentInfo(wacRequest);
            CobaltStore          cobaltStore    = attachmentInfo.CobaltStore;

            if (cobaltStore == null)
            {
                lock (attachmentInfo)
                {
                    cobaltStore = attachmentInfo.CobaltStore;
                    if (cobaltStore == null)
                    {
                        WacRequestHandler.ProcessAttachment(wacRequest, PropertyOpenMode.ReadOnly, delegate(IExchangePrincipal exchangePrincipal, Attachment attachment, Stream stream, bool contentProtected)
                        {
                            if (!WacRequestHandler.MessageIsDraft(wacRequest))
                            {
                                throw new NotSupportedException("Cell storage requests are only supported for draft items.");
                            }
                            cobaltStore = WacRequestHandler.CreateCobaltStore(exchangePrincipal, attachment, wacRequest, attachmentInfo);
                        });
                        attachmentInfo.CobaltStore = cobaltStore;
                    }
                }
            }
            return(cobaltStore);
        }
        public static CachedAttachmentInfo GetInstance(string mailboxSmtpAddress, string ewsAttachmentId, string sessionId, SecurityIdentifier logonSid, string cultureName)
        {
            string cacheKey = CachedAttachmentInfo.GetCacheKey(mailboxSmtpAddress, ewsAttachmentId);
            CachedAttachmentInfo cachedAttachmentInfo = CachedAttachmentInfo.GetFromCache(cacheKey);

            if (cachedAttachmentInfo != null)
            {
                OwaApplication.GetRequestDetailsLogger.Set(WacRequestHandlerMetadata.CacheHit, true);
                return(cachedAttachmentInfo);
            }
            CachedAttachmentInfo result;

            lock (CachedAttachmentInfo.factorySynchronizer)
            {
                cachedAttachmentInfo = CachedAttachmentInfo.GetFromCache(cacheKey);
                if (cachedAttachmentInfo != null)
                {
                    OwaApplication.GetRequestDetailsLogger.Set(WacRequestHandlerMetadata.CacheHit, true);
                    result = cachedAttachmentInfo;
                }
                else
                {
                    OwaApplication.GetRequestDetailsLogger.Set(WacRequestHandlerMetadata.CacheHit, false);
                    string domain = ((SmtpAddress)mailboxSmtpAddress).Domain;
                    string logonSmtpAddress;
                    string logonDisplayName;
                    string logonPuid;
                    CachedAttachmentInfo.GetLogonUserInfo(logonSid, domain, out logonSmtpAddress, out logonDisplayName, out logonPuid);
                    cachedAttachmentInfo = new CachedAttachmentInfo(mailboxSmtpAddress, logonSmtpAddress, logonDisplayName, logonPuid, logonSid, cultureName, ewsAttachmentId, sessionId);
                    cachedAttachmentInfo.InsertIntoCache(cacheKey);
                    result = cachedAttachmentInfo;
                }
            }
            return(result);
        }
        private static void GetLogonUserInfo(SecurityIdentifier sid, string smtpDomain, out string smtpAddress, out string displayName, out string puid)
        {
            string smtpAddressTemporary = sid.ToString();
            string displayNameTemporary = sid.ToString();
            string puidTemporary        = string.Empty;

            ADNotificationAdapter.RunADOperation(delegate()
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(smtpDomain), 339, "GetLogonUserInfo", "f:\\15.00.1497\\sources\\dev\\clients\\src\\Owa2\\Server\\Core\\attachment\\CachedAttachmentInfo.cs");
                PropertyDefinition[] properties = new PropertyDefinition[]
                {
                    ADRecipientSchema.PrimarySmtpAddress,
                    ADRecipientSchema.LegacyExchangeDN,
                    ADRecipientSchema.DisplayName,
                    ADUserSchema.NetID
                };
                ADRawEntry entry = tenantOrRootOrgRecipientSession.FindADRawEntryBySid(sid, properties);
                try
                {
                    CachedAttachmentInfo.SafeGetValue(entry, ADRecipientSchema.PrimarySmtpAddress, ref smtpAddressTemporary);
                    CachedAttachmentInfo.SafeGetValue(entry, ADRecipientSchema.DisplayName, ref displayNameTemporary);
                    CachedAttachmentInfo.SafeGetValue(entry, ADUserSchema.NetID, ref puidTemporary);
                }
                catch (NotInBagPropertyErrorException)
                {
                }
            });
            smtpAddress = smtpAddressTemporary;
            displayName = displayNameTemporary;
            puid        = puidTemporary;
        }
예제 #4
0
        private bool ReadyToSend()
        {
            bool result;

            lock (this.asyncResult)
            {
                if (this.asyncResult.IsCompleted)
                {
                    result = true;
                }
                else
                {
                    base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Count, this.checks);
                    string primarySmtpAddress      = base.CallContext.MailboxIdentityPrincipal.MailboxInfo.PrimarySmtpAddress.ToString();
                    string cacheKey                = CachedAttachmentInfo.GetCacheKey(primarySmtpAddress, this.attachmentId);
                    CachedAttachmentInfo fromCache = CachedAttachmentInfo.GetFromCache(cacheKey);
                    if (fromCache == null)
                    {
                        base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Result, SynchronizeWacAttachment.AttachmentState.NoCachedInfo);
                        result = true;
                    }
                    else
                    {
                        base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.SessionId, fromCache.SessionId);
                        if (fromCache.CobaltStore == null)
                        {
                            if (fromCache.LockCount == 0)
                            {
                                base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Result, SynchronizeWacAttachment.AttachmentState.NoLocks);
                                result = true;
                            }
                            else
                            {
                                base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Result, SynchronizeWacAttachment.AttachmentState.HasLocks);
                                result = false;
                            }
                        }
                        else if (fromCache.CobaltStore.EditorCount == 0)
                        {
                            base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Result, SynchronizeWacAttachment.AttachmentState.NoEditors);
                            result = true;
                        }
                        else
                        {
                            base.CallContext.ProtocolLog.Set(SynchronizeWacAttachmentMetadata.Result, SynchronizeWacAttachment.AttachmentState.HasEditors);
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }
예제 #5
0
        public static bool ShouldUpdateAttachment(string mailboxSmtpAddress, string ewsAttachmentId, out CobaltStoreSaver saver)
        {
            string cacheKey = CachedAttachmentInfo.GetCacheKey(mailboxSmtpAddress, ewsAttachmentId);
            CachedAttachmentInfo fromCache = CachedAttachmentInfo.GetFromCache(cacheKey);

            if (fromCache == null || fromCache.CobaltStore == null)
            {
                saver = null;
                return(false);
            }
            saver = fromCache.CobaltStore.Saver;
            return(saver != null);
        }
        private static void OnCacheEntryExpired(string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
        {
            expensiveObject    = null;
            dependency         = null;
            absoluteExpiration = Cache.NoAbsoluteExpiration;
            slidingExpiration  = Cache.NoSlidingExpiration;
            CachedAttachmentInfo cachedAttachmentInfo = (CachedAttachmentInfo)HttpRuntime.Cache.Get(key);

            if (cachedAttachmentInfo.CobaltStore == null)
            {
                return;
            }
            WacRequestHandler.OnCacheEntryExpired(cachedAttachmentInfo);
        }
        // Token: 0x06001AD7 RID: 6871 RVA: 0x00065FAC File Offset: 0x000641AC
        private static WacAttachmentType GetResultForStreamAttachment(CallContext callContext, UserContext userContext, ConfigurationContext configurationContext, AttachmentPolicy attachmentPolicy, bool isPublicLogon, string cultureName, bool isEdit, IStreamAttachment attachment, string attachmentExtension, AttachmentIdType attachmentIdType, bool isInDraft, IStoreSession storeSession, string mailboxSmtpAddress, bool isArchive)
        {
            WacFileRep  wacFileRep = GetWacAttachmentInfo.CreateWacFileRep(callContext, configurationContext, attachmentPolicy, isPublicLogon, isEdit, isArchive);
            HttpRequest request    = callContext.HttpContext.Request;
            string      text;
            string      arg;

            GetWacAttachmentInfo.GenerateWopiSrcUrl(request, wacFileRep, mailboxSmtpAddress, out text, out arg);
            if (text == null)
            {
                throw new OwaInvalidOperationException("WOPI URL is null.");
            }
            string      id                = attachmentIdType.Id;
            TokenResult oauthToken        = GetWacAttachmentInfo.GetOAuthToken(id, userContext, mailboxSmtpAddress, text);
            string      exchangeSessionId = WacUtilities.GetExchangeSessionId(oauthToken.TokenString);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.ExchangeSessionId, exchangeSessionId);
            SecurityIdentifier effectiveCallerSid = callContext.EffectiveCallerSid;

            CachedAttachmentInfo.GetInstance(mailboxSmtpAddress, id, exchangeSessionId, effectiveCallerSid, cultureName);
            string wacUrl = GetWacAttachmentInfo.GetWacUrl(isEdit, cultureName, attachmentExtension);

            if (string.IsNullOrEmpty(wacUrl))
            {
                throw new OwaInvalidRequestException(string.Format("Wac Base Url is null for this given extension {0} and culture {1}", attachmentExtension, cultureName));
            }
            new Uri(wacUrl);
            string format = "{0}WOPISrc={1}&access_token={2}";
            string arg2   = HttpUtility.UrlEncode(oauthToken.TokenString);
            string text2  = string.Format(format, wacUrl, HttpUtility.UrlEncode(text), arg2);
            string value  = string.Format(format, wacUrl, arg, arg2);

            callContext.ProtocolLog.Set(GetWacAttachmentInfoMetadata.WacUrl, value);
            if (!Uri.IsWellFormedUriString(text2, UriKind.Absolute))
            {
                throw new OwaInvalidOperationException("The WAC Iframe URL that was generated is not a well formed URI: " + text2);
            }
            return(new WacAttachmentType
            {
                AttachmentId = attachmentIdType,
                IsEdit = isEdit,
                IsInDraft = isInDraft,
                WacUrl = text2,
                Status = WacAttachmentStatus.Success
            });
        }
예제 #8
0
 internal static void OnCacheEntryExpired(CachedAttachmentInfo attachmentInfo)
 {
     SimulatedWebRequestContext.ExecuteWithoutUserContext("WAC.CacheEntryExpired", delegate(RequestDetailsLogger logger)
     {
         WacUtilities.SetEventId(logger, "WAC.CacheEntryExpired");
         logger.ActivityScope.SetProperty(OwaServerLogger.LoggerData.PrimarySmtpAddress, attachmentInfo.MailboxSmtpAddress);
         CobaltStore store = attachmentInfo.CobaltStore;
         ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
         {
             store.Saver.SaveAndLogExceptions(logger);
         });
         store.Dispose();
         Exception exception = adoperationResult.Exception;
         if (exception != null)
         {
             logger.ActivityScope.SetProperty(ServiceCommonMetadata.GenericErrors, exception.ToString());
         }
     });
 }
예제 #9
0
        private static void ProcessCheckFileRequest(HttpContext context, WacRequest wacRequest, RequestDetailsLogger logger)
        {
            WacRequestHandler.UpdateAttachment(wacRequest, logger);
            CachedAttachmentInfo cachedAttachmentInfo = WacRequestHandler.GetCachedAttachmentInfo(wacRequest);
            string attachmentStreamHash   = null;
            long   attachmentStreamLength = 0L;
            string attachmentFileName     = null;
            string attachmentExtension    = null;
            bool   attachmentIsProtected  = false;

            WacRequestHandler.ProcessAttachment(wacRequest, PropertyOpenMode.ReadOnly, delegate(IExchangePrincipal exchangePrincipal, Attachment attachment, Stream stream, bool isProtected)
            {
                attachmentStreamHash   = WacUtilities.GenerateSHA256HashForStream(stream);
                attachmentStreamLength = stream.Length;
                attachmentFileName     = attachment.FileName;
                attachmentExtension    = attachment.FileExtension;
                attachmentIsProtected  = isProtected;
            });
            WacFileRep           wacFileRep           = wacRequest.WacFileRep;
            string               downloadUrl          = WacRequestHandler.GetDownloadUrl(context.Request, wacFileRep, wacRequest);
            WacCheckFileResponse wacCheckFileResponse = new WacCheckFileResponse(attachmentFileName, attachmentStreamLength, attachmentStreamHash, downloadUrl, cachedAttachmentInfo.MailboxSmtpAddress, cachedAttachmentInfo.LogonSmtpAddress, cachedAttachmentInfo.LogonDisplayName, cachedAttachmentInfo.LogonPuid, attachmentIsProtected, wacFileRep.DirectFileAccessEnabled, wacFileRep.WacExternalServicesEnabled, wacFileRep.OMEXEnabled);

            if (wacFileRep.IsEdit)
            {
                wacCheckFileResponse.UserCanWrite    = true;
                wacCheckFileResponse.ReadOnly        = false;
                wacCheckFileResponse.SupportsUpdate  = true;
                wacCheckFileResponse.SupportsLocks   = true;
                wacCheckFileResponse.SupportsCobalt  = true;
                wacCheckFileResponse.SupportsFolders = true;
            }
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(WacCheckFileResponse));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                dataContractJsonSerializer.WriteObject(memoryStream, wacCheckFileResponse);
                memoryStream.Position = 0L;
                context.Response.OutputStream.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
            }
        }
예제 #10
0
 private static CachedAttachmentInfo GetCachedAttachmentInfo(WacRequest wacRequest)
 {
     return(CachedAttachmentInfo.GetInstance(wacRequest.MailboxSmtpAddress.ToString(), wacRequest.EwsAttachmentId, wacRequest.ExchangeSessionId, wacRequest.WacFileRep.LogonSid, wacRequest.CultureName));
 }
예제 #11
0
        private static void DecrementLockCount(WacRequest wacRequest)
        {
            CachedAttachmentInfo cachedAttachmentInfo = WacRequestHandler.GetCachedAttachmentInfo(wacRequest);

            cachedAttachmentInfo.DecrementLockCount();
        }
예제 #12
0
        private static CobaltStore CreateCobaltStore(IExchangePrincipal exchangePrincipal, Attachment attachment, WacRequest wacRequest, CachedAttachmentInfo attachmentInfo)
        {
            if (exchangePrincipal == null)
            {
                throw new ArgumentException("exchangePrincipal");
            }
            if (exchangePrincipal.MailboxInfo.IsRemote)
            {
                throw new OwaInvalidRequestException("Remote mailboxes are not supported.");
            }
            Guid        objectGuid         = exchangePrincipal.MailboxInfo.MailboxDatabase.ObjectGuid;
            bool        diagnosticsEnabled = WacConfiguration.Instance.DiagnosticsEnabled;
            MdbCache    instance           = MdbCache.GetInstance();
            string      path          = instance.GetPath(objectGuid);
            string      correlationId = HttpContext.Current.Request.Headers["X-WOPI-CorrelationID"];
            CobaltStore store         = new CobaltStore(path, objectGuid.ToString(), correlationId, diagnosticsEnabled, WacConfiguration.Instance.BlobStoreMemoryBudget);

            using (Stream contentStream = ((StreamAttachment)attachment).GetContentStream(PropertyOpenMode.ReadOnly))
            {
                store.Save(contentStream);
            }
            store.Saver.Initialize((string)wacRequest.MailboxSmtpAddress, wacRequest.ExchangeSessionId, WacConfiguration.Instance.AutoSaveInterval, delegate
            {
                using (Stream documentStream = store.GetDocumentStream())
                {
                    WacRequestHandler.ReplaceAttachmentContent(documentStream, wacRequest);
                }
                return(true);
            }, delegate(Exception exception)
            {
                store.SaveFailed(exception);
            });
            return(store);
        }