1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Added UseSso bool to Organization (#834)

* Added UseSso bool to org

* Update fields in migration script

* bump version & check enabled flag on ssoConfig
This commit is contained in:
Matt Portune
2020-07-22 09:38:39 -04:00
committed by GitHub
parent 7bf559b4b6
commit 51fd87df0b
16 changed files with 364 additions and 8 deletions

View File

@ -30,6 +30,7 @@ namespace Bit.Admin.Models
Seats = org.Seats;
MaxCollections = org.MaxCollections;
UsePolicies = org.UsePolicies;
UseSso = org.UseSso;
UseGroups = org.UseGroups;
UseDirectory = org.UseDirectory;
UseEvents = org.UseEvents;
@ -71,6 +72,8 @@ namespace Bit.Admin.Models
public short? MaxCollections { get; set; }
[Display(Name = "Policies")]
public bool UsePolicies { get; set; }
[Display(Name = "SSO")]
public bool UseSso { get; set; }
[Display(Name = "Groups")]
public bool UseGroups { get; set; }
[Display(Name = "Directory")]
@ -112,6 +115,7 @@ namespace Bit.Admin.Models
existingOrganization.Seats = Seats;
existingOrganization.MaxCollections = MaxCollections;
existingOrganization.UsePolicies = UsePolicies;
existingOrganization.UseSso = UseSso;
existingOrganization.UseGroups = UseGroups;
existingOrganization.UseDirectory = UseDirectory;
existingOrganization.UseEvents = UseEvents;

View File

@ -22,6 +22,7 @@
document.getElementById('@(nameof(Model.MaxStorageGb))').value = '1';
// Features
document.getElementById('@(nameof(Model.UsePolicies))').checked = true;
document.getElementById('@(nameof(Model.UseSso))').checked = true;
document.getElementById('@(nameof(Model.UseGroups))').checked = true;
document.getElementById('@(nameof(Model.UseDirectory))').checked = true;
document.getElementById('@(nameof(Model.UseEvents))').checked = true;
@ -165,6 +166,10 @@
<input type="checkbox" class="form-check-input" asp-for="UsePolicies">
<label class="form-check-label" asp-for="UsePolicies"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="UseSso">
<label class="form-check-label" asp-for="UseSso"></label>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" asp-for="UseDirectory">
<label class="form-check-label" asp-for="UseDirectory"></label>

View File

@ -17,6 +17,10 @@ namespace Bit.Core.Enums
[Display(Name = "Enterprise (Annually)")]
EnterpriseAnnually = 5,
[Display(Name = "Custom")]
Custom = 6
Custom = 6,
[Display(Name = "PLACEHOLDER")]
SsoPlaceholderMonthly = 10,
[Display(Name = "PLACEHOLDER")]
SsoPlaceholderAnnually = 11,
}
}

View File

@ -31,6 +31,7 @@ namespace Bit.Core.Models.Api
MaxCollections = organization.MaxCollections;
MaxStorageGb = organization.MaxStorageGb;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
@ -56,6 +57,7 @@ namespace Bit.Core.Models.Api
public short? MaxCollections { get; set; }
public short? MaxStorageGb { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }

View File

@ -11,6 +11,7 @@ namespace Bit.Core.Models.Api
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UsePolicies = organization.UsePolicies;
UseSso = organization.UseSso;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
UseEvents = organization.UseEvents;
@ -31,13 +32,14 @@ namespace Bit.Core.Models.Api
public string Id { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }
public bool Use2fa { get; set; }
public bool UseApi { get; set; }
public bool UseBusinessPortal => UsePolicies; // TODO add events if needed, add SSO when created
public bool UseBusinessPortal => UsePolicies || UseSso; // TODO add events if needed
public bool UsersGetPremium { get; set; }
public bool SelfHost { get; set; }
public int Seats { get; set; }

View File

