// Token: 0x06000380 RID: 896 RVA: 0x00015D94 File Offset: 0x00013F94
        internal static bool ValidateRequest <T>(AutodiscoverRequest request, Collection <T> identities, RequestedSettingCollection requestedSettingCollection, ExchangeVersion?requestedVersion, LazyMember <int> maxIdentities, string maxIdentitiesString, out string errorMessage, out ExchangeVersion requestVersion)
        {
            bool result = false;

            if (!AutodiscoverRequestMessage.TryGetRequestVersion(out requestVersion))
            {
                errorMessage = Strings.MissingOrInvalidRequestedServerVersion;
            }
            else if (request == null)
            {
                errorMessage = Strings.InvalidRequest;
            }
            else if (identities == null || identities.Count == 0)
            {
                errorMessage = Strings.NoUsersRequested;
            }
            else if (requestedSettingCollection == null || requestedSettingCollection.Count == 0)
            {
                errorMessage = Strings.NoSettingsRequested;
            }
            else if (identities.Count > maxIdentities.Member)
            {
                errorMessage = string.Format(maxIdentitiesString, maxIdentities.Member);
            }
            else if (requestedVersion != null && !AutodiscoverRequestMessage.IsValidExchangeRequestedVersion(requestedVersion.Value))
            {
                errorMessage = Strings.InvalidRequestedVersion;
            }
            else
            {
                errorMessage = Strings.NoError;
                result       = true;
            }
            return(result);
        }
Пример #2
0
        // Token: 0x06000395 RID: 917 RVA: 0x00016394 File Offset: 0x00014594
        internal override AutodiscoverResponseMessage Execute()
        {
            GetDomainSettingsResponseMessage getDomainSettingsResponseMessage = new GetDomainSettingsResponseMessage();
            GetDomainSettingsResponse        response = getDomainSettingsResponseMessage.Response;
            ExchangeVersion?requestedVersion          = this.Request.RequestedVersion;
            IPrincipal      user = HttpContext.Current.User;
            string          errorMessage;
            ExchangeVersion exchangeVersion;

            if (!AutodiscoverRequestMessage.ValidateRequest <string>(this.Request, this.Request.Domains, this.Request.RequestedSettings, null, GetDomainSettingsRequestMessage.maxDomainsPerGetDomainSettingsRequest, Strings.MaxDomainsPerGetDomainSettingsRequestExceeded, out errorMessage, out exchangeVersion))
            {
                response.ErrorCode    = ErrorCode.InvalidRequest;
                response.ErrorMessage = errorMessage;
            }
            else
            {
                HashSet <DomainConfigurationSettingName> hashSet;
                DomainSettingErrorCollection             settingErrors;
                this.TryParseRequestDomainSettings(out hashSet, out settingErrors);
                if (hashSet.Count == 0)
                {
                    response.ErrorCode    = ErrorCode.InvalidRequest;
                    response.ErrorMessage = Strings.NoSettingsToReturn;
                }
                else
                {
                    string userAgent = Common.SafeGetUserAgent(HttpContext.Current.Request);
                    GetDomainSettingsCallContext callContext = new GetDomainSettingsCallContext(userAgent, this.Request.RequestedVersion, this.Request.Domains, hashSet, settingErrors, response);
                    try
                    {
                        this.ExecuteGetDomainSettingsCommand(user, callContext);
                    }
                    catch (OverBudgetException arg)
                    {
                        ExTraceGlobals.FrameworkTracer.TraceError <OverBudgetException>(0L, "GetDomainSettingsRequestMessage.Execute()returning ServerBusy for exception: {0}.", arg);
                        response.ErrorCode    = ErrorCode.ServerBusy;
                        response.ErrorMessage = Strings.ServerBusy;
                        response.DomainResponses.Clear();
                    }
                    catch (LocalizedException ex)
                    {
                        ExTraceGlobals.FrameworkTracer.TraceError <LocalizedException>(0L, "GetDomainSettingsRequestMessage.Execute()returning InternalServerError for exception: {0}.", ex);
                        Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_ErrWebException, Common.PeriodicKey, new object[]
                        {
                            ex.Message,
                            ex
                        });
                        response.ErrorCode    = ErrorCode.InternalServerError;
                        response.ErrorMessage = Strings.InternalServerError;
                        response.DomainResponses.Clear();
                    }
                }
            }
            return(getDomainSettingsResponseMessage);
        }
Пример #3
0
        private TResponse Execute <TResponse>(AutodiscoverRequestMessage message) where TResponse : AutodiscoverResponseMessage
        {
            TResponse response = default(TResponse);

            Common.SendWatsonReportOnUnhandledException(delegate
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .Current.TrackLatency(ServiceLatencyMetadata.CoreExecutionLatency, delegate()
                {
                    response = (TResponse)((object)message.Execute());
                });
            });
            return(response);
        }
        // Token: 0x06000386 RID: 902 RVA: 0x00015F04 File Offset: 0x00014104
        private static bool TryGetRequestVersion(out ExchangeVersion requestVersion)
        {
            requestVersion = ExchangeVersion.Exchange2010;
            bool result;

            try
            {
                MessageHeaders incomingMessageHeaders = OperationContext.Current.IncomingMessageHeaders;
                string         header = incomingMessageHeaders.GetHeader <string>("RequestedServerVersion", "http://schemas.microsoft.com/exchange/2010/Autodiscover");
                AutodiscoverRequestMessage.RemapEquivalentRequestedExchangeVersion(ref header);
                result = EnumValidator <ExchangeVersion> .TryParse(header, EnumParseOptions.Default, out requestVersion);
            }
            catch (MessageHeaderException)
            {
                result = false;
            }
            catch (SerializationException)
            {
                result = false;
            }
            return(result);
        }
