Example #1
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            string text = source.Items["WLID-MemberName"] as string;

            if (string.IsNullOrEmpty(text))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            if (!SmtpAddress.IsValidSmtpAddress(text))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[LogonUserAddressFinder::Find]: Malformed memberName {0}.", text);
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            string text2 = source.Items["WLID-OrganizationContext"] as string;

            if (!string.IsNullOrEmpty(text2) && !SmtpAddress.IsValidDomain(text2))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[LogonUserAddressFinder::Find]: Malformed organizationContext {0}.", text2);
                text2 = null;
            }
            IRoutingKey routingKey = new LiveIdMemberNameRoutingKey(new SmtpAddress(text), text2);

            diagnostics.AddRoutingkey(routingKey, "LogonUser");
            return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
            {
                routingKey
            }));
        }
Example #2
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            ExTraceGlobals.VerboseTracer.TraceDebug <int>((long)this.GetHashCode(), "[CompositeAddressFinder::Find]: Number of addressFinders {0}.", this.addressFinders.Length);
            if (this.addressFinders.Length == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            List <IRoutingKey> list = new List <IRoutingKey>(this.addressFinders.Length);

            foreach (IAddressFinder addressFinder in this.addressFinders)
            {
                if (addressFinder != null)
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug <Type>((long)this.GetHashCode(), "[CompositeAddressFinder::Find]: addressFinder {0}.", addressFinder.GetType());
                    IRoutingKey[] collection = addressFinder.Find(source, diagnostics);
                    if (!collection.IsNullOrEmpty())
                    {
                        list.AddRange(collection);
                    }
                }
                else
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[CompositeAddressFinder::Find]: addressFinder is null.");
                }
            }
            if (list.Count == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            return(list.ToArray());
        }
Example #3
0
        private static IRoutingKey FindByMailboxId(string mailboxId, IAddressFinderDiagnostics diagnostics)
        {
            if (string.IsNullOrEmpty(mailboxId))
            {
                return(null);
            }
            if (!SmtpAddress.IsValidSmtpAddress(mailboxId))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[MapiAddressFinder::FindByMailboxId]: Malformed mailboxId {0}.", mailboxId);
                return(null);
            }
            Guid   guid         = Guid.Empty;
            string tenantDomain = string.Empty;

            try
            {
                SmtpAddress smtpAddress = new SmtpAddress(mailboxId);
                guid         = new Guid(smtpAddress.Local);
                tenantDomain = smtpAddress.Domain;
            }
            catch (FormatException arg)
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string, FormatException>(0L, "[MapiAddressFinder::FindByMailboxId]: Caught exception: Reason {0}; Exception {1}.", string.Format("Invalid mailboxGuid {0}", guid), arg);
                return(null);
            }
            IRoutingKey routingKey = new MailboxGuidRoutingKey(guid, tenantDomain);

            diagnostics.AddRoutingkey(routingKey, "MailboxGuidInQueryString");
            return(routingKey);
        }
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            string text = source.Headers["X-PreferServerAffinity"];

            if (!string.IsNullOrEmpty(text) && text.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase))
            {
                HttpCookie httpCookie = source.Cookies["X-BackEndOverrideCookie"];
                string     text2      = (httpCookie == null) ? null : httpCookie.Value;
                if (!string.IsNullOrEmpty(text2))
                {
                    string text3;
                    string s;
                    Utilities.GetTwoSubstrings(text2, '~', out text3, out s);
                    int value;
                    if (!string.IsNullOrWhiteSpace(text3) && int.TryParse(s, out value))
                    {
                        IRoutingKey routingKey = new ServerRoutingKey(text3, new int?(value));
                        diagnostics.AddRoutingkey(routingKey, "X-BackEndOverrideCookie");
                        return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                        {
                            routingKey
                        }));
                    }
                    diagnostics.AddErrorInfo("Unable to parse TargetServer:" + text2);
                }
            }
            return(AddressFinderHelper.EmptyRoutingKeyArray);
        }
Example #5
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            List <IRoutingKey> list = new List <IRoutingKey>();

            if (!source.Headers.IsNullOrEmpty())
            {
                IRoutingKey routingKey = RoutingHintAddressFinder.FindByTargetServer(source.Headers[WellKnownHeader.XTargetServer], diagnostics);
                if (routingKey != null)
                {
                    list.Add(routingKey);
                }
                else
                {
                    IRoutingKey[] collection = RoutingHintAddressFinder.FindByAnchorMailbox(source.Headers[WellKnownHeader.AnchorMailbox], diagnostics);
                    if (!collection.IsNullOrEmpty())
                    {
                        list.AddRange(collection);
                    }
                }
            }
            if (list.Count == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            return(list.ToArray());
        }
