1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00
bitwarden-server/util/Migrator/DbScripts/2023-02-16_FixSsoAvailableOrganizationDomain.sql
SmithThe4th 34544f2292
[SG-1082]-Defect-Update stored procedure to properly determine is SSO is available (#2715)
* Fixed SsoAvailble bug by using the enabled column from SsoConfig table, updated the existing query for EF Core

* Added no tracking to ef query since it is read only
2023-02-17 13:19:21 -05:00

31 lines
864 B
Transact-SQL

CREATE OR ALTER PROCEDURE [dbo].[OrganizationDomainSsoDetails_ReadByEmail]
@Email NVARCHAR(256)
AS
BEGIN
SET NOCOUNT ON
DECLARE @Domain NVARCHAR(256)
SELECT @Domain = SUBSTRING(@Email, CHARINDEX( '@', @Email) + 1, LEN(@Email))
SELECT
O.Id AS OrganizationId,
O.[Name] AS OrganizationName,
S.Enabled AS SsoAvailable,
P.Enabled AS SsoRequired,
O.Identifier AS OrganizationIdentifier,
OD.VerifiedDate,
P.[Type] AS PolicyType,
OD.DomainName
FROM
[dbo].[OrganizationView] O
INNER JOIN [dbo].[OrganizationDomainView] OD
ON O.Id = OD.OrganizationId
LEFT JOIN [dbo].[PolicyView] P
ON O.Id = P.OrganizationId
LEFT JOIN [dbo].[Ssoconfig] S
ON O.Id = S.OrganizationId
WHERE OD.DomainName = @Domain
AND O.Enabled = 1
AND (P.Id is NULL OR (P.Id IS NOT NULL AND P.[Type] = 4)) -- SSO Type
END