Пример #5
0
        // Token: 0x060003B5 RID: 949 RVA: 0x00016F80 File Offset: 0x00015180
        internal override AutodiscoverResponseMessage Execute()
        {
            GetUserSettingsResponseMessage getUserSettingsResponseMessage = new GetUserSettingsResponseMessage();
            GetUserSettingsResponse        response = getUserSettingsResponseMessage.Response;
            IPrincipal      user = HttpContext.Current.User;
            string          errorMessage;
            ExchangeVersion exchangeVersion;

            if (!AutodiscoverRequestMessage.ValidateRequest <User>(this.Request, this.Request.Users, this.Request.RequestedSettings, this.Request.RequestedVersion, GetUserSettingsRequestMessage.maxUsersPerGetUserSettingsRequest, Strings.MaxUsersPerGetUserSettingsRequestExceeded, out errorMessage, out exchangeVersion))
            {
                response.ErrorCode    = ErrorCode.InvalidRequest;
                response.ErrorMessage = errorMessage;
            }
            else
            {
                HashSet <UserConfigurationSettingName> hashSet;
                UserSettingErrorCollection             settingErrors;
                this.TryParseRequestUserSettings(out hashSet, out settingErrors);
                if (hashSet.Count == 0)
                {
                    response.ErrorCode    = ErrorCode.InvalidRequest;
                    response.ErrorMessage = Strings.NoSettingsToReturn;
                }
                else
                {
                    ExchangeServerVersion?requestedVersion = null;
                    if (this.Request.RequestedVersion != null)
                    {
                        switch (this.Request.RequestedVersion.Value)
                        {
                        case ExchangeVersion.Exchange2010:
                            requestedVersion = new ExchangeServerVersion?(ExchangeServerVersion.E14);
                            break;

                        case ExchangeVersion.Exchange2010_SP1:
                            requestedVersion = new ExchangeServerVersion?(ExchangeServerVersion.E14_SP1);
                            break;

                        case ExchangeVersion.Exchange2010_SP2:
                            requestedVersion = new ExchangeServerVersion?(ExchangeServerVersion.E14_SP2);
                            break;

                        case ExchangeVersion.Exchange2012:
                        case ExchangeVersion.Exchange2013:
                        case ExchangeVersion.Exchange2013_SP1:
                            requestedVersion = new ExchangeServerVersion?(ExchangeServerVersion.E15);
                            break;
                        }
                    }
                    CallContext callContext = new CallContext(HttpContext.Current, this.Request.Users, hashSet, requestedVersion, settingErrors, response);
                    try
                    {
                        this.ExecuteGetUserSettingsCommand(user, callContext);
                    }
                    catch (OverBudgetException arg)
                    {
                        ExTraceGlobals.FrameworkTracer.TraceError <OverBudgetException>(0L, "GetUserSettingsRequestMessage.Execute()returning ServerBusy for exception: {0}.", arg);
                        response.ErrorCode    = ErrorCode.ServerBusy;
                        response.ErrorMessage = Strings.ServerBusy;
                        response.UserResponses.Clear();
                    }
                    catch (LocalizedException ex)
                    {
                        ExTraceGlobals.FrameworkTracer.TraceError <LocalizedException>(0L, "GetUserSettingsRequestMessage.Execute()returning InternalServerError for exception: {0}.", ex);
                        Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_ErrWebException, Common.PeriodicKey, new object[]
                        {
                            ex.Message,
                            ex
                        });
                        response.ErrorCode    = ErrorCode.InternalServerError;
                        response.ErrorMessage = Strings.InternalServerError;
                        response.UserResponses.Clear();
                    }
                }
            }
            return(getUserSettingsResponseMessage);
        }
