// Token: 0x0600053A RID: 1338 RVA: 0x0001D034 File Offset: 0x0001B234
        protected override Uri GetTargetBackEndServerUrl()
        {
            Uri uri = base.GetTargetBackEndServerUrl();

            if (base.AnchoredRoutingTarget.BackEndServer.Version < Server.E15MinVersion)
            {
                throw new HttpException(500, string.Format("Version < E14 and a WOPI request?  Should not happen....  AnchorMailbox: {0}", base.AnchoredRoutingTarget.AnchorMailbox));
            }
            if (uri.Query.Length == 0)
            {
                throw new HttpException(400, "Unexpected query string format");
            }
            if (!string.IsNullOrEmpty(this.targetMailboxId))
            {
                UriBuilder uriBuilder = new UriBuilder(uri);
                uriBuilder.Path  = AuthenticatedWopiRequestPathHandler.StripMailboxId(HttpUtility.UrlDecode(uriBuilder.Path), this.targetMailboxId);
                uriBuilder.Query = uri.Query.Substring(1) + "&UserEmail=" + HttpUtility.UrlEncode(this.targetMailboxId);
                uri = uriBuilder.Uri;
            }
            if (HttpProxySettings.DFPOWAVdirProxyEnabled.Value)
            {
                return(UrlUtilities.FixDFPOWAVdirUrlForBackEnd(uri, HttpUtility.ParseQueryString(uri.Query)["vdir"]));
            }
            return(uri);
        }
Esempio n. 2
0
        protected override void AddProtocolSpecificHeadersToServerRequest(WebHeaderCollection headers)
        {
            IIdentity         identity          = base.HttpContext.User.Identity;
            CompositeIdentity compositeIdentity = base.HttpContext.User.Identity as CompositeIdentity;

            if (compositeIdentity != null)
            {
                identity = compositeIdentity.PrimaryIdentity;
            }
            if (!base.ProxyToDownLevel || identity is OAuthIdentity || identity is OAuthPreAuthIdentity || identity is MSAIdentity)
            {
                ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[OwaProxyRequestHandler::AddProtocolSpecificHeadersToServerRequest]: Skip adding downlevel proxy headers.");
            }
            else
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaProxyRequestHandler::AddProtocolSpecificHeadersToServerRequest]: User identity type is {0}.", identity.GetType().FullName);
                headers["X-OWA-ProxySid"] = identity.GetSecurityIdentifier().ToString();
                OwaProxyRequestHandler.AddProxyUriHeader(base.ClientRequest, headers);
                headers["X-OWA-ProxyVersion"] = HttpProxyGlobals.ApplicationVersion;
            }
            if (UrlUtilities.IsCmdWebPart(base.ClientRequest) && !OwaProxyRequestHandler.IsOwa15Url(base.ClientRequest))
            {
                headers["X-OWA-ProxyWebPart"] = "1";
            }
            headers["RPSPUID"]      = (string)base.HttpContext.Items["RPSPUID"];
            headers["RPSOrgIdPUID"] = (string)base.HttpContext.Items["RPSOrgIdPUID"];
            headers["logonLatency"] = (string)base.HttpContext.Items["logonLatency"];
            if (base.IsExplicitSignOn)
            {
                headers["X-OWA-ExplicitLogonUser"] = HttpUtility.UrlDecode(base.ExplicitSignOnAddress);
            }
            base.AddProtocolSpecificHeadersToServerRequest(headers);
        }