Example #6
0
        private void LastChanceExceptionHandler(Exception ex)
        {
            IAddressFinderDiagnostics addressFinderDiagnostics = this.GetDiagnostics(new HttpContextWrapper(HttpContext.Current));

            if (addressFinderDiagnostics != null)
            {
                addressFinderDiagnostics.LogUnhandledException(ex);
            }
        }
Example #7
0
        private static IRoutingKey FindByTargetServer(string targetServer, IAddressFinderDiagnostics diagnostics)
        {
            if (string.IsNullOrEmpty(targetServer))
            {
                return(null);
            }
            IRoutingKey routingKey = new ServerRoutingKey(targetServer);

            diagnostics.AddRoutingkey(routingKey, "TargetServerInHeader");
            return(routingKey);
        }
Example #8
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            if (string.IsNullOrEmpty(source.Url.Query))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(source.Url.Query);

            if (!SmtpAddress.IsValidSmtpAddress(rpcHttpQueryString.RcaServer))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            Guid   guid = Guid.Empty;
            string text = string.Empty;

            try
            {
                SmtpAddress smtpAddress = new SmtpAddress(rpcHttpQueryString.RcaServer);
                guid = new Guid(smtpAddress.Local);
                text = smtpAddress.Domain;
            }
            catch (FormatException arg)
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string, FormatException>(0L, "[RpcHttpAddressFinder::Find]: Caught exception: Reason {0}; Exception {1}.", string.Format("Invalid mailboxGuid {0}", guid), arg);
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            string text2 = "MailboxGuidWithDomain";

            if (!text.Contains(".") && !source.Items.IsNullOrEmpty())
            {
                string text3 = source.Items["WLID-MemberName"] as string;
                if (!string.IsNullOrEmpty(text3))
                {
                    SmtpAddress smtpAddress2 = new SmtpAddress(text3);
                    string      domain       = smtpAddress2.Domain;
                    if (domain != null && !string.Equals(domain, text, StringComparison.OrdinalIgnoreCase))
                    {
                        ExTraceGlobals.BriefTracer.TraceError <string, string>((long)this.GetHashCode(), "[RpcHttpAddressFinder::Find]: Fixing up invalid domain name from client: {0} to {1}", text, domain);
                        text   = domain;
                        text2 += "-ChangedToUserDomain";
                    }
                }
            }
            IRoutingKey routingKey = new MailboxGuidRoutingKey(guid, text);

            diagnostics.AddRoutingkey(routingKey, text2);
            return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
            {
                routingKey
            }));
        }
Example #9
0
        private static IRoutingKey[] FindByAnchorMailbox(string anchorMailbox, IAddressFinderDiagnostics diagnostics)
        {
            if (string.IsNullOrEmpty(anchorMailbox))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            Match match = Constants.GuidAtDomainRegex.Match(anchorMailbox);

            if (match != null && match.Success)
            {
                string text = match.Result("${mailboxguid}");
                if (!string.IsNullOrEmpty(text))
                {
                    Guid        mailboxGuid = new Guid(text);
                    string      text2       = match.Result("${domain}");
                    IRoutingKey routingKey  = new MailboxGuidRoutingKey(mailboxGuid, text2);
                    diagnostics.AddRoutingkey(routingKey, "MailboxGuidInAnchorMailbox");
                    if (string.IsNullOrEmpty(text2))
                    {
                        return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                        {
                            routingKey
                        }));
                    }
                    if (SmtpAddress.IsValidSmtpAddress(anchorMailbox))
                    {
                        IRoutingKey routingKey2 = new SmtpRoutingKey(new SmtpAddress(anchorMailbox));
                        diagnostics.AddRoutingkey(routingKey2, "FallbackSmtpAddressInAnchorMailbox");
                        return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                        {
                            routingKey,
                            routingKey2
                        }));
                    }
                    ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[RoutingHintAddressFinder::FindByAnchorMailbox]: Malformed smtp address in X-AnchorMailbox {0}.", anchorMailbox);
                }
            }
            if (SmtpAddress.IsValidSmtpAddress(anchorMailbox))
            {
                IRoutingKey routingKey3 = new SmtpRoutingKey(new SmtpAddress(anchorMailbox));
                diagnostics.AddRoutingkey(routingKey3, "SmtpAddressInAnchorMailbox");
                return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                {
                    routingKey3
                }));
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[RoutingHintAddressFinder::FindByAnchorMailbox]: Invalid smtp address in X-AnchorMailbox {0}.", anchorMailbox);
            return(AddressFinderHelper.EmptyRoutingKeyArray);
        }
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            string text = source.QueryString["email"];

            if (!string.IsNullOrEmpty(text) && SmtpAddress.IsValidSmtpAddress(text))
            {
                IRoutingKey routingKey = new SmtpRoutingKey(new SmtpAddress(text));
                diagnostics.AddRoutingkey(routingKey, "ExplicitLogon-SMTP");
                return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                {
                    routingKey
                }));
            }
            return(AddressFinderHelper.EmptyRoutingKeyArray);
        }
