mirror of
https://github.com/bitwarden/server
synced 2025-12-21 10:43:44 +00:00
* Add RemovePaymentMethod to StripePaymentService * Add SendProviderUpdatePaymentMethod to HandlebarsMailService * Add RemoveOrganizationFromProviderCommand * Use RemoveOrganizationFromProviderCommand in ProviderOrganizationController * Remove RemoveOrganizationAsync from ProviderService * Add RemoveOrganizationFromProviderCommandTests * PR review feedback and refactoring * Remove RemovePaymentMethod from StripePaymentService * Review feedback * Add Organization RisksSubscriptionFailure endpoint * fix build error * Review feedback * [AC-1359] Bitwarden Portal Unlink Provider Buttons (#3588) * Added ability to unlink organization from provider from provider edit page * Refreshing provider edit page after removing an org * Added button to organization to remove the org from the provider * Updated based on product feedback * Removed organization name from alert message * Temporary logging * Remove coupon from Stripe org after disconnected from MSP * Updated test * Change payment terms on org disconnect from MSP * Set Stripe account email to new billing email * Remove logging --------- Co-authored-by: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Co-authored-by: Conner Turnbull <cturnbull@bitwarden.com>
169 lines
5.5 KiB
C#
169 lines
5.5 KiB
C#
using System.Globalization;
|
|
using Bit.Admin.IdentityServer;
|
|
using Bit.Core.Context;
|
|
using Bit.Core.Settings;
|
|
using Bit.Core.Utilities;
|
|
using Bit.SharedWeb.Utilities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Stripe;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Bit.Admin.Services;
|
|
using Bit.Core.Billing.Extensions;
|
|
|
|
#if !OSS
|
|
using Bit.Commercial.Core.Utilities;
|
|
using Bit.Commercial.Infrastructure.EntityFramework.SecretsManager;
|
|
#endif
|
|
|
|
namespace Bit.Admin;
|
|
|
|
public class Startup
|
|
{
|
|
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
|
{
|
|
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
|
Configuration = configuration;
|
|
Environment = env;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; private set; }
|
|
public IWebHostEnvironment Environment { get; set; }
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
// Options
|
|
services.AddOptions();
|
|
|
|
// Settings
|
|
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
|
|
services.Configure<AdminSettings>(Configuration.GetSection("AdminSettings"));
|
|
|
|
// Data Protection
|
|
services.AddCustomDataProtectionServices(Environment, globalSettings);
|
|
|
|
// Stripe Billing
|
|
StripeConfiguration.ApiKey = globalSettings.Stripe.ApiKey;
|
|
StripeConfiguration.MaxNetworkRetries = globalSettings.Stripe.MaxNetworkRetries;
|
|
|
|
// Repositories
|
|
var databaseProvider = services.AddDatabaseRepositories(globalSettings);
|
|
switch (databaseProvider)
|
|
{
|
|
case Core.Enums.SupportedDatabaseProviders.SqlServer:
|
|
services.AddSingleton<IDbMigrator, Migrator.SqlServerDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.MySql:
|
|
services.AddSingleton<IDbMigrator, MySqlMigrations.MySqlDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.Postgres:
|
|
services.AddSingleton<IDbMigrator, PostgresMigrations.PostgresDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.Sqlite:
|
|
services.AddSingleton<IDbMigrator, SqliteMigrations.SqliteDbMigrator>();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// Context
|
|
services.AddScoped<ICurrentContext, CurrentContext>();
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
// Identity
|
|
services.AddPasswordlessIdentityServices<ReadOnlyEnvIdentityUserStore>(globalSettings);
|
|
services.Configure<SecurityStampValidatorOptions>(options =>
|
|
{
|
|
options.ValidationInterval = TimeSpan.FromMinutes(5);
|
|
});
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
services.ConfigureApplicationCookie(options =>
|
|
{
|
|
options.Cookie.Path = "/admin";
|
|
});
|
|
}
|
|
|
|
// Services
|
|
services.AddBaseServices(globalSettings);
|
|
services.AddDefaultServices(globalSettings);
|
|
services.AddScoped<IAccessControlService, AccessControlService>();
|
|
services.AddBillingCommands();
|
|
|
|
#if OSS
|
|
services.AddOosServices();
|
|
#else
|
|
services.AddCommercialCoreServices();
|
|
services.AddSecretsManagerEfRepositories();
|
|
#endif
|
|
|
|
// Mvc
|
|
services.AddMvc(config =>
|
|
{
|
|
config.Filters.Add(new LoggingExceptionHandlerFilterAttribute());
|
|
});
|
|
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
|
|
|
services.Configure<RazorViewEngineOptions>(o =>
|
|
{
|
|
o.ViewLocationFormats.Add("/Auth/Views/{1}/{0}.cshtml");
|
|
});
|
|
|
|
// Jobs service
|
|
Jobs.JobsHostedService.AddJobsServices(services, globalSettings.SelfHosted);
|
|
services.AddHostedService<Jobs.JobsHostedService>();
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
services.AddHostedService<HostedServices.DatabaseMigrationHostedService>();
|
|
}
|
|
else
|
|
{
|
|
if (CoreHelpers.SettingHasValue(globalSettings.Storage.ConnectionString))
|
|
{
|
|
services.AddHostedService<HostedServices.AzureQueueBlockIpHostedService>();
|
|
}
|
|
else if (CoreHelpers.SettingHasValue(globalSettings.Amazon?.AccessKeySecret))
|
|
{
|
|
services.AddHostedService<HostedServices.AmazonSqsBlockIpHostedService>();
|
|
}
|
|
if (CoreHelpers.SettingHasValue(globalSettings.Mail.ConnectionString))
|
|
{
|
|
services.AddHostedService<HostedServices.AzureQueueMailHostedService>();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Configure(
|
|
IApplicationBuilder app,
|
|
IWebHostEnvironment env,
|
|
IHostApplicationLifetime appLifetime,
|
|
GlobalSettings globalSettings)
|
|
{
|
|
app.UseSerilog(env, appLifetime, globalSettings);
|
|
|
|
// Add general security headers
|
|
app.UseMiddleware<SecurityHeadersMiddleware>();
|
|
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
app.UsePathBase("/admin");
|
|
app.UseForwardedHeaders(globalSettings);
|
|
}
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/error");
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
|
}
|
|
}
|