Esempio n. 3
0
        protected override Uri GetTargetBackEndServerUrl()
        {
            Uri targetBackEndServerUrl = base.GetTargetBackEndServerUrl();

            if (HttpProxySettings.DFPOWAVdirProxyEnabled.Value)
            {
                string     text       = base.ClientRequest.QueryString[OwaProxyRequestHandler.DFPOWAVdirParam];
                HttpCookie httpCookie = base.ClientRequest.Cookies["X-DFPOWA-Vdir"];
                if (!base.ClientRequest.Url.AbsolutePath.EndsWith("/logoff.owa", StringComparison.OrdinalIgnoreCase))
                {
                    string text2 = string.Empty;
                    if (httpCookie != null && !string.IsNullOrEmpty(httpCookie.Value))
                    {
                        text2 = httpCookie.Value;
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        text = text.Trim();
                        if (OwaProxyRequestHandler.DFPOWAValidVdirValues.Contains(text, StringComparer.OrdinalIgnoreCase))
                        {
                            text2 = text;
                        }
                    }
                    if (!string.IsNullOrEmpty(text2))
                    {
                        return(UrlUtilities.FixDFPOWAVdirUrlForBackEnd(targetBackEndServerUrl, text2));
                    }
                }
            }
            return(UrlUtilities.FixIntegratedAuthUrlForBackEnd(targetBackEndServerUrl));
        }
Esempio n. 4
0
 // Token: 0x06000543 RID: 1347 RVA: 0x0001D1C8 File Offset: 0x0001B3C8
 private string GetExplicitLogonAddress()
 {
     string text = null;
     if (UrlUtilities.TryGetExplicitLogonUser(base.ClientRequest, ref text) && ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
     {
         ExTraceGlobals.VerboseTracer.TraceDebug<int, string>((long)this.GetHashCode(), "[OwaDownloadProxyRequestHandler::GetExplicitLogonAddress]: Context {0}; candidate explicit logon address: {1}", base.TraceContext, text);
     }
     return text;
 }
        // Token: 0x060005A0 RID: 1440 RVA: 0x0001F3C4 File Offset: 0x0001D5C4
        protected override Uri UpdateExternalRedirectUrl(Uri originalRedirectUrl)
        {
            UriBuilder uriBuilder = new UriBuilder(originalRedirectUrl);

            if (!string.IsNullOrEmpty(this.ExplicitSignOnAddress))
            {
                uriBuilder.Path = UrlUtilities.GetPathWithExplictLogonHint(originalRedirectUrl, this.ExplicitSignOnAddress);
            }
            return(uriBuilder.Uri);
        }
        // Token: 0x060005A3 RID: 1443 RVA: 0x0001F424 File Offset: 0x0001D624
        protected override UriBuilder GetClientUrlForProxy()
        {
            UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url.OriginalString);

            if (this.IsExplicitSignOn && !UrlUtilities.IsOwaDownloadRequest(base.ClientRequest.Url))
            {
                uriBuilder.Path = UrlHelper.RemoveExplicitLogonFromUrlAbsolutePath(HttpUtility.UrlDecode(base.ClientRequest.Url.AbsolutePath), HttpUtility.UrlDecode(this.ExplicitSignOnAddress));
            }
            return(uriBuilder);
        }
Esempio n. 7
0
        public static Uri FixIntegratedAuthUrlForBackEnd(Uri url)
        {
            if (!UrlUtilities.IsIntegratedAuthUrl(url))
            {
                return(url);
            }
            UriBuilder uriBuilder   = new UriBuilder(url);
            string     absolutePath = url.AbsolutePath;
            int        num          = url.AbsolutePath.IndexOf(Constants.IntegratedAuthPath, StringComparison.OrdinalIgnoreCase);

            uriBuilder.Path = absolutePath.Substring(0, num) + absolutePath.Substring(num + Constants.IntegratedAuthPath.Length);
            return(uriBuilder.Uri);
        }
        // Token: 0x060005D2 RID: 1490 RVA: 0x000205F8 File Offset: 0x0001E7F8
        private string GetCrossPremiseRedirectUrl(string domainName, string externalDirectoryOrgId, string externalEmailAddress)
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            string value = UrlUtilities.IsConsumerRequestForO365(base.HttpContext) ? OwaProxyRequestHandler.SilentRedirection : OwaProxyRequestHandler.ManualRedirection;

            nameValueCollection.Add("redirectType", value);
            nameValueCollection.Add("extDomain", domainName);
            nameValueCollection.Add("extDirOrgId", externalDirectoryOrgId);
            if (CafeConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).AddExternalEmailAddressToRedirectURL.Enabled)
            {
                nameValueCollection.Add("extEmail", externalEmailAddress);
            }
            return(AspNetHelper.GetCafeErrorPageRedirectUrl(base.HttpContext, nameValueCollection));
        }
