public void ShouldThrowExceptionForNoAccounts() { var config = BuildConfig(EmptyConfigData); Action act = () => { StorageConfiguration.Validate(config); }; act.Should().Throw <FluentValidation.ValidationException>(); }
public void ConfigureServices() { var services = new ServiceCollection(); services.AddMemoryCache(); services.AddOptions(); services.Configure <SearchConfiguration>(options => { Configuration.GetSection("search").Bind(options); SearchConfiguration.Validate(options); }); services.Configure <CosmosConfiguration>(options => { Configuration.GetSection("documents").Bind(options); CosmosConfiguration.Validate(options); }); services.Configure <StorageConfiguration>((config) => { Configuration.GetSection("storage").Bind(config); StorageConfiguration.Validate(config); }); services.Configure <BatchConfiguration>((config) => { Configuration.GetSection("batch").Bind(config); BatchConfiguration.Validate(config); }); var armTemplatesMap = new ArmTemplatesMap(); services.AddSingleton(armTemplatesMap); var staticAssetsMap = new StaticAssetsMap(); services.AddSingleton(staticAssetsMap); services.AddSingleton <ApplicationJobs>(); services.AddSingleton <DatasetStorageService>(); services.AddSingleton <DatasetOwnersService>(); services.AddSingleton <DatasetEditStorageService>(); services.AddSingleton <UserDataStorageService>(); services.AddSingleton <SasTokenService>(); services.AddSingleton <ValidationService>(); services.AddSingleton <DatasetSearchService>(); services.AddSingleton <FileSearchService>(); ServiceProvider = services.BuildServiceProvider(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(Configuration); services.AddOptions(); services.Configure <IdentityProviderConfiguration>(options => { Configuration.GetSection("azuread").Bind(options); IdentityProviderConfiguration.Validate(options); }); services.Configure <SearchConfiguration>(options => { Configuration.GetSection("search").Bind(options); SearchConfiguration.Validate(options); }); services.Configure <CosmosConfiguration>(options => { Configuration.GetSection("documents").Bind(options); CosmosConfiguration.Validate(options); }); services.Configure <StorageConfiguration>((config) => { Configuration.GetSection("storage").Bind(config); StorageConfiguration.Validate(config); }); services.Configure <BatchConfiguration>((config) => { Configuration.GetSection("batch").Bind(config); BatchConfiguration.Validate(config); }); services.Configure <AppInsightsConfiguration>((config) => { Configuration.GetSection("applicationinsights").Bind(config); AppInsightsConfiguration.Validate(config); }); var armTemplatesMap = new ArmTemplatesMap(); services.AddSingleton(armTemplatesMap); var staticAssetsMap = new StaticAssetsMap(); services.AddSingleton(staticAssetsMap); services.AddMemoryCache(); //services // .AddAuthentication(options => // { // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; // }) // .AddJwtBearer(options => // { // options.Audience = Configuration["azureADConfig:clientId"]; // options.Authority = Configuration["azureADConfig:authority"]; // options.Events = new JwtBearerEvents // { // OnMessageReceived = FetchAuthTokenFromCookie, // OnTokenValidated = async context => // { // var principal = context.Principal; // var ODREmailList = Configuration["ODRAdminList"].Split(";"); // } // }; // }); //services // .AddAuthentication(options => // { // options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; // }) // .AddJwtBearer(options => // { // options.Audience = Configuration["azureADConfig:clientId"]; // options.Authority = Configuration["azureADConfig:authority"]; // options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters // { // ValidAudience = Configuration["azureADConfig:clientId"], // ValidIssuer = $"https://login.microsoftonline.com/" + Configuration["azureADConfig:tenantId"] + "/v2.0" // }; // options.Events = new JwtBearerEvents // { // OnMessageReceived = FetchAuthTokenFromCookie, // //OnTokenValidated = async context => // //{ // // var principal = context.Principal; // // if (Configuration.GetChildren().Any(item => item.Key == "ODRAdminList") && principal.Claims.Any(c => c.Type == "preferred_username")) // // { // // var ODRAdminsList = Configuration["ODRAdminList"].Split(";").ToList(); // // var testSubject = principal.Claims.FirstOrDefault(c => c.Type == "preferred_username").Value; // // if (ODRAdminsList.Contains(testSubject)) // // { // // var claims = new List<Claim> // // { // // new Claim(ClaimTypes.Role, "ODRAdmin") // // }; // // var appIdentity = new ClaimsIdentity(claims); // // principal.AddIdentity(appIdentity); // // } // // } // //} // }; // }); services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { var tenantName = Configuration["AzureAD:Tenant"].Split('.').First(); var policyName = Configuration["AzureAD:Policy"]; var audience = Configuration["AzureAD:Audience"]; options.MetadataAddress = $"https://{tenantName}.b2clogin.com/{tenantName}.onmicrosoft.com/{policyName}/v2.0/.well-known/openid-configuration"; options.Audience = audience; options.Events = new JwtBearerEvents { OnMessageReceived = FetchAuthTokenFromCookie, OnAuthenticationFailed = context => { var ctx = context; return(Task.FromResult(0)); }, }; }); services.AddMvc(); services .AddAuthorization(options => { options.AddPolicy(PolicyNames.MustBeInAdminGroup, policy => { var authorizedAdminUsers = Configuration["AuthorizedAdminUsers"]; policy.Requirements.Add(new AzureActiveDirectoryGroupRequirement(authorizedAdminUsers)); }); }); services.AddSingleton <IAuthorizationHandler, AzureActiveDirectoryGroupHandler>(); //if (CurrentEnvironment.IsDevelopment()) //{ // services.AddSingleton<IAuthorizationHandler, DevelopmentOnlyNoAuthDirectoryGroupHandler>(); //} //else //{ // services.AddSingleton<IAuthorizationHandler, AzureActiveDirectoryGroupHandler>(); //} services.AddScoped <DatasetSearchService>(); services.AddScoped <UserDataSearchService>(); services.AddScoped <DatasetStorageService>(); services.AddScoped <AppInsightsService>(); services.AddScoped <UserDataStorageService>(); services.AddScoped <LicenseStorageService>(); services.AddScoped <SasTokenService>(); services.AddScoped <ValidationService>(); services.AddScoped <ApplicationJobs>(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ui-app"; }); // Add Swagger generator if (Configuration.GetValue <bool>("Application:EnableSwagger")) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "MSR ODR Admin API", Version = "v1" }); }); } }
/// <summary> /// Adds the runtime services to the instance. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(this.Configuration); services.AddSingleton <ITelemetryInitializer, TelemetryUserAndSessionContext>(); services.AddApplicationInsightsTelemetry(); services.AddOptions(); services.Configure <IdentityProviderConfiguration>(options => { Configuration.GetSection("azuread").Bind(options); IdentityProviderConfiguration.Validate(options); }); services.Configure <SearchConfiguration>(options => { Configuration.GetSection("search").Bind(options); SearchConfiguration.Validate(options); }); services.Configure <CosmosConfiguration>(options => { Configuration.GetSection("documents").Bind(options); CosmosConfiguration.Validate(options); }); services.Configure <StorageConfiguration>((config) => { Configuration.GetSection("storage").Bind(config); StorageConfiguration.Validate(config); }); services.Configure <WebServerConfiguration>(options => { Configuration.GetSection("webserver").Bind(options); WebServerConfiguration.Validate(options); }); services.Configure <BatchConfiguration>((config) => { Configuration.GetSection("batch").Bind(config); BatchConfiguration.Validate(config); }); var armTemplatesMap = Configuration.GetSection("armTemplates").Get <ArmTemplatesMap>(); services.AddSingleton(armTemplatesMap); var staticAssetsMap = Configuration.GetSection("staticAssets").Get <StaticAssetsMap>(); services.AddSingleton(staticAssetsMap); services.AddMemoryCache(); services.AddCors(options => { options.AddPolicy("DefaultPolicy", builder => builder.AllowAnyOrigin() .WithMethods("GET", "POST", "PUT", "DELETE") .AllowAnyHeader() .AllowCredentials()); }); services.AddResponseCompression(opt => { opt.EnableForHttps = true; }); services.AddMvc() .AddMvcOptions(options => { options.Filters.Add(new TelemetryExceptionFilter(new LoggerFactory())); }) .AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); }); services.AddScoped <DatasetSearchService>(); services.AddScoped <FileSearchService>(); services.AddScoped <DatasetStorageService>(); services.AddScoped <DatasetOwnersService>(); services.AddScoped <DatasetEditStorageService>(); services.AddScoped <UserDataStorageService>(); services.AddScoped <FileStorageService>(); services.AddScoped <LicenseStorageService>(); services.AddScoped <ValidationService>(); services.AddScoped <SasTokenService>(); services.AddScoped <GenerateFilePreview>(); services.AddScoped <CurrentUserService>(); services.AddScoped <ApplicationJobs>(); if (this.UseSwagger) { services.UseSwagger(this.Configuration); } services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { var tenantName = Configuration["AzureAD:Tenant"].Split('.').First(); var policyName = Configuration["AzureAD:Policy"]; var audience = Configuration["AzureAD:Audience"]; options.MetadataAddress = $"https://{tenantName}.b2clogin.com/{tenantName}.onmicrosoft.com/{policyName}/v2.0/.well-known/openid-configuration"; options.Audience = audience; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { var ctx = context; return(Task.FromResult(0)); }, }; }); }
public void ShouldValidate() { var config = BuildConfig(AccountsConfigData); StorageConfiguration.Validate(config); }