private void LoadConfigFile(string configPath)
        {
            SafeXmlDocument safeXmlDocument = new SafeXmlDocument();

            if (!File.Exists(configPath))
            {
                ReportingWebServiceEventLogConstants.Tuple_LoadReportingschemaFailed.LogEvent(new object[]
                {
                    Strings.ErrorSchemaConfigurationFileMissing(configPath)
                });
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorSchemaInitializationFail, Strings.ErrorSchemaInitializationFail);
            }
            safeXmlDocument.Load(configPath);
            try
            {
                Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> reportPropertyCmdletParamMapping = this.LoadRbacMapping(safeXmlDocument);
                this.LoadEntityNodes(safeXmlDocument, reportPropertyCmdletParamMapping);
            }
            catch (ReportingSchema.SchemaLoadException ex)
            {
                ReportingWebServiceEventLogConstants.Tuple_LoadReportingschemaFailed.LogEvent(new object[]
                {
                    ex.Message
                });
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorSchemaInitializationFail, Strings.ErrorSchemaInitializationFail, ex);
            }
        }
Beispiel #2
0
        private void ThrowError(ErrorRecord errorRecord)
        {
            Exception exception = errorRecord.Exception;

            if (exception is OverBudgetException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorOverBudget, Strings.ErrorOverBudget, exception);
                return;
            }
            if (exception is ConnectionFailedException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ConnectionFailedException, Strings.ConnectionFailedException, exception);
                return;
            }
            if (exception is ADTransientException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, exception);
                return;
            }
            if (exception is InvalidExpressionException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidQueryException, Strings.InvalidQueryException, exception);
                return;
            }
            if (exception is DataMartTimeoutException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.DataMartTimeoutException, Strings.DataMartTimeoutException, exception);
                return;
            }
            ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, exception);
        }
 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     if (request.Properties.ContainsKey("UriTemplateMatchResults"))
     {
         HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
         UriTemplateMatch           uriTemplateMatch           = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
         string text = uriTemplateMatch.QueryParameters["$orderby"];
         if (!string.IsNullOrEmpty(text) && text.IndexOf('\'') >= 0)
         {
             ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidQueryException, "Single quotation marks is not supported in $orderby.");
         }
     }
     return(null);
 }
        private string GetTenantDomain(HttpRequest httpRequest)
        {
            string text = null;

            if (httpRequest.Url.Segments.Any((string segment) => segment.Equals("partner/", StringComparison.OrdinalIgnoreCase)))
            {
                text = httpRequest.QueryString["tenantDomain"];
                if (string.IsNullOrEmpty(text))
                {
                    ExTraceGlobals.ReportingWebServiceTracer.TraceError(0L, "[RbacPrincipalManager::GetTenantDomain] Get tenant domain from query string failed.");
                    ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorMissingTenantDomainInRequest, Strings.ErrorMissingTenantDomainInRequest);
                }
            }
            return(text);
        }
        public static string GetCurrentReportingVersion(HttpContext httpContext)
        {
            string text = (string)httpContext.Items["Exchange_RWS_Version"];

            if (string.IsNullOrEmpty(text))
            {
                bool flag  = httpContext.Request.QueryString.AllKeys.Contains(ReportingVersion.QueryStringParameterName);
                bool flag2 = httpContext.Request.Headers.AllKeys.Contains(ReportingVersion.HttpHeaderName);
                if (flag && flag2)
                {
                    ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorVersionAmbiguous, Strings.ErrorVersionAmbiguous);
                }
                else if (flag || flag2)
                {
                    string version;
                    if (flag)
                    {
                        version = httpContext.Request.QueryString[ReportingVersion.QueryStringParameterName];
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Version in query string: {0}", text);
                    }
                    else
                    {
                        version = httpContext.Request.Headers[ReportingVersion.HttpHeaderName];
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Version in header: {0}", text);
                    }
                    if (!ReportingVersion.IsVersionSupported(version, out text))
                    {
                        ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorInvalidVersion, Strings.ErrorInvalidVersion);
                    }
                }
                else
                {
                    ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Use the latest version: {0}", ReportingVersion.LatestVersion);
                    text = ReportingVersion.LatestVersion;
                }
            }
            ExTraceGlobals.ReportingWebServiceTracer.Information <string>(0L, "[ReportingVersion::GetVersion] Version: {0}", text);
            httpContext.Items["Exchange_RWS_Version"] = text;
            return(text);
        }
 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     if (request.Properties.ContainsKey("UriTemplateMatchResults"))
     {
         HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
         UriTemplateMatch           uriTemplateMatch           = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
         string value = uriTemplateMatch.QueryParameters["$format"];
         if ("json".Equals(value, StringComparison.OrdinalIgnoreCase))
         {
             uriTemplateMatch.QueryParameters.Remove("$format");
             httpRequestMessageProperty.Headers["Accept"] = "application/json;odata=verbose";
         }
         else if ("Atom".Equals(value, StringComparison.OrdinalIgnoreCase))
         {
             uriTemplateMatch.QueryParameters.Remove("$format");
             httpRequestMessageProperty.Headers["Accept"] = "application/atom+xml";
         }
         else if (!string.IsNullOrEmpty(value))
         {
             ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidFormatQuery, Strings.InvalidFormatQuery);
         }
     }
     return(null);
 }
        private RbacPrincipal CreateRbacPrincipal(IIdentity identity, string tenantDomain, string cacheKey, HttpContext httpContext)
        {
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Create RbacPrincipal. Identity: {0}; tenantDomain: {1}; cacheKey: '{2}'", identity.GetSafeName(true), tenantDomain ?? string.Empty, cacheKey);
            ExchangeRunspaceConfigurationSettings rbacSettings = null;

            ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewExchangeRunspaceConfigurationSettingsLatency, delegate
            {
                rbacSettings = new ExchangeRunspaceConfigurationSettings(ExchangeRunspaceConfigurationSettings.ExchangeApplication.ReportingWebService, tenantDomain, ExchangeRunspaceConfigurationSettings.SerializationLevel.None);
            });
            ReportingSchema schema = ReportingSchema.GetCurrentReportingSchema(httpContext);

            try
            {
                RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics;
                if (requestStatistics != null)
                {
                    requestStatistics.AddExtendedStatisticsDataPoint("AuthType", identity.AuthenticationType);
                }
                using (new AverageTimePerfCounter(RwsPerfCounters.AverageRbacPrincipalCreation, RwsPerfCounters.AverageRbacPrincipalCreationBase, true))
                {
                    RwsExchangeRunspaceConfiguration rbacConfiguration = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRwsExchangeRunspaceConfigurationLatency, delegate
                    {
                        rbacConfiguration = RwsExchangeRunspaceConfiguration.NewInstance(identity, rbacSettings, schema.CmdletFilter, this.GetSnapinSet());
                    });
                    RbacPrincipal rbacPrincipal = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRbacPrincipalLatency, delegate
                    {
                        rbacPrincipal = new RbacPrincipal(rbacConfiguration, cacheKey);
                    });
                    return(rbacPrincipal);
                }
            }
            catch (CmdletAccessDeniedException ex)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CmdletAccessDeniedException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CmdletAccessDeniedException: {0}", ex);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotInOrgScope, Strings.ErrorTenantNotInOrgScope(tenantDomain), ex);
            }
            catch (CannotResolveTenantNameException ex2)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CannotResolveTenantNameException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CannotResolveTenantNameException: {0}", ex2);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotResolved, Strings.ErrorTenantNotResolved(tenantDomain), ex2);
            }
            catch (ADTransientException ex3)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <ADTransientException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] ADTransientException: {0}", ex3);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, ex3);
            }
            catch (DataSourceOperationException ex4)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] DataSourceOperationException: {0}", ex4);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADOperationError, Strings.ADOperationError, ex4);
            }
            catch (TimeoutException ex5)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <TimeoutException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] TimeoutException: {0}", ex5);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.CreateRunspaceConfigTimeoutError, Strings.CreateRunspaceConfigTimeoutError, ex5);
            }
            catch (Exception ex6)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <Exception>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Exception: {0}", ex6);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, ex6);
            }
            return(null);
        }
 internal static void ThrowError(ReportingErrorCode errorCode, string message)
 {
     ServiceDiagnostics.ThrowError(errorCode, message, null);
 }