Esempio n. 9
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                LatencyTracker latencyTracker = new LatencyTracker();
                latencyTracker.StartTracking(LatencyTrackerKey.ProxyModuleLatency, false);
                AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Request.Headers, "X-FrontEnd-Begin");
                if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug <string, Uri, int>((long)this.GetHashCode(), "[ProxyModule::OnBeginRequest]: Method {0}; Url {1}; Context {2};", httpContext.Request.HttpMethod, httpContext.Request.Url, httpContext.GetHashCode());
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    HealthCheckResponder.Instance.CheckHealthStateAndRespond(httpContext);
                    return;
                }
                RequestDetailsLogger requestDetailsLogger = RequestDetailsLoggerBase <RequestDetailsLogger> .InitializeRequestLogger();
                requestDetailsLogger.LogCurrentTime("BeginRequest");
                httpContext.Items[Constants.TraceContextKey] = httpContext.GetHashCode();
                httpContext.Items[Constants.LatencyTrackerContextKeyName] = latencyTracker;
                requestDetailsLogger.ActivityScope.UpdateFromMessage(httpContext.Request);
                requestDetailsLogger.ActivityScope.SerializeTo(httpContext.Response);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SetCurrent(httpContext, requestDetailsLogger);
                httpContext.Items[typeof(ActivityScope)] = requestDetailsLogger.ActivityScope;
                httpContext.Items[Constants.RequestIdHttpContextKeyName] = requestDetailsLogger.ActivityScope.ActivityId;
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.Protocol, HttpProxyGlobals.ProtocolType);
                requestDetailsLogger.SafeLogUriData(httpContext.Request.Url);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, ServiceCommonMetadata.HttpMethod, httpContext.Request.HttpMethod);
                string requestCorrelationId = AspNetHelper.GetRequestCorrelationId(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "CorrelationID", requestCorrelationId);
                httpContext.Response.AppendToLog(Constants.CorrelationIdKeyForIISLogs + requestCorrelationId + ";");
                string cookieValueAndSetIfNull = ClientIdCookie.GetCookieValueAndSetIfNull(httpContext);
                httpContext.Response.AppendToLog(string.Format("&{0}={1}", "ClientId", cookieValueAndSetIfNull));
                UrlUtilities.SaveOriginalRequestHostSchemePortToContext(httpContext);
                try
                {
                    this.OnBeginRequestInternal(httpApplication);
                }
                catch (Exception ex)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestDetailsLogger, "OnBeginRequestInternal", ex.ToString());
                    requestDetailsLogger.AsyncCommit(false);
                    throw;
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Esempio n. 10
0
        public static bool IsEacUrl(string urlString)
        {
            if (!UrlUtilities.IsEcpUrl(urlString))
            {
                return(false);
            }
            int num = urlString.IndexOf('?');

            if (num > 0)
            {
                string[] source = urlString.Substring(num + 1).Split(new char[]
                {
                    '&'
                });
                return(!source.Contains("rfr=owa") && !source.Contains("rfr=olk"));
            }
            return(true);
        }
        protected override AnchorMailbox ResolveAnchorMailbox()
        {
            string text = base.HttpContext.Items["destination"] as string;
            Uri    uri;

            if (!Uri.TryCreate(text, UriKind.Absolute, out uri))
            {
                throw new HttpException(400, "destination value is not valid");
            }
            string text2 = null;
            bool   flag2;
            string text3;
            bool   flag = FbaFormPostProxyRequestHandler.IsExplicitLogon(HttpRuntime.AppDomainAppVirtualPath, uri.PathAndQuery, uri.OriginalString, out flag2, out text2, out text3);

            if (flag)
            {
                this.explicitLogonUser = text2;
            }
            AnchorMailbox anchorMailbox;

            if (!string.IsNullOrEmpty(this.explicitLogonUser))
            {
                anchorMailbox = new SmtpAnchorMailbox(this.explicitLogonUser, this);
            }
            else
            {
                anchorMailbox = AnchorMailboxFactory.CreateFromCaller(this);
            }
            UserBasedAnchorMailbox userBasedAnchorMailbox = anchorMailbox as UserBasedAnchorMailbox;

            if (userBasedAnchorMailbox != null)
            {
                if (UrlUtilities.IsEacUrl(text))
                {
                    userBasedAnchorMailbox.CacheKeyPostfix = "_EAC";
                }
                else
                {
                    userBasedAnchorMailbox.MissingDatabaseHandler = new Func <ADRawEntry, ADObjectId>(base.ResolveMailboxDatabase);
                }
            }
            return(anchorMailbox);
        }