Example #11
0
        private static IRoutingKey FindBySmtpAddress(string smtpAddress, IAddressFinderDiagnostics diagnostics)
        {
            if (string.IsNullOrEmpty(smtpAddress))
            {
                return(null);
            }
            if (!SmtpAddress.IsValidSmtpAddress(smtpAddress))
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "[MapiAddressFinder::FindBySmtpAddress]: Malformed smtpAddress {0}.", smtpAddress);
                return(null);
            }
            IRoutingKey routingKey = new SmtpRoutingKey(new SmtpAddress(smtpAddress));

            diagnostics.AddRoutingkey(routingKey, "SmtpAddressInQueryString");
            return(routingKey);
        }
Example #12
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            bool   selectedNodeIsLast;
            string explicitLogonNode = ProtocolHelper.GetExplicitLogonNode(source.ApplicationPath, source.FilePath, ExplicitLogonNode.Second, out selectedNodeIsLast);
            string address;

            if (ProtocolHelper.TryGetValidNormalizedExplicitLogonAddress(explicitLogonNode, selectedNodeIsLast, out address))
            {
                IRoutingKey routingKey = new SmtpRoutingKey(new SmtpAddress(address));
                diagnostics.AddRoutingkey(routingKey, "ExplicitLogon-SMTP");
                return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                {
                    routingKey
                }));
            }
            return(AddressFinderHelper.EmptyRoutingKeyArray);
        }
Example #13
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            List <IRoutingKey> list       = new List <IRoutingKey>();
            IRoutingKey        routingKey = MapiAddressFinder.FindByMailboxId(source.QueryString["mailboxId"], diagnostics);

            if (routingKey != null)
            {
                list.Add(routingKey);
            }
            routingKey = MapiAddressFinder.FindBySmtpAddress(source.QueryString["smtpAddress"], diagnostics);
            if (routingKey != null)
            {
                list.Add(routingKey);
            }
            if (list.Count == 0)
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            return(list.ToArray());
        }
Example #14
0
 IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
 {
     AddressFinderHelper.ThrowIfNull(source, diagnostics);
     if (!string.IsNullOrWhiteSpace(source.Url.PathAndQuery))
     {
         Match match = Constants.UsersEntityRegex.Match(source.Url.PathAndQuery);
         if (match.Success)
         {
             string address = match.Result("${address}");
             if (SmtpAddress.IsValidSmtpAddress(address))
             {
                 IRoutingKey routingKey = new SmtpRoutingKey(new SmtpAddress(address));
                 diagnostics.AddRoutingkey(routingKey, "TargetMailbox-SMTP");
                 return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
                 {
                     routingKey
                 }));
             }
         }
     }
     return(AddressFinderHelper.EmptyRoutingKeyArray);
 }
Example #15
0
 internal void OnPostAuthorizeRequest(HttpContextBase context)
 {
     Diagnostics.SendWatsonReportOnUnhandledException(delegate()
     {
         if (!this.isEnabled)
         {
             return;
         }
         IAddressFinderDiagnostics addressFinderDiagnostics = this.GetDiagnostics(context);
         IAddressFinder addressFinder = this.addressFinderFactory.CreateAddressFinder(HttpProxyGlobals.ProtocolType, context.Request.Url.AbsolutePath);
         if (addressFinder != null)
         {
             AddressFinderSource source   = new AddressFinderSource(context.Items, context.Request.Headers, context.Request.QueryString, context.Request.Url, context.Request.ApplicationPath, context.Request.FilePath, context.Request.Cookies);
             IRoutingKey[] value          = addressFinder.Find(source, addressFinderDiagnostics);
             context.Items["RoutingKeys"] = value;
         }
         else
         {
             ExTraceGlobals.VerboseTracer.TraceDebug <string, Uri, ProtocolType>((long)this.GetHashCode(), "[AddressFinderModule::OnPostAuthorizeRequest]: addressFinder is null: Method {0}; Url {1}; Protocol {2};", context.Request.HttpMethod, context.Request.Url, HttpProxyGlobals.ProtocolType);
             addressFinderDiagnostics.AddErrorInfo("addressFinder is null");
         }
         addressFinderDiagnostics.LogRoutingKeys();
     }, new Diagnostics.LastChanceExceptionHandler(this.LastChanceExceptionHandler));
 }
Example #16
0
 internal AddressFinderModule(IAddressFinderFactory addressFinderFactory, bool isEnabled, IAddressFinderDiagnostics diagnostics)
 {
     if (addressFinderFactory == null)
     {
         throw new ArgumentNullException("addressFinderFactory");
     }
     this.addressFinderFactory = addressFinderFactory;
     this.isEnabled            = isEnabled;
     this.diagnostics          = diagnostics;
 }
Example #17
0
 public static void ThrowIfNull(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
 {
     ArgumentValidator.ThrowIfNull("source", source);
     ArgumentValidator.ThrowIfNull("diagnostics", diagnostics);
 }