@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId,
ILicensingService licenseService)
{
Version = 5; // TODO: bump to version 6
Version = 6; // TODO: bump to version 7
LicenseKey = org.LicenseKey;
InstallationId = installationId;
Id = org.Id;
@ -32,6 +32,7 @@ namespace Bit.Core.Models.Business
Seats = org.Seats;
MaxCollections = org.MaxCollections;
UsePolicies = org.UsePolicies;
UseSso = org.UseSso;
UseGroups = org.UseGroups;
UseEvents = org.UseEvents;
UseDirectory = org.UseDirectory;
@ -100,6 +101,7 @@ namespace Bit.Core.Models.Business
public short? Seats { get; set; }
public short? MaxCollections { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseGroups { get; set; }
public bool UseEvents { get; set; }
public bool UseDirectory { get; set; }
@ -122,7 +124,7 @@ namespace Bit.Core.Models.Business
public byte[] GetDataBytes(bool forHash = false)
{
string data = null;
if (Version >= 1 && Version <= 6)
if (Version >= 1 && Version <= 7)
{
var props = typeof(OrganizationLicense)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
@ -139,6 +141,8 @@ namespace Bit.Core.Models.Business
(Version >= 5 || !p.Name.Equals(nameof(UseApi))) &&
// UsePolicies was added in Version 6
(Version >= 6 || !p.Name.Equals(nameof(UsePolicies))) &&
// UseSso was added in Version 7
(Version >= 7 || !p.Name.Equals(nameof(UseSso))) &&
(
!forHash ||
(
@ -175,7 +179,7 @@ namespace Bit.Core.Models.Business
return false;
}
if (Version >= 1 && Version <= 6)
if (Version >= 1 && Version <= 7)
{
return InstallationId == globalSettings.Installation.Id && SelfHost;
}
@ -192,7 +196,7 @@ namespace Bit.Core.Models.Business
return false;
}
if (Version >= 1 && Version <= 6)
if (Version >= 1 && Version <= 7)
{
var valid =
globalSettings.Installation.Id == InstallationId &&
@ -231,6 +235,11 @@ namespace Bit.Core.Models.Business
{
valid = organization.UsePolicies == UsePolicies;
}
if (valid && Version >= 7)
{
valid = organization.UseSso == UseSso;
}
return valid;
}

View File

@ -8,6 +8,7 @@ namespace Bit.Core.Models.Data
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }

View File

@ -16,6 +16,7 @@ namespace Bit.Core.Models.StaticStore
public bool CanBuyPremiumAccessAddon { get; set; }
public bool UseGroups { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }
public bool UseTotp { get; set; }

View File

@ -26,6 +26,7 @@ namespace Bit.Core.Models.Table
public short? Seats { get; set; }
public short? MaxCollections { get; set; }
public bool UsePolicies { get; set; }
public bool UseSso { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public bool UseEvents { get; set; }

View File

@ -34,6 +34,7 @@ namespace Bit.Core.Services
private readonly IApplicationCacheService _applicationCacheService;
private readonly IPaymentService _paymentService;
private readonly IPolicyRepository _policyRepository;
private readonly ISsoConfigRepository _ssoConfigRepository;
private readonly IReferenceEventService _referenceEventService;
private readonly GlobalSettings _globalSettings;
@ -54,6 +55,7 @@ namespace Bit.Core.Services
IApplicationCacheService applicationCacheService,
IPaymentService paymentService,
IPolicyRepository policyRepository,
ISsoConfigRepository ssoConfigRepository,
IReferenceEventService referenceEventService,
GlobalSettings globalSettings)
{
@ -73,6 +75,7 @@ namespace Bit.Core.Services
_applicationCacheService = applicationCacheService;
_paymentService = paymentService;
_policyRepository = policyRepository;
_ssoConfigRepository = ssoConfigRepository;
_referenceEventService = referenceEventService;
_globalSettings = globalSettings;
}
@ -216,6 +219,16 @@ namespace Bit.Core.Services
$"Disable your policies.");
}
}
if (!newPlan.UseSso && organization.UseSso)
{
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(organization.Id);
if (ssoConfig != null && ssoConfig.Enabled)
{
throw new BadRequestException($"Your new plan does not allow the SSO feature. " +
$"Disable your SSO configuration.");
}
}
// TODO: Check storage?
@ -504,6 +517,7 @@ namespace Bit.Core.Services
MaxStorageGb = !plan.MaxStorageGb.HasValue ?
(short?)null : (short)(plan.MaxStorageGb.Value + signup.AdditionalStorageGb),
UsePolicies = plan.UsePolicies,
UseSso = plan.UseSso,
UseGroups = plan.UseGroups,
UseEvents = plan.UseEvents,
UseDirectory = plan.UseDirectory,
@ -586,6 +600,7 @@ namespace Bit.Core.Services
MaxCollections = license.MaxCollections,
MaxStorageGb = _globalSettings.SelfHosted ? 10240 : license.MaxStorageGb, // 10 TB
UsePolicies = license.UsePolicies,
UseSso = license.UseSso,
UseGroups = license.UseGroups,
UseDirectory = license.UseDirectory,
UseEvents = license.UseEvents,
@ -747,6 +762,16 @@ namespace Bit.Core.Services
$"policies. Your new license does not allow for the use of policies. Disable all policies.");
}
}
if (!license.UseSso && organization.UseSso)
{
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(organization.Id);
if (ssoConfig != null && ssoConfig.Enabled)
{
throw new BadRequestException($"Your organization currently has a SSO configuration. " +
$"Your new license does not allow for the use of SSO. Disable your SSO configuration.");
}
}
var dir = $"{_globalSettings.LicenseDirectory}/organization";
Directory.CreateDirectory(dir);
@ -766,6 +791,7 @@ namespace Bit.Core.Services
organization.Use2fa = license.Use2fa;
organization.UseApi = license.UseApi;
organization.UsePolicies = license.UsePolicies;
organization.UseSso = license.UseSso;
organization.SelfHost = license.SelfHost;
organization.UsersGetPremium = license.UsersGetPremium;
organization.Plan = license.Plan;

