1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-25 22:21:38 +01:00

Grant table for identity persisted grants

This commit is contained in:
Kyle Spearrin 2017-01-11 22:43:03 -05:00
parent 2b7f6e5a6c
commit 9749d1e3a8
9 changed files with 168 additions and 0 deletions

View File

@ -69,6 +69,7 @@
<Build Include="dbo\Tables\Device.sql" />
<Build Include="dbo\Tables\History.sql" />
<Build Include="dbo\Tables\User.sql" />
<Build Include="dbo\Tables\Grant.sql" />
<Build Include="dbo\Views\CipherView.sql" />
<Build Include="dbo\Views\DeviceView.sql" />
<Build Include="dbo\Views\HistoryView.sql" />
@ -94,5 +95,12 @@
<Build Include="dbo\Stored Procedures\User_ReadById.sql" />
<Build Include="dbo\Stored Procedures\User_Update.sql" />
<Build Include="dbo\Stored Procedures\User_UpdateEmailPassword.sql" />
<Build Include="dbo\Stored Procedures\Grant_DeleteByKey.sql" />
<Build Include="dbo\Stored Procedures\Grant_DeleteBySubjectIdClientId.sql" />
<Build Include="dbo\Stored Procedures\Grant_DeleteBySubjectIdClientIdType.sql" />
<Build Include="dbo\Stored Procedures\Grant_ReadByKey.sql" />
<Build Include="dbo\Views\GrantView.sql" />
<Build Include="dbo\Stored Procedures\Grant_ReadBySubjectId.sql" />
<Build Include="dbo\Stored Procedures\Grant_Save.sql" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
CREATE PROCEDURE [dbo].[Grant_DeleteByKey]
@Key NVARCHAR(200)
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[Grant]
WHERE
[Key] = @Key
END

View File

@ -0,0 +1,14 @@
CREATE PROCEDURE [dbo].[Grant_DeleteBySubjectIdClientId]
@SubjectId NVARCHAR(50),
@ClientId NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[Grant]
WHERE
[SubjectId] = @SubjectId
AND [ClientId] = @ClientId
END

View File

@ -0,0 +1,16 @@
CREATE PROCEDURE [dbo].[Grant_DeleteBySubjectIdClientIdType]
@SubjectId NVARCHAR(50),
@ClientId NVARCHAR(50),
@Type NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[Grant]
WHERE
[SubjectId] = @SubjectId
AND [ClientId] = @ClientId
AND [Type] = @Type
END

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Grant_ReadByKey]
@Key NVARCHAR(200)
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[GrantView]
WHERE
[Key] = @Key
END

View File

@ -0,0 +1,13 @@
CREATE PROCEDURE [dbo].[Grant_ReadBySubjectId]
@SubjectId NVARCHAR(50)
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[GrantView]
WHERE
[SubjectId] = @SubjectId
END

View File

@ -0,0 +1,70 @@
CREATE PROCEDURE [dbo].[Grant_Save]
@Key NVARCHAR(200),
@Type NVARCHAR(50),
@SubjectId NVARCHAR(50),
@ClientId NVARCHAR(50),
@CreationDate DATETIME2,
@ExpirationDate DATETIME2,
@Data NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON
MERGE
[dbo].[Grant] AS [Target]
USING
(
VALUES
(
@Key,
@Type,
@SubjectId,
@ClientId,
@CreationDate,
@ExpirationDate,
@Data
)
) AS [Source]
(
[Key],
[Type],
[SubjectId],
[ClientId],
[CreationDate],
[ExpirationDate],
[Data]
)
ON
[Target].[Key] = [Source].[Key]
WHEN MATCHED THEN
UPDATE
SET
[Type] = [Source].[Type],
[SubjectId] = [Source].[SubjectId],
[ClientId] = [Source].[ClientId],
[CreationDate] = [Source].[CreationDate],
[ExpirationDate] = [Source].[ExpirationDate],
[Data] = [Source].[Data]
WHEN NOT MATCHED THEN
INSERT
(
[Key],
[Type],
[SubjectId],
[ClientId],
[CreationDate],
[ExpirationDate],
[Data]
)
VALUES
(
[Source].[Key],
[Source].[Type],
[Source].[SubjectId],
[Source].[ClientId],
[Source].[CreationDate],
[Source].[ExpirationDate],
[Source].[Data]
)
;
END

View File

@ -0,0 +1,16 @@
CREATE TABLE [dbo].[Grant] (
[Key] NVARCHAR (200) NOT NULL,
[Type] NVARCHAR (50) NULL,
[SubjectId] NVARCHAR (50) NULL,
[ClientId] NVARCHAR (50) NOT NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[ExpirationDate] DATETIME2 (7) NULL,
[Data] NVARCHAR (MAX) NOT NULL,
CONSTRAINT [PK_Grant] PRIMARY KEY CLUSTERED ([Key] ASC)
);
GO
CREATE NONCLUSTERED INDEX [IX_Grant_SubjectId_ClientId_Type]
ON [dbo].[Grant]([SubjectId] ASC, [ClientId] ASC, [Type] ASC);

View File

@ -0,0 +1,6 @@
CREATE VIEW [dbo].[GrantView]
AS
SELECT
*
FROM
[dbo].[Grant]