Esempio n. 12
0
        // Token: 0x060005F1 RID: 1521 RVA: 0x000210E0 File Offset: 0x0001F2E0
        protected virtual bool AllowAnonymousRequest(HttpRequest httpRequest)
        {
            if (HttpProxyGlobals.ProtocolType == 14)
            {
                return(false);
            }
            if (HttpProxyGlobals.ProtocolType == 21)
            {
                return(true);
            }
            if (HttpProxyGlobals.ProtocolType == 22)
            {
                return(true);
            }
            UriBuilder uriBuilder = new UriBuilder(httpRequest.Url);
            string     text       = null;

            if (UrlUtilities.TryGetExplicitLogonUser(httpRequest, ref text))
            {
                uriBuilder.Path = UrlUtilities.GetPathWithExplictLogonHint(httpRequest.Url, text);
            }
            return(WopiRequestPathHandler.IsWopiRequest(httpRequest.HttpMethod, httpRequest.Url, AuthCommon.IsFrontEnd) || AnonymousCalendarProxyRequestHandler.IsAnonymousCalendarRequest(httpRequest) || OwaExtensibilityProxyRequestHandler.IsOwaExtensibilityRequest(httpRequest) || UrlUtilities.IsOwaDownloadRequest(uriBuilder.Uri) || OwaCobrandingRedirProxyRequestHandler.IsCobrandingRedirRequest(httpRequest) || E4eProxyRequestHandler.IsE4ePayloadRequest(httpRequest) || httpRequest.IsWsSecurityRequest() || PsgwProxyRequestHandler.IsPsgwRequest(httpRequest));
        }
 // Token: 0x060005B6 RID: 1462 RVA: 0x0001E8DA File Offset: 0x0001CADA
 protected override Uri GetTargetBackEndServerUrl()
 {
     return(UrlUtilities.FixIntegratedAuthUrlForBackEnd(base.GetTargetBackEndServerUrl()));
 }
        private void HandleFbaFormPost(BackEndServer backEndServer)
        {
            HttpContext      httpContext            = base.HttpContext;
            HttpResponse     response               = httpContext.Response;
            Uri              uri                    = null;
            string           text                   = httpContext.Items["destination"] as string;
            bool             flag                   = false;
            bool             flag2                  = false;
            bool             flag3                  = true;
            string           fqdn                   = backEndServer.Fqdn;
            int              version                = backEndServer.Version;
            OwaServerVersion owaServerVersion       = null;
            bool             flag4                  = false;
            ServiceTopology  currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\FbaFormPostProxyRequestHandler.cs", "HandleFbaFormPost", 780);
            Site             site                   = currentServiceTopology.GetSite(fqdn, "f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\FbaFormPostProxyRequestHandler.cs", "HandleFbaFormPost", 781);

            if (site != null && !site.Equals(HttpProxyGlobals.LocalSite.Member))
            {
                flag3 = false;
            }
            if (!FbaFormPostProxyRequestHandler.DisableSSORedirects)
            {
                owaServerVersion = OwaServerVersion.CreateFromVersionNumber(version);
                if (UrlUtilities.IsEcpUrl(text) && owaServerVersion.Major < (int)ExchangeObjectVersion.Exchange2010.ExchangeBuild.Major)
                {
                    flag  = false;
                    flag2 = false;
                }
                else if (!flag3 && !UserAgentParser.IsMonitoringRequest(base.ClientRequest.UserAgent))
                {
                    if (owaServerVersion.Major >= (int)ExchangeObjectVersion.Exchange2007.ExchangeBuild.Major)
                    {
                        FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause legacyRedirectFailureCause = FbaFormPostProxyRequestHandler.NeedCrossSiteRedirect(backEndServer, site, HttpProxyGlobals.LocalSite.Member, owaServerVersion, UrlUtilities.IsEcpUrl(text), out uri, out flag4);
                        string authority = base.ClientRequest.Url.Authority;
                        string b         = (uri == null) ? string.Empty : uri.Authority;
                        flag2 = (legacyRedirectFailureCause != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.NoCasFound && !string.Equals(authority, b, StringComparison.OrdinalIgnoreCase) && (legacyRedirectFailureCause != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null));
                        if (uri == null && owaServerVersion.Major == (int)ExchangeObjectVersion.Exchange2007.ExchangeBuild.Major)
                        {
                            flag = (FbaFormPostProxyRequestHandler.NeedOnSiteLegacyRedirect(backEndServer, null, HttpProxyGlobals.LocalSite.Member, owaServerVersion, out uri, out flag4) != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null);
                        }
                    }
                }
                else
                {
                    flag = (FbaFormPostProxyRequestHandler.NeedOnSiteLegacyRedirect(backEndServer, site, HttpProxyGlobals.LocalSite.Member, owaServerVersion, out uri, out flag4) != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null);
                }
            }
            if (flag2 || flag)
            {
                if (uri != null)
                {
                    string authority2 = base.ClientRequest.Url.Authority;
                    string authority3 = uri.Authority;
                    if (string.Compare(authority2, authority3, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new HttpException(403, "Redirect loop detected");
                    }
                }
                using (SecureNameValueCollection secureNameValueCollection = new SecureNameValueCollection())
                {
                    int num = (int)base.HttpContext.Items["flags"];
                    secureNameValueCollection.AddUnsecureNameValue("destination", base.HttpContext.Items["destination"] as string);
                    secureNameValueCollection.AddUnsecureNameValue("username", base.HttpContext.Items["username"] as string);
                    secureNameValueCollection.AddUnsecureNameValue("flags", num.ToString(CultureInfo.InvariantCulture));
                    using (SecureString secureString = base.HttpContext.Items["password"] as SecureString)
                    {
                        secureNameValueCollection.AddSecureNameValue("password", secureString);
                        if (flag)
                        {
                            if (uri == null)
                            {
                                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoLegacyCAS);
                            }
                            else if (flag4)
                            {
                                if (uri.Scheme == Uri.UriSchemeHttps)
                                {
                                    ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - SSO redirecting to {0}", uri.ToString());
                                    this.RedirectUsingSSOFBA(secureNameValueCollection, uri, response, owaServerVersion.Major);
                                    response.End();
                                }
                                else
                                {
                                    AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
                                }
                            }
                            else
                            {
                                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", uri.ToString());
                                base.PfdTracer.TraceRedirect("FbaAuth", uri.ToString());
                                response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(uri.ToString()));
                            }
                        }
                        else if (flag2)
                        {
                            if (uri == null)
                            {
                                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoLegacyCAS);
                            }
                            else
                            {
                                Uri uri2 = uri;
                                if (this.explicitLogonUser != null)
                                {
                                    uri2 = FbaFormPostProxyRequestHandler.AppendSmtpAddressToUrl(uri, this.explicitLogonUser);
                                }
                                if (flag4)
                                {
                                    if (uri.Scheme == Uri.UriSchemeHttps)
                                    {
                                        ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - SSO redirecting to {0}", uri.ToString());
                                        this.RedirectUsingSSOFBA(secureNameValueCollection, uri, response, owaServerVersion.Major);
                                        response.End();
                                    }
                                    else
                                    {
                                        AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
                                    }
                                }
                                else
                                {
                                    ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", uri2.ToString());
                                    base.PfdTracer.TraceRedirect("FbaAuth", uri2.ToString());
                                    response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(uri2.ToString()));
                                }
                            }
                        }
                    }
                    return;
                }
            }
            try
            {
                FbaModule.SetCadataCookies(base.HttpApplication);
            }
            catch (MissingSslCertificateException)
            {
                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", text);
            base.PfdTracer.TraceRedirect("FbaAuth", text);
            response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(text), false);
        }