View File

@ -14,6 +14,7 @@
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UsePolicies BIT,
@UseSso BIT,
@UseGroups BIT,
@UseDirectory BIT,
@UseEvents BIT,
@ -56,6 +57,7 @@ BEGIN
[Seats],
[MaxCollections],
[UsePolicies],
[UseSso],
[UseGroups],
[UseDirectory],
[UseEvents],
@ -95,6 +97,7 @@ BEGIN
@Seats,
@MaxCollections,
@UsePolicies,
@UseSso,
@UseGroups,
@UseDirectory,
@UseEvents,

View File

@ -14,6 +14,7 @@
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UsePolicies BIT,
@UseSso BIT,
@UseGroups BIT,
@UseDirectory BIT,
@UseEvents BIT,
@ -56,6 +57,7 @@ BEGIN
[Seats] = @Seats,
[MaxCollections] = @MaxCollections,
[UsePolicies] = @UsePolicies,
[UseSso] = @UseSso,
[UseGroups] = @UseGroups,
[UseDirectory] = @UseDirectory,
[UseEvents] = @UseEvents,

View File

@ -14,6 +14,7 @@
[Seats] SMALLINT NULL,
[MaxCollections] SMALLINT NULL,
[UsePolicies] BIT NOT NULL,
[UseSso] BIT NOT NULL,
[UseGroups] BIT NOT NULL,
[UseDirectory] BIT NOT NULL,
[UseEvents] BIT NOT NULL,

View File

@ -6,6 +6,7 @@ SELECT
O.[Name],
O.[Enabled],
O.[UsePolicies],
O.[UseSso],
O.[UseGroups],
O.[UseDirectory],
O.[UseEvents],