// Token: 0x0600071C RID: 1820 RVA: 0x00029C28 File Offset: 0x00027E28
        private AnchorMailbox ResolveToDefaultAnchorMailbox(string originalRpcServerName, string reason)
        {
            string text;

            if (HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text))
            {
                AnchorMailbox anchorMailbox = base.ResolveAnchorMailbox();
                if (anchorMailbox != null)
                {
                    base.Logger.AppendString(3, "-" + reason);
                    if (ExTraceGlobals.BriefTracer.IsTraceEnabled(3))
                    {
                        ExTraceGlobals.BriefTracer.TraceError((long)this.GetHashCode(), "[RpcHttpProxyRequestHandler::ResolveToDefaultAnchorMailbox]: Invalid explicit RPC server name from client: {0}; Defaulting to authenticated user {1} for routing; Context {2}; State {3}", new object[]
                        {
                            originalRpcServerName,
                            text,
                            base.TraceContext,
                            base.State
                        });
                    }
                    this.rpcServerTarget = text;
                    return(anchorMailbox);
                }
            }
            throw new HttpProxyException(HttpStatusCode.NotFound, 3003, string.Format("RPC server name passed in by client could not be resolved: {0}", originalRpcServerName));
        }
Exemple #2
0
        // Token: 0x060003D4 RID: 980 RVA: 0x000160E0 File Offset: 0x000142E0
        public static CommonAccessToken FixupCommonAccessToken(HttpContext httpContext, int targetVersion)
        {
            if (!httpContext.Request.IsAuthenticated)
            {
                return(null);
            }
            CommonAccessToken commonAccessToken = null;

            try
            {
                if (httpContext.User.Identity is OAuthIdentity)
                {
                    commonAccessToken = (httpContext.User.Identity as OAuthIdentity).ToCommonAccessToken(targetVersion);
                }
                else if (httpContext.User is DelegatedPrincipal)
                {
                    commonAccessToken = new CommonAccessToken(8);
                    commonAccessToken.ExtensionData["DelegatedData"] = IIdentityExtensions.GetSafeName(((DelegatedPrincipal)httpContext.User).Identity, true);
                }
                else
                {
                    CommonAccessToken commonAccessToken2 = httpContext.Items["Item-CommonAccessToken"] as CommonAccessToken;
                    if (commonAccessToken2 != null)
                    {
                        return(commonAccessToken2);
                    }
                    if (httpContext.User.Identity is WindowsIdentity)
                    {
                        WindowsIdentity windowsIdentity = httpContext.User.Identity as WindowsIdentity;
                        string          value;
                        if (HttpContextItemParser.TryGetLiveIdMemberName(httpContext.Items, ref value))
                        {
                            commonAccessToken = new CommonAccessToken(3);
                            commonAccessToken.ExtensionData["UserSid"]    = windowsIdentity.User.ToString();
                            commonAccessToken.ExtensionData["MemberName"] = value;
                        }
                        else
                        {
                            commonAccessToken = new CommonAccessToken(windowsIdentity);
                        }
                    }
                }
            }
            catch (CommonAccessTokenException ex)
            {
                if (ExTraceGlobals.BriefTracer.IsTraceEnabled(3))
                {
                    ExTraceGlobals.BriefTracer.TraceError <string, CommonAccessTokenException>(0L, "[AspNetHelper::FixupCommonAccessToken] Error encountered when creating CommonAccessToken from current logong identity. User: {0} Exception: {1}.", IIdentityExtensions.GetSafeName(httpContext.User.Identity, true), ex);
                }
                throw new HttpProxyException(HttpStatusCode.Unauthorized, 3002, string.Format("Error encountered when creating common access token. User: {0}", IIdentityExtensions.GetSafeName(httpContext.User.Identity, true)));
            }
            return(commonAccessToken);
        }
        // Token: 0x060001CF RID: 463 RVA: 0x00008AA0 File Offset: 0x00006CA0
        public override string GetExecutingUserOrganization()
        {
            string text;

            if (HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text))
            {
                SmtpAddress smtpAddress;
                smtpAddress..ctor(text);
                return(smtpAddress.Domain);
            }
            return(base.GetExecutingUserOrganization());
        }
        // Token: 0x060001CE RID: 462 RVA: 0x00008A4C File Offset: 0x00006C4C
        public override AnchorMailbox CreateAuthModuleSpecificAnchorMailbox(IRequestContext requestContext)
        {
            string liveIdMemberName;

            if (!HttpContextItemParser.TryGetLiveIdMemberName(requestContext.HttpContext.Items, ref liveIdMemberName))
            {
                return(null);
            }
            string organizationContext;

            HttpContextItemParser.TryGetLiveIdOrganizationContext(requestContext.HttpContext.Items, ref organizationContext);
            requestContext.Logger.SafeSet(3, "LiveIdBasic-LiveIdMemberName");
            return(new LiveIdMemberNameAnchorMailbox(liveIdMemberName, organizationContext, requestContext));
        }
        // Token: 0x060001B2 RID: 434 RVA: 0x00008840 File Offset: 0x00006A40
        public override AnchorMailbox CreateAuthModuleSpecificAnchorMailbox(IRequestContext requestContext)
        {
            AnchorMailbox result = null;
            string        text;

            if (RequestCookieParser.TryGetDefaultAnchorMailboxCookie(requestContext.HttpContext.Request.Cookies, ref text))
            {
                if (SmtpAddress.IsValidSmtpAddress(text))
                {
                    string organizationContext;
                    HttpContextItemParser.TryGetLiveIdOrganizationContext(requestContext.HttpContext.Items, ref organizationContext);
                    requestContext.Logger.SafeSet(3, "DefaultAnchorMailboxCookie");
                    result = new LiveIdMemberNameAnchorMailbox(text, organizationContext, requestContext);
                }
            }
            else
            {
                requestContext.Logger.SafeSet(3, "UnauthenticatedAnonymous");
                result = new AnonymousAnchorMailbox(requestContext);
            }
            return(result);
        }
