Пример #1
0
		private DataServiceController(DSConfiguration settings, CustomAuthorizationHandler.ICustomContextStore customContextStore, ISchemaBuilder testSchemaBuilder)
		{
			TraceHelper.Current.CorrelateWithActivity(EtwActivity.GetActivityId());
			try
			{
				this.Configuration = settings;
				this.cmdManagers = new Dictionary<ManagementSystemType, ICommandManager>();
				this.PerfCounters = new PerfCounters(CurrentRequestHelper.EndPointAddress);
				this.UserDataCache = new UserDataCache(this.Configuration.Invocation.Lifetime);
				this.QuotaSystem = new QuotaSystem();
				InitialSessionStateManager initialSessionStateManager = new InitialSessionStateManager(this.Configuration.PowerShell.SessionConfig.Assembly, this.Configuration.PowerShell.SessionConfig.Type);
				this.intialSessionStateStore = new SharedItemStore<InitialSessionState, UserContext>(initialSessionStateManager, this.Configuration.Quotas.UserSchemaTimeout, this.Configuration.Quotas.MaxUserSchemas);
				PSRunspaceFactory pSRunspaceFactory = new PSRunspaceFactory(this.intialSessionStateStore, true);
				int runspaceTimeout = this.Configuration.PowerShell.Quotas.RunspaceTimeout;
				ExclusiveItemStore<PSRunspace, UserContext> exclusiveItemStore = new ExclusiveItemStore<PSRunspace, UserContext>(pSRunspaceFactory, runspaceTimeout, this.Configuration.PowerShell.Quotas.MaxRunspaces);
				PSCommandManager pSCommandManager = new PSCommandManager(exclusiveItemStore);
				this.cmdManagers.Add(ManagementSystemType.PowerShell, pSCommandManager);
				PSRunspaceFactory pSRunspaceFactory1 = new PSRunspaceFactory(this.intialSessionStateStore, false);
				ExclusiveItemStore<PSRunspace, UserContext> exclusiveItemStore1 = new ExclusiveItemStore<PSRunspace, UserContext>(pSRunspaceFactory1, runspaceTimeout, this.Configuration.PowerShell.Quotas.MaxRunspaces);
				this.cmdManagers.Add(ManagementSystemType.GenericInvoke, new GICommandManager(exclusiveItemStore1));
				List<ISchemaBuilder> schemaBuilders = new List<ISchemaBuilder>();
				if (testSchemaBuilder != null)
				{
					schemaBuilders.Add(testSchemaBuilder);
				}
				schemaBuilders.Add(new PSSchemaBuilder(exclusiveItemStore));
				schemaBuilders.Add(new GISchemaBuilder());
				SchemaFactory schemaFactory = new SchemaFactory(this.Configuration.SchemaFileName, this.Configuration.ResourceMappingFileName, schemaBuilders, settings);
				this.schemaStore = new SharedItemStore<Microsoft.Management.Odata.Schema.Schema, UserContext>(schemaFactory, this.Configuration.Quotas.UserSchemaTimeout, this.Configuration.Quotas.MaxUserSchemas);
				this.customAuthorizationHandler = new CustomAuthorizationHandler(this.Configuration.CustomAuthorization.Assembly, this.Configuration.CustomAuthorization.Type, customContextStore);
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				TraceHelper.Current.DataServiceControllerCreationFailedOperational(exception.Message);
				if (TraceHelper.IsEnabled(5))
				{
					TraceHelper.Current.DebugMessage(exception.ToTraceMessage("DataServiceController failed to create"));
				}
				if (this.PerfCounters != null)
				{
					this.PerfCounters.Dispose();
				}
				throw;
			}
			TraceHelper.Current.DataServiceControllerCreationSucceeded();
		}
Пример #2
0
        public void Handle_WhenCalledWithIllegalUser_ShouldNotSucceed()
        {
            var resource = new Document()
            {
                Name = "Homer's document", Owner = "homer.simpson"
            };
            var user = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> {
                new Claim(ClaimTypes.Name, "ned.flanders")
            }));
            var requirement = new OperationAuthorizationRequirement {
                Name = "Read"
            };

            var authzContext = new AuthorizationContext(new List <IAuthorizationRequirement> {
                requirement
            }, user, resource);

            var authzHandler = new CustomAuthorizationHandler();

            authzHandler.Handle(authzContext);

            Assert.False(authzContext.HasSucceeded);
        }
Пример #3
0
		public void SetCustomStateStore(CustomAuthorizationHandler.ICustomContextStore context)
		{
			this.customAuthorizationHandler.SetCustomStateStore(context);
		}
Пример #4
0
		public static void CreateDataServiceController(DSConfiguration settings, CustomAuthorizationHandler.ICustomContextStore customContextStore, ISchemaBuilder testSchemaBuilder)
		{
			string filePath;
			lock (DataServiceController.syncObject)
			{
				Configuration configuration = null;
				if (settings == null)
				{
					try
					{
						settings = DSConfiguration.GetSection(configuration);
					}
					catch (Exception exception1)
					{
						Exception exception = exception1;
						Microsoft.Management.Odata.Tracing.Tracer current = TraceHelper.Current;
						string str = "config file is ";
						if (configuration == null)
						{
							filePath = "(not available)";
						}
						else
						{
							filePath = configuration.FilePath;
						}
						current.DebugMessage(string.Concat(str, filePath));
						if (TraceHelper.IsEnabled(5))
						{
							TraceHelper.Current.DebugMessage(exception.ToTraceMessage("DataServiceController failed to create"));
						}
						TraceHelper.Current.DataServiceControllerCreationFailedOperational(exception.Message);
						throw;
					}
				}
				DataServiceController.current = new DataServiceController(settings, customContextStore, testSchemaBuilder);
			}
		}
Пример #5
0
		public static void CreateDataServiceController(DSConfiguration settings, CustomAuthorizationHandler.ICustomContextStore customContextStore)
		{
			DataServiceController.CreateDataServiceController(settings, customContextStore, null);
		}