Example #1
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpContext httpContext = HttpContext.Current;
            HttpRequest request     = httpContext.Request;

            if (RequestFilterModule.BlockNonCafeRequest)
            {
                string a = HttpContext.Current.Request.Headers[WellKnownHeader.XIsFromCafe];
                if (!string.Equals(a, "1"))
                {
                    httpContext.Response.Headers.Set("X-BlockDirectBERequest", "1");
                    throw new BadRequestException();
                }
            }
            if (Utility.IsResourceRequest(request.Url.LocalPath))
            {
                return;
            }
            httpContext.Response.Headers.Set("X-Content-Type-Options", "nosniff");
            this.ProcessFeatureRedirection(httpContext, request);
            RequestTypeInfo requestTypeInfo = RequestFilterModule.DetermineRequestType(request);

            this.StampTokenToHeader(httpContext, request, requestTypeInfo);
            this.HandleRedirection(httpContext, request, requestTypeInfo);
        }
Example #2
0
        private void HandleRedirection(HttpContext httpContext, HttpRequest request, RequestTypeInfo requestTypeInfo)
        {
            string text = null;

            if (requestTypeInfo.Need302Redirect)
            {
                text = request.RawUrl.Insert(request.FilePath.Length, "/");
            }
            else if (requestTypeInfo.NeedRedirectTargetTenant)
            {
                text = EcpUrl.ProcessUrl(request.RawUrl, true);
                text = EcpUrl.RemoveQueryParameter(text, requestTypeInfo.IsDelegatedAdminRequest ? "delegatedorg" : "organizationcontext", false);
            }
            else if (requestTypeInfo.UseImplicitPathRewrite && requestTypeInfo.IsSecurityTokenPresented)
            {
                text = request.Headers[RequestFilterModule.OriginalUrlKey];
            }
            if (text != null)
            {
                ExTraceGlobals.RedirectTracer.TraceInformation <string>(0, 0L, "[RequestFilterModule::HandleRedirection] Redirect to {0}).", text);
                httpContext.Response.Redirect(text, true);
            }
        }
Example #3
0
        internal static RequestTypeInfo DetermineRequestType(HttpRequest httpRequest)
        {
            string filePath = httpRequest.FilePath;
            NameValueCollection queryString = httpRequest.QueryString;
            RequestTypeInfo     result      = default(RequestTypeInfo);
            string text = queryString["delegatedorg"];

            if (!string.IsNullOrEmpty(text))
            {
                result.NeedRedirectTargetTenant = true;
                result.IsDelegatedAdminRequest  = true;
                result.TargetTenant             = text;
            }
            string text2 = queryString["organizationcontext"];

            if (!string.IsNullOrEmpty(text2))
            {
                result.NeedRedirectTargetTenant = true;
                result.IsByoidAdmin             = true;
                result.TargetTenant             = text2;
            }
            if (result.IsDelegatedAdminRequest && result.IsByoidAdmin)
            {
                throw new BadRequestException(new Exception("Both delegatedorg and organizationcontext parameters are specified in request url."));
            }
            Match match = RequestFilterModule.regex.Match(filePath);

            if (match.Success)
            {
                Group group  = match.Groups["isOrgContext"];
                Group group2 = match.Groups["targetTenant"];
                Group group3 = match.Groups["esoAddress"];
                Group group4 = match.Groups["closeSlash"];
                if (group2.Success)
                {
                    if (result.NeedRedirectTargetTenant)
                    {
                        throw new BadRequestException(new Exception("Both '/@' style and parameter style are used in request url."));
                    }
                    if (group.Success)
                    {
                        result.IsByoidAdmin = true;
                    }
                    else
                    {
                        result.IsDelegatedAdminRequest = true;
                        if (filePath.EndsWith("/", StringComparison.InvariantCulture))
                        {
                            result.UseImplicitPathRewrite = true;
                        }
                        result.IsSecurityTokenPresented = DelegatedAuthenticationModule.IsSecurityTokenPresented(httpRequest);
                    }
                    result.TargetTenant = group2.Value;
                }
                if (group3.Success)
                {
                    result.IsEsoRequest          = true;
                    result.EsoMailboxSmtpAddress = group3.Value;
                }
                if (!group4.Success)
                {
                    result.Need302Redirect = true;
                }
            }
            return(result);
        }
Example #4
0
 private void StampTokenToHeader(HttpContext httpContext, HttpRequest request, RequestTypeInfo requestTypeInfo)
 {
     if (requestTypeInfo.IsDelegatedAdminRequest)
     {
         request.Headers.Set(RequestFilterModule.TargetTenantKey, requestTypeInfo.TargetTenant);
         string text = request.RawUrl;
         if (requestTypeInfo.UseImplicitPathRewrite)
         {
             text = text.Insert(request.FilePath.Length, "default.aspx");
         }
         request.Headers.Set(RequestFilterModule.OriginalUrlKey, text);
         if (requestTypeInfo.IsSecurityTokenPresented)
         {
             httpContext.Items[RequestFilterModule.NoResolveIdKey] = "1";
         }
     }
     else if (requestTypeInfo.IsByoidAdmin)
     {
         request.Headers.Set(RequestFilterModule.OrganizationContextKey, requestTypeInfo.TargetTenant);
     }
     if (requestTypeInfo.IsEsoRequest)
     {
         request.Headers.Set("msExchEcpESOUser", requestTypeInfo.EsoMailboxSmtpAddress);
     }
 }