/// <summary> /// Enables principal-supplied role-based security for an API. /// </summary> /// <param name="configuration"> /// An API configuration. /// </param> /// <remarks> /// This method adds hook points to the API configuration that /// authorize according to roles assigned to the current principal /// along with any that have been asserted during an API flow. /// </remarks> public static void EnableRoleBasedSecurity( this ApiConfiguration configuration) { Ensure.NotNull(configuration, "configuration"); configuration.AddHookHandler <IQueryExpressionInspector>(RoleBasedAuthorization.Default); configuration.AddHookHandler <IQueryExpressionExpander>(RoleBasedAuthorization.Default); }
public async Task GetModelUsingDefaultModelHandler() { var configuration = new ApiConfiguration(); configuration.AddHookHandler <IModelBuilder>(new TestModelProducer()); configuration.AddHookHandler <IModelBuilder>(new TestModelExtender(2)); configuration.AddHookHandler <IModelBuilder>(new TestModelExtender(3)); configuration.EnsureCommitted(); var context = new ApiContext(configuration); var model = await Api.GetModelAsync(context); Assert.Equal(4, model.SchemaElements.Count()); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName")); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName2")); Assert.NotNull(model.SchemaElements .SingleOrDefault(e => e.Name == "TestName3")); Assert.NotNull(model.EntityContainer); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet")); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet2")); Assert.NotNull(model.EntityContainer.Elements .SingleOrDefault(e => e.Name == "TestEntitySet3")); }
/// <inheritdoc/> public static void ApplyTo( ApiConfiguration configuration, Type targetType) { Ensure.NotNull(configuration, "configuration"); Ensure.NotNull(targetType, "targetType"); configuration.AddHookHandler<IQueryExpressionFilter>(new ConventionBasedEntitySetFilter(targetType)); }
/// <inheritdoc/> public static void ApplyTo( ApiConfiguration configuration, Type targetType) { Ensure.NotNull(configuration, "configuration"); Ensure.NotNull(targetType, "targetType"); configuration.AddHookHandler<IChangeSetEntryAuthorizer>(new ConventionBasedChangeSetAuthorizer(targetType)); }