Esempio n. 15
0
        // Token: 0x060005F5 RID: 1525 RVA: 0x00021738 File Offset: 0x0001F938
        private IHttpHandler SelectHandlerForUnauthenticatedRequest(HttpContext httpContext)
        {
            IHttpHandler result;

            try
            {
                if (HttpProxySettings.NeedHandleAsAuthenticatedRequest(httpContext.Request.Headers, httpContext.Request.Cookies, httpContext.SkipAuthorization))
                {
                    result = this.SelectHandlerForAuthenticatedRequest(httpContext);
                }
                else
                {
                    UriBuilder uriBuilder = new UriBuilder(httpContext.Request.Url);
                    string     text       = null;
                    if (UrlUtilities.TryGetExplicitLogonUser(httpContext.Request, ref text))
                    {
                        uriBuilder.Path = UrlUtilities.GetPathWithExplictLogonHint(httpContext.Request.Url, text);
                    }
                    IHttpHandler httpHandler = null;
                    if (HttpProxyGlobals.ProtocolType == 9)
                    {
                        httpHandler = new AutodiscoverProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 2)
                    {
                        if (RequestPathParser.IsEwsUnauthenticatedRequestProxyHandlerAllowed(httpContext.Request))
                        {
                            httpHandler = new EwsProxyRequestHandler();
                        }
                    }
                    else if (HttpProxyGlobals.ProtocolType == 27)
                    {
                        if (RequestPathParser.IsRestUnauthenticatedRequestProxyHandlerAllowed(httpContext.Request))
                        {
                            httpHandler = new RestProxyRequestHandler();
                        }
                    }
                    else if (HttpProxyGlobals.ProtocolType == 1)
                    {
                        if (EDiscoveryExportToolProxyRequestHandler.IsEDiscoveryExportToolProxyRequest(httpContext.Request))
                        {
                            httpHandler = new EDiscoveryExportToolProxyRequestHandler();
                        }
                        else if (BEResourceRequestHandler.CanHandle(httpContext.Request))
                        {
                            httpHandler = new BEResourceRequestHandler();
                        }
                        else if (EcpProxyRequestHandler.IsCrossForestDelegatedRequest(httpContext.Request))
                        {
                            httpHandler = new EcpProxyRequestHandler
                            {
                                IsCrossForestDelegated = true
                            };
                        }
                        else if (!httpContext.Request.Path.StartsWith("/ecp/auth/", StringComparison.OrdinalIgnoreCase) && !httpContext.Request.Path.Equals("/ecp/ping.ecp", StringComparison.OrdinalIgnoreCase))
                        {
                            httpHandler = new Return401RequestHandler();
                        }
                    }
                    else if (HttpProxyGlobals.ProtocolType == 8)
                    {
                        httpHandler = new RpcHttpRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 12)
                    {
                        httpHandler = new XRopProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 15)
                    {
                        httpHandler = new E4eProxyRequestHandler();
                    }
                    else if (AnonymousCalendarProxyRequestHandler.IsAnonymousCalendarRequest(httpContext.Request))
                    {
                        httpHandler = new AnonymousCalendarProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 4 && WopiRequestPathHandler.IsWopiRequest(httpContext.Request.HttpMethod, httpContext.Request.Url, AuthCommon.IsFrontEnd))
                    {
                        httpHandler = new WopiProxyRequestHandler();
                    }
                    else if (OwaExtensibilityProxyRequestHandler.IsOwaExtensibilityRequest(httpContext.Request))
                    {
                        httpHandler = new OwaExtensibilityProxyRequestHandler();
                    }
                    else if (UrlUtilities.IsOwaDownloadRequest(uriBuilder.Uri))
                    {
                        httpHandler = new OwaDownloadProxyRequestHandler();
                    }
                    else if (OwaCobrandingRedirProxyRequestHandler.IsCobrandingRedirRequest(httpContext.Request))
                    {
                        httpHandler = new OwaCobrandingRedirProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 4 && OwaResourceProxyRequestHandler.CanHandle(httpContext.Request))
                    {
                        httpHandler = new OwaResourceProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 19)
                    {
                        httpHandler = new PsgwProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 21)
                    {
                        httpHandler = new MailboxDeliveryProxyRequestHandler();
                    }
                    else if (HttpProxyGlobals.ProtocolType == 22)
                    {
                        httpHandler = new ComplianceServiceProxyRequestHandler();
                    }
                    result = httpHandler;
                }
            }
            finally
            {
                long currentLatency = LatencyTracker.FromHttpContext(httpContext).GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);
                if (currentLatency > 100L)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext), "SelectHandler", currentLatency);
                }
            }
            return(result);
        }
