protected override AnchorMailbox ResolveAnchorMailbox()
        {
            AnonymousPublishingUrl anonymousPublishingUrl = new AnonymousPublishingUrl(base.ClientRequest.Url);

            if (anonymousPublishingUrl.ParameterSegments.Length > 0)
            {
                string text  = anonymousPublishingUrl.ParameterSegments[0];
                Match  match = RegexUtilities.TryMatch(Constants.GuidAtDomainRegex, text, base.Logger);
                if (match != null && match.Success)
                {
                    Guid   mailboxGuid = new Guid(match.Result("${mailboxguid}"));
                    string text2       = match.Result("${domain}");
                    string value       = string.Format("AnonymousPublishingUrl-MailboxGuid{0}", string.IsNullOrEmpty(text2) ? string.Empty : "WithDomainAndSmtpFallback");
                    base.Logger.Set(HttpProxyMetadata.RoutingHint, value);
                    MailboxGuidAnchorMailbox mailboxGuidAnchorMailbox = new MailboxGuidAnchorMailbox(mailboxGuid, text2, this);
                    if (!string.IsNullOrEmpty(text2))
                    {
                        mailboxGuidAnchorMailbox.FallbackSmtp = text;
                    }
                    return(mailboxGuidAnchorMailbox);
                }
                match = RegexUtilities.TryMatch(Constants.AddressRegex, text, base.Logger);
                if (match != null && match.Success)
                {
                    string text3 = match.Result("${address}");
                    if (!string.IsNullOrEmpty(text3) && SmtpAddress.IsValidSmtpAddress(text3))
                    {
                        base.Logger.Set(HttpProxyMetadata.RoutingHint, "AnonymousPublishingUrl-SMTP");
                        return(new SmtpAnchorMailbox(text3, this));
                    }
                }
            }
            return(base.ResolveAnchorMailbox());
        }
Example #2
0
        // Token: 0x060000E9 RID: 233 RVA: 0x00005A04 File Offset: 0x00003C04
        public static AnchorMailbox CreateFromSamlTokenAddress(string address, IRequestContext requestContext)
        {
            if (string.IsNullOrEmpty(address))
            {
                string text = string.Format("Cannot authenticate user address claim {0}", address);
                requestContext.Logger.AppendGenericError("Invalid Wssecurity address claim.", text);
                throw new HttpProxyException(HttpStatusCode.Unauthorized, 4002, text);
            }
            if (SmtpAddress.IsValidSmtpAddress(address))
            {
                requestContext.Logger.Set(3, "WSSecurityRequest-SMTP");
                return(new SmtpAnchorMailbox(address, requestContext)
                {
                    FailOnDomainNotFound = false
                });
            }
            Match match = RegexUtilities.TryMatch(Constants.SidOnlyRegex, address);

            if (match != null && match.Success)
            {
                SecurityIdentifier securityIdentifier = null;
                try
                {
                    securityIdentifier = new SecurityIdentifier(address);
                }
                catch (ArgumentException ex)
                {
                    requestContext.Logger.AppendGenericError("Ignored Exception", ex.ToString());
                }
                catch (SystemException ex2)
                {
                    requestContext.Logger.AppendGenericError("Ignored Exception", ex2.ToString());
                }
                if (securityIdentifier != null)
                {
                    requestContext.Logger.Set(3, "WSSecurityRequest-SID");
                    return(new SidAnchorMailbox(securityIdentifier, requestContext));
                }
            }
            if (SmtpAddress.IsValidDomain(address))
            {
                requestContext.Logger.Set(3, "WSSecurityRequest-Domain");
                return(new DomainAnchorMailbox(address, requestContext));
            }
            throw new HttpProxyException(HttpStatusCode.Unauthorized, 4002, string.Format("Cannot authenticate user address claim {0}", address));
        }
Example #3
0
 private static bool TryGetMailboxGuid(string anchorMailboxAddress, out Guid mailboxGuid, out string domain, IRequestContext requestContext)
 {
     mailboxGuid = default(Guid);
     domain      = null;
     if (anchorMailboxAddress != null)
     {
         Match match = RegexUtilities.TryMatch(Constants.GuidAtDomainRegex, anchorMailboxAddress, requestContext.Logger);
         if (match != null && match.Success)
         {
             string text = RegexUtilities.ParseIdentifier(match, "${mailboxguid}", requestContext.Logger);
             if (!string.IsNullOrEmpty(text))
             {
                 mailboxGuid = new Guid(text);
                 domain      = RegexUtilities.ParseIdentifier(match, "${domain}", requestContext.Logger);
                 return(true);
             }
         }
     }
     return(false);
 }
