1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 13:08:17 -05:00

Modified sso details stored procedure to remove policy checks or an organization (#2831)

This commit is contained in:
SmithThe4th 2023-04-03 11:03:59 -04:00 committed by GitHub
parent 60bdf77e8b
commit 6551d9176b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 18 deletions

View File

@ -16,13 +16,11 @@ public class OrganizationDomainSsoDetailsResponseModel : ResponseModel
SsoAvailable = data.SsoAvailable;
DomainName = data.DomainName;
OrganizationIdentifier = data.OrganizationIdentifier;
SsoRequired = data.SsoRequired;
VerifiedDate = data.VerifiedDate;
}
public bool SsoAvailable { get; private set; }
public string DomainName { get; private set; }
public string OrganizationIdentifier { get; private set; }
public bool SsoRequired { get; private set; }
public DateTime? VerifiedDate { get; private set; }
}

View File

@ -1,6 +1,4 @@
using Bit.Core.Enums;
namespace Bit.Core.Models.Data.Organizations;
namespace Bit.Core.Models.Data.Organizations;
public class OrganizationDomainSsoDetailsData
{
@ -9,8 +7,6 @@ public class OrganizationDomainSsoDetailsData
public string DomainName { get; set; }
public bool SsoAvailable { get; set; }
public string OrganizationIdentifier { get; set; }
public bool SsoRequired { get; set; }
public PolicyType? PolicyType { get; set; }
public DateTime? VerifiedDate { get; set; }
public bool OrganizationEnabled { get; set; }
}

View File

@ -1,6 +1,5 @@
using System.Net.Mail;
using AutoMapper;
using Bit.Core.Enums;
using Bit.Core.Models.Data.Organizations;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
@ -78,19 +77,14 @@ public class OrganizationDomainRepository : Repository<Core.Entities.Organizatio
from od in o.Domains
join s in dbContext.SsoConfigs on o.Id equals s.OrganizationId into sJoin
from s in sJoin.DefaultIfEmpty()
join p in dbContext.Policies.Where(p => p.Type == PolicyType.RequireSso) on o.Id
equals p.OrganizationId into pJoin
from p in pJoin.DefaultIfEmpty()
where od.DomainName == domainName && o.Enabled
select new OrganizationDomainSsoDetailsData
{
OrganizationId = o.Id,
OrganizationName = o.Name,
SsoAvailable = o.SsoConfigs.Any(sc => sc.Enabled),
SsoRequired = p != null && p.Enabled,
OrganizationIdentifier = o.Identifier,
VerifiedDate = od.VerifiedDate,
PolicyType = p.Type,
DomainName = od.DomainName
})
.AsNoTracking()

View File

@ -12,20 +12,15 @@ BEGIN
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

View File

@ -0,0 +1,26 @@
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,
O.Identifier AS OrganizationIdentifier,
OD.VerifiedDate,
OD.DomainName
FROM
[dbo].[OrganizationView] O
INNER JOIN [dbo].[OrganizationDomainView] OD
ON O.Id = OD.OrganizationId
LEFT JOIN [dbo].[Ssoconfig] S
ON O.Id = S.OrganizationId
WHERE OD.DomainName = @Domain
AND O.Enabled = 1
END