Esempio n. 16
0
        protected override void OnEndRequestInternal(HttpApplication httpApplication)
        {
            HttpRequest          request  = httpApplication.Context.Request;
            HttpResponse         response = httpApplication.Context.Response;
            RequestDetailsLogger current  = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpApplication.Context);

            if (httpApplication.Context.Items[Constants.RequestCompletedHttpContextKeyName] == null && !UrlUtilities.IsIntegratedAuthUrl(request.Url) && !UrlUtilities.IsOwaMiniUrl(request.Url) && (response.StatusCode == 401 || (HttpProxyGlobals.ProtocolType == ProtocolType.Ecp && (response.StatusCode == 403 || response.StatusCode == 404))))
            {
                FbaModule.LogonReason reason = FbaModule.LogonReason.None;
                if (request.Headers["Authorization"] != null)
                {
                    reason = FbaModule.LogonReason.InvalidCredentials;
                }
                bool flag = request.Url.AbsolutePath.Equals("/owa/auth.owa", StringComparison.OrdinalIgnoreCase);
                if (request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase) || flag)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "NoCookies", "302 - GET/E14AuthPost");

                    this.RedirectToFbaLogon(httpApplication, reason);
                }
                else if (request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase))
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "NoCookies", "440 - POST");

                    this.Send440Response(httpApplication, true);
                }
                else
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(current, "NoCookies", "440 - " + request.HttpMethod);

                    this.Send440Response(httpApplication, false);
                }
            }
            base.OnEndRequestInternal(httpApplication);
        }