Пример #6
0
        // Token: 0x060003B7 RID: 951 RVA: 0x0001721C File Offset: 0x0001541C
        private void ExecuteCommand(IIdentity callerIdentity, CallContext callContext)
        {
            ADRecipient adrecipient = HttpContext.Current.Items["CallerRecipient"] as ADRecipient;

            if (adrecipient == null && (Common.IsPartnerHostedOnly || VariantConfiguration.InvariantNoFlightingSnapshot.Autodiscover.NoCrossForestDiscover.Enabled))
            {
                string identityNameForTrace = Common.GetIdentityNameForTrace(callerIdentity);
                ExTraceGlobals.FrameworkTracer.TraceError <string>(0L, "ExecuteCommand -- IRecipientSession.FindBySid user for {0} returned null.", identityNameForTrace);
                callContext.Response.ErrorCode    = ErrorCode.InvalidUser;
                callContext.Response.ErrorMessage = string.Format(Strings.InvalidUser, identityNameForTrace);
                return;
            }
            PartnerInfo partnerInfo  = null;
            string      targetTenant = null;
            bool        flag         = false;
            string      text         = null;

            byte[] binarySecret = null;
            GetUserSettingsCommandBase getUserSettingsCommandBase;

            if (VariantConfiguration.InvariantNoFlightingSnapshot.Autodiscover.ParseBinarySecretHeader.Enabled && AutodiscoverRequestMessage.HasBinarySecretHeader(out text))
            {
                PerformanceCounters.UpdatePartnerTokenRequests(callContext.UserAgent);
                bool flag2 = false;
                if (!string.IsNullOrEmpty(text))
                {
                    try
                    {
                        binarySecret = Convert.FromBase64String(text);
                        flag2        = true;
                    }
                    catch (FormatException)
                    {
                        ExTraceGlobals.FrameworkTracer.TraceDebug <string>((long)this.GetHashCode(), "[GetUserSettingsRequestMessage::ExecuteCommand] the binary secret header {0} has invalid format", text);
                    }
                }
                if (!flag2)
                {
                    PerformanceCounters.UpdatePartnerTokenRequestsFailed(callContext.UserAgent);
                    callContext.Response.ErrorCode    = ErrorCode.InvalidRequest;
                    callContext.Response.ErrorMessage = Strings.InvalidBinarySecretHeader;
                    return;
                }
                if (!this.TryGetMailboxAccessPartnerInfo(callContext, adrecipient, out partnerInfo, out targetTenant))
                {
                    ExTraceGlobals.FrameworkTracer.TraceDebug((long)this.GetHashCode(), "[GetUserSettingsRequestMessage::ExecuteCommand] TryGetMailboxAccessPartnerInfo returns false.");
                    PerformanceCounters.UpdatePartnerTokenRequestsFailed(callContext.UserAgent);
                    callContext.Response.ErrorCode    = ErrorCode.InvalidRequest;
                    callContext.Response.ErrorMessage = Strings.InvalidPartnerTokenRequest;
                    return;
                }
                flag = true;
                ExTraceGlobals.FrameworkTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "GetUserSettingsForPartner created for the '{0}'. The caller is FPO partner.", adrecipient);
                getUserSettingsCommandBase = new GetUserSettingsForPartner(callerIdentity.GetSecurityIdentifier(), callContext);
            }
            else if (adrecipient == null)
            {
                ExTraceGlobals.FrameworkTracer.TraceDebug <string>((long)this.GetHashCode(), "GetUserSettingsForUserWithUnscopedCaller created for '{0}'.", Common.GetIdentityNameForTrace(callerIdentity));
                getUserSettingsCommandBase = new GetUserSettingsForUserWithUnscopedCaller(callerIdentity.GetSecurityIdentifier(), callContext);
            }
            else if (ExchangeRunspaceConfiguration.IsAllowedOrganizationForPartnerAccounts(adrecipient.OrganizationId))
            {
                ExTraceGlobals.FrameworkTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "GetUserSettingsForPartner created for '{0}'.", adrecipient);
                getUserSettingsCommandBase = new GetUserSettingsForPartner(callerIdentity.GetSecurityIdentifier(), callContext);
            }
            else
            {
                ExTraceGlobals.FrameworkTracer.TraceDebug <ADRecipient>((long)this.GetHashCode(), "GetUserSettingsForUser created for '{0}'.", adrecipient);
                getUserSettingsCommandBase = new GetUserSettingsForUser(adrecipient, callerIdentity.GetSecurityIdentifier(), callContext);
            }
            getUserSettingsCommandBase.Execute();
            if (flag)
            {
                UserResponse userResponse = callContext.Response.UserResponses[0];
                if (userResponse.ErrorCode == ErrorCode.NoError || userResponse.ErrorCode == ErrorCode.RedirectUrl)
                {
                    string        assertionId = SecurityTokenService.CreateSamlAssertionId();
                    MessageHeader header      = MessageHeader.CreateHeader("PartnerToken", "http://schemas.microsoft.com/exchange/2010/Autodiscover", partnerInfo.CreateSamlToken(assertionId, targetTenant, binarySecret, GetUserSettingsRequestMessage.tokenLifetime.Value));
                    MessageHeader header2     = MessageHeader.CreateHeader("PartnerTokenReference", "http://schemas.microsoft.com/exchange/2010/Autodiscover", PartnerInfo.GetTokenReference(assertionId));
                    OperationContext.Current.OutgoingMessageHeaders.Add(header);
                    OperationContext.Current.OutgoingMessageHeaders.Add(header2);
                    return;
                }
                PerformanceCounters.UpdatePartnerTokenRequestsFailed(callContext.UserAgent);
                ExTraceGlobals.FrameworkTracer.TraceDebug <ErrorCode, string>((long)this.GetHashCode(), "No partner token header added since the user response error code is {0}, error message is '{1}'", userResponse.ErrorCode, userResponse.ErrorMessage);
            }
        }