Example #4
0
        // Token: 0x060000E6 RID: 230 RVA: 0x000056D4 File Offset: 0x000038D4
        public static AnchorMailbox TryCreateFromRoutingHint(IRequestContext requestContext, bool tryTargetServerRoutingHint)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            string fqdn;

            if (tryTargetServerRoutingHint && RequestHeaderParser.TryGetTargetServer(requestContext.HttpContext.Request.Headers, ref fqdn))
            {
                requestContext.Logger.Set(3, "TargetServerHeader");
                return(new ServerInfoAnchorMailbox(fqdn, requestContext));
            }
            string text;

            if (!RequestHeaderParser.TryGetAnchorMailbox(requestContext.HttpContext.Request.Headers, ref text))
            {
                return(null);
            }
            Match match = RegexUtilities.TryMatch(Constants.SidRegex, text);

            if (match != null && match.Success)
            {
                string text2 = RegexUtilities.ParseIdentifier(match, "${sid}");
                if (!string.IsNullOrEmpty(text2))
                {
                    SecurityIdentifier securityIdentifier = null;
                    try
                    {
                        securityIdentifier = new SecurityIdentifier(text2);
                    }
                    catch (ArgumentException ex)
                    {
                        requestContext.Logger.AppendGenericError("Ignored Exception", ex.ToString());
                    }
                    catch (SystemException ex2)
                    {
                        requestContext.Logger.AppendGenericError("Ignored Exception", ex2.ToString());
                    }
                    if (securityIdentifier != null)
                    {
                        requestContext.Logger.SafeSet(3, "AnchorMailboxHeader-SID");
                        return(new SidAnchorMailbox(securityIdentifier, requestContext));
                    }
                }
            }
            Guid   mailboxGuid;
            string text3;

            if (RequestHeaderParser.TryGetMailboxGuid(text, ref mailboxGuid, ref text3))
            {
                string value = string.Format("AnchorMailboxHeader-MailboxGuid{0}", string.IsNullOrEmpty(text3) ? string.Empty : "WithDomain");
                requestContext.Logger.SafeSet(3, value);
                MailboxGuidAnchorMailbox mailboxGuidAnchorMailbox = new MailboxGuidAnchorMailbox(mailboxGuid, text3, requestContext);
                if (!string.IsNullOrEmpty(text3))
                {
                    mailboxGuidAnchorMailbox.FallbackSmtp = text;
                }
                return(mailboxGuidAnchorMailbox);
            }
            if (PuidAnchorMailbox.IsEnabled)
            {
                NetID netID;
                Guid  tenantGuid;
                if (RequestHeaderParser.TryGetNetIdAndTenantGuid(text, ref netID, ref tenantGuid))
                {
                    requestContext.Logger.Set(3, "AnchorMailboxHeader-PuidAndTenantGuid");
                    return(new PuidAnchorMailbox(netID.ToString(), tenantGuid, requestContext, text));
                }
                string text4;
                if (RequestHeaderParser.TryGetNetIdAndDomain(text, ref netID, ref text4))
                {
                    if (string.IsNullOrEmpty(text4))
                    {
                        requestContext.Logger.Set(3, "AnchorMailboxHeader-Puid");
                        return(new PuidAnchorMailbox(netID.ToString(), requestContext, text));
                    }
                    requestContext.Logger.Set(3, "AnchorMailboxHeader-PuidAndDomain");
                    return(new PuidAnchorMailbox(netID.ToString(), text4, requestContext, text));
                }
            }
            if (SmtpAddress.IsValidSmtpAddress(text))
            {
                requestContext.Logger.Set(3, "AnchorMailboxHeader-SMTP");
                return(new SmtpAnchorMailbox(text, requestContext));
            }
            return(null);
        }
Example #5
0
        public static AnchorMailbox TryCreateFromRoutingHint(IRequestContext requestContext, bool tryTargetServerRoutingHint)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            string text = requestContext.HttpContext.Request.Headers[WellKnownHeader.XTargetServer];

            if (!string.IsNullOrEmpty(text) && tryTargetServerRoutingHint)
            {
                requestContext.Logger.Set(HttpProxyMetadata.RoutingHint, "TargetServerHeader");
                return(new ServerInfoAnchorMailbox(text, requestContext));
            }
            string text2 = requestContext.HttpContext.Request.Headers[Constants.AnchorMailboxHeaderName];

            if (string.IsNullOrEmpty(text2))
            {
                return(null);
            }
            Match match = RegexUtilities.TryMatch(Constants.SidRegex, text2, requestContext.Logger);

            if (match != null && match.Success)
            {
                string text3 = RegexUtilities.ParseIdentifier(match, "${sid}", requestContext.Logger);
                if (!string.IsNullOrEmpty(text3))
                {
                    SecurityIdentifier securityIdentifier = null;
                    try
                    {
                        securityIdentifier = new SecurityIdentifier(text3);
                    }
                    catch (ArgumentException ex)
                    {
                        requestContext.Logger.AppendGenericError("Ignored Exception", ex.ToString());
                    }
                    catch (SystemException ex2)
                    {
                        requestContext.Logger.AppendGenericError("Ignored Exception", ex2.ToString());
                    }
                    if (securityIdentifier != null)
                    {
                        requestContext.Logger.SafeSet(HttpProxyMetadata.RoutingHint, "AnchorMailboxHeader-SID");
                        return(new SidAnchorMailbox(securityIdentifier, requestContext));
                    }
                }
            }
            match = RegexUtilities.TryMatch(Constants.GuidAtDomainRegex, text2, requestContext.Logger);
            if (match != null && match.Success)
            {
                string text4 = RegexUtilities.ParseIdentifier(match, "${mailboxguid}", requestContext.Logger);
                if (!string.IsNullOrEmpty(text4))
                {
                    Guid   mailboxGuid = new Guid(text4);
                    string text5       = RegexUtilities.ParseIdentifier(match, "${domain}", requestContext.Logger);
                    string value       = string.Format("AnchorMailboxHeader-MailboxGuid{0}", string.IsNullOrEmpty(text5) ? string.Empty : "WithDomain");
                    requestContext.Logger.SafeSet(HttpProxyMetadata.RoutingHint, value);
                    MailboxGuidAnchorMailbox mailboxGuidAnchorMailbox = new MailboxGuidAnchorMailbox(mailboxGuid, text5, requestContext);
                    if (!string.IsNullOrEmpty(text5))
                    {
                        mailboxGuidAnchorMailbox.FallbackSmtp = text2;
                    }
                    return(mailboxGuidAnchorMailbox);
                }
            }
            if (SmtpAddress.IsValidSmtpAddress(text2))
            {
                requestContext.Logger.Set(HttpProxyMetadata.RoutingHint, "AnchorMailboxHeader-SMTP");
                return(new SmtpAnchorMailbox(text2, requestContext));
            }
            return(null);
        }