Exemple #6
0
        // Token: 0x060000EB RID: 235 RVA: 0x00005DD4 File Offset: 0x00003FD4
        private static AnchorMailbox CreateFromLogonIdentity(IRequestContext requestContext)
        {
            HttpContext httpContext = requestContext.HttpContext;
            IPrincipal  user        = httpContext.User;
            IIdentity   identity    = httpContext.User.Identity;
            string      text;

            HttpContextItemParser.TryGetLiveIdMemberName(httpContext.Items, ref text);
            OAuthIdentity oauthIdentity = identity as OAuthIdentity;

            if (oauthIdentity != null)
            {
                string externalDirectoryObjectId;
                if (RequestHeaderParser.TryGetExternalDirectoryObjectId(httpContext.Request.Headers, ref externalDirectoryObjectId))
                {
                    requestContext.Logger.SafeSet(3, "OAuthIdentity-ExternalDirectoryObjectId");
                    return(new ExternalDirectoryObjectIdAnchorMailbox(externalDirectoryObjectId, oauthIdentity.OrganizationId, requestContext));
                }
                if (oauthIdentity.ActAsUser != null)
                {
                    requestContext.Logger.SafeSet(3, "OAuthIdentity-ActAsUser");
                    return(new OAuthActAsUserAnchorMailbox(oauthIdentity.ActAsUser, requestContext));
                }
                requestContext.Logger.SafeSet(3, "OAuthIdentity-AppOrganization");
                return(new OrganizationAnchorMailbox(oauthIdentity.OrganizationId, requestContext));
            }
            else
            {
                GenericSidIdentity genericSidIdentity = identity as GenericSidIdentity;
                if (genericSidIdentity != null)
                {
                    requestContext.Logger.SafeSet(3, "GenericSidIdentity");
                    return(new SidAnchorMailbox(genericSidIdentity.Sid, requestContext)
                    {
                        PartitionId = genericSidIdentity.PartitionId,
                        SmtpOrLiveId = text
                    });
                }
                DelegatedPrincipal delegatedPrincipal = user as DelegatedPrincipal;
                if (delegatedPrincipal != null && delegatedPrincipal.DelegatedOrganization != null && string.IsNullOrEmpty(text))
                {
                    requestContext.Logger.SafeSet(3, "DelegatedPrincipal-DelegatedOrganization");
                    return(new DomainAnchorMailbox(delegatedPrincipal.DelegatedOrganization, requestContext));
                }
                WindowsIdentity windowsIdentity = identity as WindowsIdentity;
                if (windowsIdentity != null)
                {
                    if (string.IsNullOrEmpty(text))
                    {
                        requestContext.Logger.SafeSet(3, "WindowsIdentity");
                    }
                    else
                    {
                        requestContext.Logger.SafeSet(3, "WindowsIdentity-LiveIdMemberName");
                    }
                    return(new SidAnchorMailbox(windowsIdentity.User, requestContext)
                    {
                        SmtpOrLiveId = text
                    });
                }
                SecurityIdentifier securityIdentifier = null;
                if (IIdentityExtensions.TryGetSecurityIdentifier(identity, ref securityIdentifier) && !securityIdentifier.Equals(AuthCommon.MemberNameNullSid))
                {
                    if (string.IsNullOrEmpty(text))
                    {
                        requestContext.Logger.SafeSet(3, "SID");
                    }
                    else
                    {
                        requestContext.Logger.SafeSet(3, "SID-LiveIdMemberName");
                    }
                    return(new SidAnchorMailbox(securityIdentifier, requestContext)
                    {
                        SmtpOrLiveId = text
                    });
                }
                if (!HttpProxySettings.IdentityIndependentAuthBehaviorEnabled.Value && requestContext.AuthBehavior.AuthState != AuthState.FrontEndFullAuth)
                {
                    AnchorMailbox anchorMailbox = requestContext.AuthBehavior.CreateAuthModuleSpecificAnchorMailbox(requestContext);
                    if (anchorMailbox != null)
                    {
                        return(anchorMailbox);
                    }
                }
                if (!string.IsNullOrEmpty(text) && SmtpAddress.IsValidSmtpAddress(text))
                {
                    requestContext.Logger.SafeSet(3, "Smtp-LiveIdMemberName");
                    return(new SmtpAnchorMailbox(text, requestContext));
                }
                throw new InvalidOperationException(string.Format("Unknown idenity {0} with type {1}.", IIdentityExtensions.GetSafeName(identity, true), identity.ToString()));
            }
        }
        // Token: 0x0600070D RID: 1805 RVA: 0x000296EC File Offset: 0x000278EC
        protected override AnchorMailbox ResolveAnchorMailbox()
        {
            UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url);

            if (string.IsNullOrEmpty(base.ClientRequest.Url.Query))
            {
                throw new HttpProxyException(HttpStatusCode.NotFound, 3001, "No proxy destination is specified!");
            }
            RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query);

            this.rpcServerTarget = rpcHttpQueryString.RcaServer;
            if (SmtpAddress.IsValidSmtpAddress(this.rpcServerTarget))
            {
                string text;
                HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text);
                Guid   guid;
                string domain;
                string text2;
                if (RequestQueryStringParser.TryGetMailboxGuid(this.rpcServerTarget, text, ref guid, ref domain, ref text2))
                {
                    MailboxGuidAnchorMailbox result;
                    if (!string.IsNullOrEmpty(text2))
                    {
                        this.rpcServerTarget = ExchangeRpcClientAccess.CreatePersonalizedServer(guid, text2);
                        base.Logger.AppendString(3, "MailboxGuidWithDomain-ChangedToUserDomain");
                        result = new MailboxGuidAnchorMailbox(guid, text2, this);
                    }
                    else
                    {
                        base.Logger.AppendString(3, "MailboxGuidWithDomain");
                        result = new MailboxGuidAnchorMailbox(guid, domain, this);
                    }
                    this.updateRpcServer = true;
                    return(result);
                }
                return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "InvalidFormat"));
            }
            else
            {
                ProxyDestination proxyDestination;
                if (RpcHttpProxyRules.Instance.TryGetProxyDestination(this.rpcServerTarget, out proxyDestination))
                {
                    string text3 = proxyDestination.GetHostName(this.GetKeyForCasAffinity());
                    if (proxyDestination.IsDynamicTarget)
                    {
                        try
                        {
                            text3 = DownLevelServerManager.Instance.GetDownLevelClientAccessServerWithPreferredServer <RpcHttpService>(new ServerInfoAnchorMailbox(text3, this), text3, 1, base.Logger, proxyDestination.Version).Fqdn;
                        }
                        catch (NoAvailableDownLevelBackEndException)
                        {
                            throw new HttpProxyException(HttpStatusCode.NotFound, 3001, string.Format("Cannot find a healthy E12 or E14 CAS to proxy to: {0}", this.rpcServerTarget));
                        }
                    }
                    uriBuilder.Host   = text3;
                    uriBuilder.Port   = proxyDestination.Port;
                    uriBuilder.Scheme = Uri.UriSchemeHttps;
                    base.Logger.Set(3, "RpcHttpProxyRules");
                    this.updateRpcServer = false;
                    return(new UrlAnchorMailbox(uriBuilder.Uri, this));
                }
                return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "UnknownServerName"));
            }
        }
        // Token: 0x060006EE RID: 1774 RVA: 0x00028810 File Offset: 0x00026A10
        protected override void AddProtocolSpecificHeadersToServerRequest(WebHeaderCollection headers)
        {
            if (base.ClientRequest.IsAuthenticated && base.ProxyToDownLevel)
            {
                IIdentity          callerIdentity     = this.GetCallerIdentity();
                WindowsIdentity    windowsIdentity    = callerIdentity as WindowsIdentity;
                GenericSidIdentity genericSidIdentity = callerIdentity as GenericSidIdentity;
                IPrincipal         user = base.HttpContext.User;
                if (windowsIdentity != null)
                {
                    string text;
                    if (HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text))
                    {
                        headers["X-RemotePS-GenericIdentity"] = windowsIdentity.User.ToString();
                    }
                    else
                    {
                        headers["X-RemotePS-WindowsIdentity"] = this.GetSerializedAccessTokenString();
                    }
                }
                else if (genericSidIdentity != null)
                {
                    headers["X-RemotePS-GenericIdentity"] = genericSidIdentity.Sid.ToString();
                }
                else
                {
                    headers["X-RemotePS-GenericIdentity"] = IIdentityExtensions.GetSafeName(base.HttpContext.User.Identity, true);
                }
            }
            if (this.isSyndicatedAdminManageDownLevelTarget)
            {
                headers["msExchCafeForceRouteToLogonAccount"] = "1";
            }
            if (LoggerHelper.IsProbePingRequest(base.ClientRequest))
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(base.Logger, 21, "ProbePingBackend");
            }
            else if (WinRMHelper.WinRMParserEnabled.Value)
            {
                try
                {
                    this.winRMInfo = base.ParseClientRequest <WinRMInfo>(new Func <Stream, WinRMInfo>(this.ParseWinRMInfo), 10000);
                }
                catch (InvalidOperationException ex)
                {
                    if (ExTraceGlobals.ExceptionTracer.IsTraceEnabled(3))
                    {
                        ExTraceGlobals.ExceptionTracer.TraceError <InvalidOperationException>((long)this.GetHashCode(), "[RemotePowerShellProxyRequestHandler::AddProtocolSpecificHeadersToServerRequest] ParseClientRequest throws exception {0}", ex);
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(base.Logger, "ParseClientRequestException", ex.ToString());
                }
                if (this.winRMInfo != null)
                {
                    WinRMInfo.StampToHttpHeaders(this.winRMInfo, headers);
                }
            }
            DatabaseBasedAnchorMailbox databaseBasedAnchorMailbox = base.AnchoredRoutingTarget.AnchorMailbox as DatabaseBasedAnchorMailbox;

            if (databaseBasedAnchorMailbox != null)
            {
                ADObjectId database = databaseBasedAnchorMailbox.GetDatabase();
                if (database != null)
                {
                    headers["X-DatabaseGuid"] = database.ObjectGuid.ToString();
                }
            }
            if (!base.ShouldRetryOnError)
            {
                headers["X-Cafe-Last-Retry"] = "Y";
            }
            base.AddProtocolSpecificHeadersToServerRequest(headers);
        }