// 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: 0x06000215 RID: 533 RVA: 0x00008674 File Offset: 0x00006874
        private static DownloadResult TryTwice(HttpClient httpClient, HttpSessionConfig sessionConfig, string url)
        {
            ICancelableAsyncResult cancelableAsyncResult = httpClient.BeginDownload(new Uri(url), sessionConfig, null, null);

            cancelableAsyncResult.AsyncWaitHandle.WaitOne();
            DownloadResult result = httpClient.EndDownload(cancelableAsyncResult);

            if (result.Exception != null)
            {
                if (!result.IsRetryable)
                {
                    throw result.Exception;
                }
                cancelableAsyncResult = httpClient.BeginDownload(new Uri(url), sessionConfig, null, null);
                cancelableAsyncResult.AsyncWaitHandle.WaitOne();
                result = httpClient.EndDownload(cancelableAsyncResult);
                if (result.Exception != null)
                {
                    throw result.Exception;
                }
            }
            return(result);
        }
Example #3
0
        private static void AcquireCertificationMexCallback(ICancelableAsyncResult asyncResult)
        {
            RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireCertificationMexCallback invoked");
            ArgumentValidator.ThrowIfNull("asyncResult", asyncResult);
            ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState);
            AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult;

            if (acquireServerInfoAsyncResult == null)
            {
                throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult.");
            }
            acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireCertificationMexCallback);
            Exception ex = null;

            try
            {
                DownloadResult downloadResult = acquireServerInfoAsyncResult.HttpClient.EndDownload(asyncResult);
                acquireServerInfoAsyncResult.LatencyTracker.EndTrackRmsLatency(RmsOperationType.AcquireCertificationMexData);
                if (downloadResult.IsSucceeded)
                {
                    Uri targetUriFromResponse = RmsClientManagerUtils.GetTargetUriFromResponse(downloadResult.ResponseStream);
                    if (targetUriFromResponse == null)
                    {
                        ex = new RightsManagementException(RightsManagementFailureCode.FailedToExtractTargetUriFromMex, ServerStrings.FailedToFindTargetUriFromMExData(acquireServerInfoAsyncResult.CertificationMExUri), acquireServerInfoAsyncResult.LicenseUri.ToString());
                    }
                    else
                    {
                        acquireServerInfoAsyncResult.ServerInfo.CertificationWSTargetUri = TokenTarget.Fix(targetUriFromResponse);
                        acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginDownloadServerLicensingMexData);
                        WebProxy localServerProxy;
                        try
                        {
                            localServerProxy = RmsClientManagerUtils.GetLocalServerProxy(true);
                        }
                        catch (ExchangeConfigurationException ex2)
                        {
                            ex = ex2;
                            return;
                        }
                        HttpSessionConfig httpSessionConfig = new HttpSessionConfig();
                        if (localServerProxy != null)
                        {
                            httpSessionConfig.Proxy = localServerProxy;
                        }
                        acquireServerInfoAsyncResult.LatencyTracker.BeginTrackRmsLatency(RmsOperationType.AcquireServerLicensingMexData);
                        acquireServerInfoAsyncResult.HttpClient.BeginDownload(acquireServerInfoAsyncResult.ServerLicensingMExUri, httpSessionConfig, RmsClientManagerUtils.WrapCancellableCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new CancelableAsyncCallback(RmsServerInfoManager.AcquireServerLicensingMexCallback)), acquireServerInfoAsyncResult);
                    }
                }
                else
                {
                    RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Failed to download data from certification MEx {0}.  Exception is {1}", new object[]
                    {
                        acquireServerInfoAsyncResult.CertificationMExUri,
                        downloadResult.Exception
                    });
                    ex = new RightsManagementException(RightsManagementFailureCode.FailedToDownloadMexData, ServerStrings.FailedToDownloadCertificationMExData(downloadResult.ResponseUri), downloadResult.Exception, acquireServerInfoAsyncResult.LicenseUri.ToString());
                    ((RightsManagementException)ex).IsPermanent = !downloadResult.IsRetryable;
                }
            }
            finally
            {
                if (ex != null)
                {
                    acquireServerInfoAsyncResult.Release();
                    RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks");
                    RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex);
                }
            }
        }
        // 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);
        }
Example #5
0
        private static void AcquireServiceLocationCallback(IAsyncResult asyncResult)
        {
            RmsServerInfoManager.Tracer.TraceDebug(0L, "AcquireServiceLocationCallback invoked");
            ArgumentValidator.ThrowIfNull("asyncResult", asyncResult);
            ArgumentValidator.ThrowIfNull("asyncResult.AsyncState", asyncResult.AsyncState);
            AcquireServerInfoAsyncResult acquireServerInfoAsyncResult = asyncResult.AsyncState as AcquireServerInfoAsyncResult;

            if (acquireServerInfoAsyncResult == null)
            {
                throw new InvalidOperationException("asyncResult.AsyncState has to be type of AcquireServerInfoAsyncResult.");
            }
            acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.AcquireServiceLocationCallback);
            Exception ex = null;

            try
            {
                acquireServerInfoAsyncResult.ServiceLocationResponses = acquireServerInfoAsyncResult.ServerWSManager.EndFindServiceLocations(asyncResult);
                LocalizedString value;
                if (!RmsServerInfoManager.ValidateResponsesAndUpdateServerInfo(acquireServerInfoAsyncResult, out value))
                {
                    ex = new RightsManagementException(RightsManagementFailureCode.FindServiceLocationFailed, ServerStrings.ValidationForServiceLocationResponseFailed(acquireServerInfoAsyncResult.LicenseUri, value));
                }
                else
                {
                    HttpSessionConfig httpSessionConfig = new HttpSessionConfig();
                    WebProxy          localServerProxy  = RmsClientManagerUtils.GetLocalServerProxy(true);
                    if (localServerProxy != null)
                    {
                        httpSessionConfig.Proxy = localServerProxy;
                    }
                    acquireServerInfoAsyncResult.HttpClient = new HttpClient();
                    acquireServerInfoAsyncResult.AddBreadCrumb(Constants.State.BeginDownloadCertificationMexData);
                    acquireServerInfoAsyncResult.LatencyTracker.BeginTrackRmsLatency(RmsOperationType.AcquireCertificationMexData);
                    acquireServerInfoAsyncResult.HttpClient.BeginDownload(acquireServerInfoAsyncResult.CertificationMExUri, httpSessionConfig, RmsClientManagerUtils.WrapCancellableCallbackWithUnhandledExceptionHandlerAndUpdatePoisonContext(new CancelableAsyncCallback(RmsServerInfoManager.AcquireCertificationMexCallback)), acquireServerInfoAsyncResult);
                }
            }
            catch (RightsManagementException ex2)
            {
                RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Hit an exception during AcquireServiceLocationCallback {0}", new object[]
                {
                    ex2
                });
                ex = ex2;
            }
            catch (ExchangeConfigurationException ex3)
            {
                RmsClientManager.TraceFail(null, acquireServerInfoAsyncResult.Context.SystemProbeId, "Hit an exception during AcquireServiceLocationCallback {0}", new object[]
                {
                    ex3
                });
                ex = ex3;
            }
            finally
            {
                if (ex != null)
                {
                    acquireServerInfoAsyncResult.Release();
                    RmsServerInfoManager.Tracer.TraceError(0L, "AcquireServiceLocationCallback: Invoking find service location callbacks");
                    RmsServerInfoManager.outstandingFindServiceLocationCalls.InvokeCallbacks(acquireServerInfoAsyncResult.LicenseUri, ex);
                }
            }
        }