protected override bool CheckAccessCore(OperationContext operationContext) { if (RbacAuthorizationManager.NewAuthZMethodEnabled.Value) { if (HttpContext.Current.Items.Contains(RbacAuthorizationManager.DataServiceExceptionKey)) { throw (DataServiceException)HttpContext.Current.Items[RbacAuthorizationManager.DataServiceExceptionKey]; } operationContext.SetRbacPrincipal((RbacPrincipal)HttpContext.Current.User); return(base.CheckAccessCore(operationContext)); } else { RbacPrincipal rbacPrincipal = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.RbacPrincipalAcquireLatency, delegate { rbacPrincipal = RbacPrincipalManager.Instance.AcquireRbacPrincipal(HttpContext.Current); }); if (rbacPrincipal == null) { return(false); } HttpContext.Current.User = rbacPrincipal; rbacPrincipal.SetCurrentThreadPrincipal(); if (OperationContext.Current != null) { OperationContext.Current.SetRbacPrincipal(rbacPrincipal); } return(base.CheckAccessCore(operationContext)); } }
public RbacPrincipal AcquireRbacPrincipalWrapper(HttpContext httpContext) { RbacPrincipal rbacPrincipal = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.RbacPrincipalAcquireLatency, delegate { rbacPrincipal = this.AcquireRbacPrincipal(httpContext); }); return(rbacPrincipal); }
public static ReportingSchema GetCurrentReportingSchema(HttpContext httpContext) { ReportingSchema schema = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetReportingSchemaLatency, delegate { string currentReportingVersion = ReportingVersion.GetCurrentReportingVersion(httpContext); schema = ReportingSchema.GetReportingSchema(currentReportingVersion); }); return(schema); }
public IList GetData(IEntity entity, Expression expression) { IPSCommandWrapper ipscommandWrapper = DependencyFactory.CreatePSCommandWrapper(); ipscommandWrapper.AddCommand(entity.TaskInvocationInfo.CmdletName); if (entity.TaskInvocationInfo.Parameters != null) { foreach (KeyValuePair <string, string> keyValuePair in entity.TaskInvocationInfo.Parameters) { ipscommandWrapper.AddParameter(keyValuePair.Key, keyValuePair.Value); } } if (!this.principal.IsInRole(string.Format("{0}\\{1}?{2}", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName, "Expression"))) { throw new InvalidOperationException(string.Format("Expression parameter is not avaible for the cmdlet {0}\\{1}. Add an entry in Microsoft.Exchange.Configuration.Authorization.ClientRoleEntries.TenantReportingRequiredParameters for your cmdlet.", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName)); } ipscommandWrapper.AddParameter("Expression", expression); IList data = null; using (new AverageTimePerfCounter(RwsPerfCounters.AverageReportCmdletResponseTime, RwsPerfCounters.AverageReportCmdletResponseTimeBase, true)) { PowerShellResults result = ipscommandWrapper.Invoke(ReportingDataSource.RunspaceMediator); if (result.Succeeded) { ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CreateGenericTypeListForResults, delegate { data = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { entity.ClrType }), new object[] { result.Output.Count }); }); foreach (PSObject psobject in result.Output) { data.Add(psobject.BaseObject); } ReportingDataSource.reportRowCounter.AddSample((long)data.Count); } else { ReportingWebServiceEventLogConstants.Tuple_InvokeCmdletFailed.LogEvent(new object[] { EventLogExtension.GetUserNameToLog(), ipscommandWrapper.Commands[0].CommandText, result.Errors[0].Exception }); RwsPerfCounters.ReportCmdletErrors.Increment(); this.ThrowError(result.Errors[0]); } } return(data); }
IEnumerator IEnumerable.GetEnumerator() { Expression queryExpression = this.expressionWithouSelect ?? this.expression; IEnumerator enumerator = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CmdletResponseTime, delegate { enumerator = this.dataSource.GetData(this.entity, queryExpression).GetEnumerator(); }); return(enumerator); }
public IEnumerator <T> GetEnumerator() { if (!typeof(T).IsAssignableFrom(this.entity.ClrType)) { throw new NotSupportedException("The underline clr type of the resouce entity doesn't match the generic type T"); } IEnumerator <T> enumerator = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CmdletResponseTime, delegate { enumerator = this.dataSource.GetData <T>(this.entity, this.expression).GetEnumerator(); }); return(enumerator); }
public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.HttpHandlerProcessRequestLatency, delegate { if (request.IsAuthenticated) { this.actualHandler.ProcessRequest(context); return; } response.StatusCode = 401; }); }
public TElement Execute <TElement>(Expression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } IQueryable result = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CmdletResponseTime, delegate { result = this.dataSource.GetData(this.entity, this.expression).AsQueryable(); }); Expression expression2 = ReportingDataQuery <T> .DecorateExpression(result, (MethodCallExpression)expression); return(result.Provider.Execute <TElement>(expression2)); }
public static ReportingSchema GetReportingSchema(string version) { ReportingSchema schema = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetReportingSchemaLatency, delegate { if (!ReportingSchema.SchemaDictionary.TryGetValue(version, out schema)) { lock (ReportingSchema.SyncRoot) { if (!ReportingSchema.SchemaDictionary.TryGetValue(version, out schema)) { schema = new ReportingSchema(version); ReportingSchema.SchemaDictionary[version] = schema; } } } }); return(schema); }
public object GetService(Type serviceType) { object provider = null; if (serviceType == typeof(IDataServiceMetadataProvider)) { ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetMetadataProviderLatency, delegate { provider = this.GetMetadataProvider(); }); } if (serviceType == typeof(IDataServiceQueryProvider)) { ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetQueryProviderLatency, delegate { provider = this.GetQueryProvider(this.metadataProvider); }); } return(provider); }
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); }