2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.Models.Business.Tokenables;
|
2022-12-12 09:59:48 +00:00
|
|
|
|
using Bit.Core.OrganizationFeatures.Groups;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.Groups.Interfaces;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationApiKeys;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationApiKeys.Interfaces;
|
2023-01-19 17:00:54 +01:00
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationCollections;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationCollections.Interfaces;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationConnections;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationConnections.Interfaces;
|
2023-01-31 07:42:10 +10:00
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationLicenses;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationLicenses.Interfaces;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Cloud;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
|
|
|
|
|
|
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.SelfHosted;
|
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
|
using Bit.Core.Settings;
|
|
|
|
|
|
using Bit.Core.Tokens;
|
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-09-26 15:22:02 -04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-05-10 17:12:09 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.OrganizationFeatures;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2022-05-10 17:12:09 -04:00
|
|
|
|
public static class OrganizationServiceCollectionExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void AddOrganizationServices(this IServiceCollection services, IGlobalSettings globalSettings)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<IOrganizationService, OrganizationService>();
|
|
|
|
|
|
services.AddTokenizers();
|
2022-12-12 09:59:48 +00:00
|
|
|
|
services.AddOrganizationGroupCommands();
|
2022-05-10 17:12:09 -04:00
|
|
|
|
services.AddOrganizationConnectionCommands();
|
|
|
|
|
|
services.AddOrganizationSponsorshipCommands(globalSettings);
|
2022-11-28 17:39:09 -07:00
|
|
|
|
services.AddOrganizationApiKeyCommandsQueries();
|
2023-01-19 17:00:54 +01:00
|
|
|
|
services.AddOrganizationCollectionCommands();
|
|
|
|
|
|
services.AddOrganizationGroupCommands();
|
2023-01-31 07:42:10 +10:00
|
|
|
|
services.AddOrganizationLicenseCommandQueries();
|
2022-12-12 09:59:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-10 17:12:09 -04:00
|
|
|
|
private static void AddOrganizationConnectionCommands(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<ICreateOrganizationConnectionCommand, CreateOrganizationConnectionCommand>();
|
|
|
|
|
|
services.AddScoped<IDeleteOrganizationConnectionCommand, DeleteOrganizationConnectionCommand>();
|
|
|
|
|
|
services.AddScoped<IUpdateOrganizationConnectionCommand, UpdateOrganizationConnectionCommand>();
|
|
|
|
|
|
}
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2022-05-10 17:12:09 -04:00
|
|
|
|
private static void AddOrganizationSponsorshipCommands(this IServiceCollection services, IGlobalSettings globalSettings)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2022-05-10 17:12:09 -04:00
|
|
|
|
services.AddScoped<ICreateSponsorshipCommand, CreateSponsorshipCommand>();
|
|
|
|
|
|
services.AddScoped<IRemoveSponsorshipCommand, RemoveSponsorshipCommand>();
|
|
|
|
|
|
services.AddScoped<ISendSponsorshipOfferCommand, SendSponsorshipOfferCommand>();
|
|
|
|
|
|
services.AddScoped<ISetUpSponsorshipCommand, SetUpSponsorshipCommand>();
|
|
|
|
|
|
services.AddScoped<IValidateRedemptionTokenCommand, ValidateRedemptionTokenCommand>();
|
|
|
|
|
|
services.AddScoped<IValidateSponsorshipCommand, ValidateSponsorshipCommand>();
|
|
|
|
|
|
services.AddScoped<IValidateBillingSyncKeyCommand, ValidateBillingSyncKeyCommand>();
|
|
|
|
|
|
services.AddScoped<IOrganizationSponsorshipRenewCommand, OrganizationSponsorshipRenewCommand>();
|
|
|
|
|
|
services.AddScoped<ICloudSyncSponsorshipsCommand, CloudSyncSponsorshipsCommand>();
|
|
|
|
|
|
services.AddScoped<ISelfHostedSyncSponsorshipsCommand, SelfHostedSyncSponsorshipsCommand>();
|
|
|
|
|
|
services.AddScoped<ISelfHostedSyncSponsorshipsCommand, SelfHostedSyncSponsorshipsCommand>();
|
|
|
|
|
|
services.AddScoped<ICloudSyncSponsorshipsCommand, CloudSyncSponsorshipsCommand>();
|
|
|
|
|
|
services.AddScoped<IValidateBillingSyncKeyCommand, ValidateBillingSyncKeyCommand>();
|
|
|
|
|
|
if (globalSettings.SelfHosted)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<IRevokeSponsorshipCommand, SelfHostedRevokeSponsorshipCommand>();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-05-10 17:12:09 -04:00
|
|
|
|
services.AddScoped<IRevokeSponsorshipCommand, CloudRevokeSponsorshipCommand>();
|
2022-08-29 14:53:16 -04:00
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2022-08-29 14:53:16 -04:00
|
|
|
|
|
2022-11-28 17:39:09 -07:00
|
|
|
|
private static void AddOrganizationApiKeyCommandsQueries(this IServiceCollection services)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2022-11-28 17:39:09 -07:00
|
|
|
|
services.AddScoped<IGetOrganizationApiKeyQuery, GetOrganizationApiKeyQuery>();
|
2022-05-10 17:12:09 -04:00
|
|
|
|
services.AddScoped<IRotateOrganizationApiKeyCommand, RotateOrganizationApiKeyCommand>();
|
2022-11-28 17:39:09 -07:00
|
|
|
|
services.AddScoped<ICreateOrganizationApiKeyCommand, CreateOrganizationApiKeyCommand>();
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-19 17:00:54 +01:00
|
|
|
|
public static void AddOrganizationCollectionCommands(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<IDeleteCollectionCommand, DeleteCollectionCommand>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void AddOrganizationGroupCommands(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<ICreateGroupCommand, CreateGroupCommand>();
|
|
|
|
|
|
services.AddScoped<IDeleteGroupCommand, DeleteGroupCommand>();
|
|
|
|
|
|
services.AddScoped<IUpdateGroupCommand, UpdateGroupCommand>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-31 07:42:10 +10:00
|
|
|
|
private static void AddOrganizationLicenseCommandQueries(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddScoped<ICloudGetOrganizationLicenseQuery, CloudGetOrganizationLicenseQuery>();
|
|
|
|
|
|
services.AddScoped<ISelfHostedGetOrganizationLicenseQuery, SelfHostedGetOrganizationLicenseQuery>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-10 17:12:09 -04:00
|
|
|
|
private static void AddTokenizers(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddSingleton<IDataProtectorTokenFactory<OrganizationSponsorshipOfferTokenable>>(serviceProvider =>
|
|
|
|
|
|
new DataProtectorTokenFactory<OrganizationSponsorshipOfferTokenable>(
|
|
|
|
|
|
OrganizationSponsorshipOfferTokenable.ClearTextPrefix,
|
|
|
|
|
|
OrganizationSponsorshipOfferTokenable.DataProtectorPurpose,
|
2022-09-26 15:22:02 -04:00
|
|
|
|
serviceProvider.GetDataProtectionProvider(),
|
|
|
|
|
|
serviceProvider.GetRequiredService<ILogger<DataProtectorTokenFactory<OrganizationSponsorshipOfferTokenable>>>())
|
2022-05-10 17:12:09 -04:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|