Esempio n. 17
0
        private bool RedirectToFbaLogon(HttpApplication httpApplication, FbaModule.LogonReason reason)
        {
            HttpContext  context  = httpApplication.Context;
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            Utility.DeleteFbaAuthCookies(request, response);
            UriBuilder uriBuilder = new UriBuilder();

            uriBuilder.Host = request.Url.Host;
            int port = uriBuilder.Port;

            uriBuilder.Scheme = FbaModule.GetExternalUrlScheme(ref port);
            uriBuilder.Port   = port;
            uriBuilder.Path   = "/owa/auth/logon.aspx";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("url=");
            if (this.destinationUrl != null)
            {
                stringBuilder.Append(HttpUtility.UrlEncode(new UriBuilder(this.destinationUrl)
                {
                    Scheme = uriBuilder.Scheme,
                    Port   = uriBuilder.Port
                }.Uri.AbsoluteUri.ToString()));
            }
            else
            {
                string text = new UriBuilder(request.GetFullRawUrl())
                {
                    Scheme = uriBuilder.Scheme,
                    Port   = uriBuilder.Port
                }.Uri.AbsoluteUri;
                string strB = request.Url.Segments[request.Url.Segments.Length - 1];
                if (string.Compare("auth.owa", strB, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    int startIndex = text.LastIndexOf("auth.owa") - 1;
                    text = text.Remove(startIndex);
                }
                string text2 = HttpUtility.UrlDecode(request.Headers["X-OWA-ExplicitLogonUser"]);
                if (!string.IsNullOrEmpty(text2) && !text.Contains(text2))
                {
                    string value           = HttpUtility.UrlEncode("/");
                    string applicationPath = request.ApplicationPath;
                    int    num             = text.IndexOf(applicationPath, StringComparison.OrdinalIgnoreCase);
                    if (num == -1)
                    {
                        stringBuilder.Append(HttpUtility.UrlEncode(text));
                        if (text[text.Length - 1] != '/')
                        {
                            stringBuilder.Append(value);
                        }
                        stringBuilder.Append(HttpUtility.UrlEncode(text2));
                        stringBuilder.Append(value);
                    }
                    else
                    {
                        num += applicationPath.Length;
                        if (num < text.Length && text[num] == '/')
                        {
                            num++;
                        }
                        stringBuilder.Append(HttpUtility.UrlEncode(text.Substring(0, num)));
                        if (text[num - 1] != '/')
                        {
                            stringBuilder.Append(value);
                        }
                        stringBuilder.Append(HttpUtility.UrlEncode(text2));
                        stringBuilder.Append(value);
                        stringBuilder.Append(HttpUtility.UrlEncode(text.Substring(num)));
                    }
                }
                else
                {
                    int    num2  = text.IndexOf('?');
                    string text3 = null;
                    if (text.ToLowerInvariant().Contains("logoff.owa"))
                    {
                        if (!LogOnSettings.IsLegacyLogOff)
                        {
                            uriBuilder.Path = "/owa/" + LogOnSettings.SignOutPageUrl;
                        }
                        if (num2 >= 0)
                        {
                            string[] source = text.Substring(num2 + 1).Split(new char[]
                            {
                                '&'
                            });
                            string text4 = source.FirstOrDefault((string x) => x.StartsWith("url=", StringComparison.OrdinalIgnoreCase));
                            if (text4 != null)
                            {
                                text3 = text4.Substring("url=".Length);
                            }
                        }
                    }
                    if (text3 == null)
                    {
                        string str;
                        text3 = ((!UrlUtilities.IsCmdWebPart(request) && UrlUtilities.ShouldRedirectQueryParamsAsHashes(new Uri(text), out str)) ? HttpUtility.UrlEncode(str) : HttpUtility.UrlEncode(text));
                    }
                    stringBuilder.Append(text3);
                }
            }
            stringBuilder.AppendFormat("&reason={0}", (int)reason);
            uriBuilder.Query = stringBuilder.ToString();
            ExTraceGlobals.VerboseTracer.TraceDebug <FbaModule.LogonReason, string>((long)this.GetHashCode(), "RedirectToFbaLogon - Reason: {0}, URL: {1}", reason, uriBuilder.ToString());
            base.PfdTracer.TraceRedirect("FbaAuth", uriBuilder.ToString());
            response.Redirect(uriBuilder.ToString(), false);
            httpApplication.CompleteRequest();
            return(true);
        }