1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-02 23:41:21 +01:00

DAL & CRUD for SSO

This commit is contained in:
Matt Portune 2020-06-25 16:42:29 -04:00
parent b7154f017f
commit 39a81af3e9
14 changed files with 407 additions and 2 deletions

View File

@ -0,0 +1,8 @@
namespace Bit.Core.Enums
{
public enum SsoType : byte
{
// TODO proper SsoType values
Test = 1
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace Bit.Core.Models.Api
{
public class SsoConfigRequestModel
{
public long Id { get; set; }
public bool Enabled { get; set; }
public Guid OrganizationId { get; set; }
public string Data { get; set; }
}
}

View File

@ -0,0 +1,27 @@
using System;
using Bit.Core.Models.Table;
namespace Bit.Core.Models.Api
{
public class SsoConfigResponseModel : ResponseModel
{
public SsoConfigResponseModel(SsoConfig ssoConfig, string obj = "ssoconfig")
: base(obj)
{
if (ssoConfig == null)
{
throw new ArgumentNullException(nameof(ssoConfig));
}
Id = ssoConfig.Id;
Enabled = ssoConfig.Enabled;
OrganizationId = ssoConfig.OrganizationId;
Data = ssoConfig.Data;
}
public long Id { get; set; }
public bool Enabled { get; set; }
public Guid OrganizationId { get; set; }
public string Data { get; set; }
}
}

View File

@ -12,6 +12,7 @@ namespace Bit.Core.Models.Table
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
public Guid Id { get; set; }
public string Identifier { get; set; }
public string Name { get; set; }
public string BusinessName { get; set; }
public string BusinessAddress1 { get; set; }

View File

@ -0,0 +1,14 @@
using System;
namespace Bit.Core.Models.Table
{
public class SsoConfig
{
public long Id { get; set; }
public bool Enabled { get; set; } = true;
public Guid OrganizationId { get; set; }
public string Data { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
}
}

View File

@ -69,8 +69,10 @@
<Folder Include="dbo\User Defined Types\" />
</ItemGroup>
<ItemGroup>
<Build Include="dbo\Stored Procedures\SsoConfig_Create.sql" />
<Build Include="dbo\Stored Procedures\SsoConfig_ReadByIdentifier.sql" />
<Build Include="dbo\Stored Procedures\SsoConfig_ReadByOrganizationId.sql" />
<Build Include="dbo\Stored Procedures\SsoConfig_Update.sql" />
<Build Include="dbo\Tables\Grant.sql" />
<Build Include="dbo\Tables\SsoConfig.sql" />
<Build Include="dbo\Tables\User.sql" />

View File

@ -1,5 +1,6 @@
CREATE PROCEDURE [dbo].[Organization_Create]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@ -41,6 +42,7 @@ BEGIN
INSERT INTO [dbo].[Organization]
(
[Id],
[Identifier],
[Name],
[BusinessName],
[BusinessAddress1],
@ -79,6 +81,7 @@ BEGIN
VALUES
(
@Id,
@Identifier,
@Name,
@BusinessName,
@BusinessAddress1,

View File

@ -1,5 +1,6 @@
CREATE PROCEDURE [dbo].[Organization_Update]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@ -41,6 +42,7 @@ BEGIN
UPDATE
[dbo].[Organization]
SET
[Identifier] = @Identifier,
[Name] = @Name,
[BusinessName] = @BusinessName,
[BusinessAddress1] = @BusinessAddress1,

View File

@ -0,0 +1,30 @@
CREATE PROCEDURE [dbo].[SsoConfig_Create]
@Id BIGINT,
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[SsoConfig]
(
[Id],
[Enabled],
[OrganizationId],
[Data],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@Enabled,
@OrganizationId,
@Data,
@CreationDate,
@RevisionDate
)
END

View File

@ -0,0 +1,22 @@
CREATE PROCEDURE [dbo].[SsoConfig_Update]
@Id BIGINT,
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[SsoConfig]
SET
[Enabled] = @Enabled,
[OrganizationId] = @OrganizationId,
[Data] = @Data,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END

View File

@ -2,7 +2,6 @@
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Enabled] BIT NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Identifier] NVARCHAR (50) NULL,
[Data] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,

View File

@ -17,3 +17,216 @@ BEGIN
WHERE [Identifier] IS NOT NULL;
END
GO
IF OBJECT_ID('[dbo].[Organization_Create]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Organization_Create]
END
GO
CREATE PROCEDURE [dbo].[Organization_Create]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@BusinessAddress2 NVARCHAR(50),
@BusinessAddress3 NVARCHAR(50),
@BusinessCountry VARCHAR(2),
@BusinessTaxNumber NVARCHAR(30),
@BillingEmail NVARCHAR(50),
@Plan NVARCHAR(50),
@PlanType TINYINT,
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UsePolicies BIT,
@UseGroups BIT,
@UseDirectory BIT,
@UseEvents BIT,
@UseTotp BIT,
@Use2fa BIT,
@UseApi BIT,
@SelfHost BIT,
@UsersGetPremium BIT,
@Storage BIGINT,
@MaxStorageGb SMALLINT,
@Gateway TINYINT,
@GatewayCustomerId VARCHAR(50),
@GatewaySubscriptionId VARCHAR(50),
@Enabled BIT,
@LicenseKey VARCHAR(100),
@ApiKey VARCHAR(30),
@TwoFactorProviders NVARCHAR(MAX),
@ExpirationDate DATETIME2(7),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Organization]
(
[Id],
[Identifier],
[Name],
[BusinessName],
[BusinessAddress1],
[BusinessAddress2],
[BusinessAddress3],
[BusinessCountry],
[BusinessTaxNumber],
[BillingEmail],
[Plan],
[PlanType],
[Seats],
[MaxCollections],
[UsePolicies],
[UseGroups],
[UseDirectory],
[UseEvents],
[UseTotp],
[Use2fa],
[UseApi],
[SelfHost],
[UsersGetPremium],
[Storage],
[MaxStorageGb],
[Gateway],
[GatewayCustomerId],
[GatewaySubscriptionId],
[Enabled],
[LicenseKey],
[ApiKey],
[TwoFactorProviders],
[ExpirationDate],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@Identifier,
@Name,
@BusinessName,
@BusinessAddress1,
@BusinessAddress2,
@BusinessAddress3,
@BusinessCountry,
@BusinessTaxNumber,
@BillingEmail,
@Plan,
@PlanType,
@Seats,
@MaxCollections,
@UsePolicies,
@UseGroups,
@UseDirectory,
@UseEvents,
@UseTotp,
@Use2fa,
@UseApi,
@SelfHost,
@UsersGetPremium,
@Storage,
@MaxStorageGb,
@Gateway,
@GatewayCustomerId,
@GatewaySubscriptionId,
@Enabled,
@LicenseKey,
@ApiKey,
@TwoFactorProviders,
@ExpirationDate,
@CreationDate,
@RevisionDate
)
END
GO
IF OBJECT_ID('[dbo].[Organization_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Organization_Update]
END
GO
CREATE PROCEDURE [dbo].[Organization_Update]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@BusinessAddress2 NVARCHAR(50),
@BusinessAddress3 NVARCHAR(50),
@BusinessCountry VARCHAR(2),
@BusinessTaxNumber NVARCHAR(30),
@BillingEmail NVARCHAR(50),
@Plan NVARCHAR(50),
@PlanType TINYINT,
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UsePolicies BIT,
@UseGroups BIT,
@UseDirectory BIT,
@UseEvents BIT,
@UseTotp BIT,
@Use2fa BIT,
@UseApi BIT,
@SelfHost BIT,
@UsersGetPremium BIT,
@Storage BIGINT,
@MaxStorageGb SMALLINT,
@Gateway TINYINT,
@GatewayCustomerId VARCHAR(50),
@GatewaySubscriptionId VARCHAR(50),
@Enabled BIT,
@LicenseKey VARCHAR(100),
@ApiKey VARCHAR(30),
@TwoFactorProviders NVARCHAR(MAX),
@ExpirationDate DATETIME2(7),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Organization]
SET
[Identifier] = @Identifier,
[Name] = @Name,
[BusinessName] = @BusinessName,
[BusinessAddress1] = @BusinessAddress1,
[BusinessAddress2] = @BusinessAddress2,
[BusinessAddress3] = @BusinessAddress3,
[BusinessCountry] = @BusinessCountry,
[BusinessTaxNumber] = @BusinessTaxNumber,
[BillingEmail] = @BillingEmail,
[Plan] = @Plan,
[PlanType] = @PlanType,
[Seats] = @Seats,
[MaxCollections] = @MaxCollections,
[UsePolicies] = @UsePolicies,
[UseGroups] = @UseGroups,
[UseDirectory] = @UseDirectory,
[UseEvents] = @UseEvents,
[UseTotp] = @UseTotp,
[Use2fa] = @Use2fa,
[UseApi] = @UseApi,
[SelfHost] = @SelfHost,
[UsersGetPremium] = @UsersGetPremium,
[Storage] = @Storage,
[MaxStorageGb] = @MaxStorageGb,
[Gateway] = @Gateway,
[GatewayCustomerId] = @GatewayCustomerId,
[GatewaySubscriptionId] = @GatewaySubscriptionId,
[Enabled] = @Enabled,
[LicenseKey] = @LicenseKey,
[ApiKey] = @ApiKey,
[TwoFactorProviders] = @TwoFactorProviders,
[ExpirationDate] = @ExpirationDate,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO

View File

@ -4,7 +4,6 @@ BEGIN
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
[Enabled] BIT NOT NULL,
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
[Identifier] NVARCHAR (50) NULL,
[Data] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
@ -28,6 +27,74 @@ FROM
[dbo].[SsoConfig]
GO
IF OBJECT_ID('[dbo].[SsoConfig_Create]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_Create]
END
GO
CREATE PROCEDURE [dbo].[SsoConfig_Create]
@Id BIGINT,
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[SsoConfig]
(
[Id],
[Enabled],
[OrganizationId],
[Data],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@Enabled,
@OrganizationId,
@Data,
@CreationDate,
@RevisionDate
)
END
GO
IF OBJECT_ID('[dbo].[SsoConfig_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_Update]
END
GO
CREATE PROCEDURE [dbo].[SsoConfig_Update]
@Id BIGINT,
@Enabled BIT,
@OrganizationId UNIQUEIDENTIFIER,
@Data NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[SsoConfig]
SET
[Enabled] = @Enabled,
[OrganizationId] = @OrganizationId,
[Data] = @Data,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO
IF OBJECT_ID('[dbo].[SsoConfig_ReadByIdentifier]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[SsoConfig_ReadByIdentifier]

View File

@ -242,6 +242,7 @@ GO
CREATE PROCEDURE [dbo].[Organization_Create]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@ -283,6 +284,7 @@ BEGIN
INSERT INTO [dbo].[Organization]
(
[Id],
[Identifier],
[Name],
[BusinessName],
[BusinessAddress1],
@ -321,6 +323,7 @@ BEGIN
VALUES
(
@Id,
@Identifier,
@Name,
@BusinessName,
@BusinessAddress1,
@ -367,6 +370,7 @@ GO
CREATE PROCEDURE [dbo].[Organization_Update]
@Id UNIQUEIDENTIFIER,
@Identifier NVARCHAR(50),
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@ -408,6 +412,7 @@ BEGIN
UPDATE
[dbo].[Organization]
SET
[Identifier] = @Identifier,
[Name] = @Name,
[BusinessName] = @BusinessName,
[BusinessAddress1] = @BusinessAddress1,