|
|
|
|
@ -1,4 +1,5 @@
@@ -1,4 +1,5 @@
|
|
|
|
|
using System; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using Bit.Core.Enums; |
|
|
|
|
using Bit.Core.Exceptions; |
|
|
|
|
@ -12,17 +13,20 @@ namespace Bit.Core.Services
@@ -12,17 +13,20 @@ namespace Bit.Core.Services
|
|
|
|
|
private readonly ISsoConfigRepository _ssoConfigRepository; |
|
|
|
|
private readonly IPolicyRepository _policyRepository; |
|
|
|
|
private readonly IOrganizationRepository _organizationRepository; |
|
|
|
|
private readonly IOrganizationUserRepository _organizationUserRepository; |
|
|
|
|
private readonly IEventService _eventService; |
|
|
|
|
|
|
|
|
|
public SsoConfigService( |
|
|
|
|
ISsoConfigRepository ssoConfigRepository, |
|
|
|
|
IPolicyRepository policyRepository, |
|
|
|
|
IOrganizationRepository organizationRepository, |
|
|
|
|
IOrganizationUserRepository organizationUserRepository, |
|
|
|
|
IEventService eventService) |
|
|
|
|
{ |
|
|
|
|
_ssoConfigRepository = ssoConfigRepository; |
|
|
|
|
_policyRepository = policyRepository; |
|
|
|
|
_organizationRepository = organizationRepository; |
|
|
|
|
_organizationUserRepository = organizationUserRepository; |
|
|
|
|
_eventService = eventService; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -42,7 +46,8 @@ namespace Bit.Core.Services
@@ -42,7 +46,8 @@ namespace Bit.Core.Services
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var oldConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(config.OrganizationId); |
|
|
|
|
if (oldConfig?.GetData()?.UseKeyConnector == true && !useKeyConnector) |
|
|
|
|
var disabledKeyConnector = oldConfig?.GetData()?.UseKeyConnector == true && !useKeyConnector; |
|
|
|
|
if (disabledKeyConnector && await AnyOrgUserHasKeyConnectorEnabledAsync(config.OrganizationId)) |
|
|
|
|
{ |
|
|
|
|
throw new BadRequestException("Key Connector cannot be disabled at this moment."); |
|
|
|
|
} |
|
|
|
|
@ -51,6 +56,13 @@ namespace Bit.Core.Services
@@ -51,6 +56,13 @@ namespace Bit.Core.Services
|
|
|
|
|
await _ssoConfigRepository.UpsertAsync(config); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task<bool> AnyOrgUserHasKeyConnectorEnabledAsync(Guid organizationId) |
|
|
|
|
{ |
|
|
|
|
var userDetails = |
|
|
|
|
await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId); |
|
|
|
|
return userDetails.Any(u => u.UsesKeyConnector); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task VerifyDependenciesAsync(SsoConfig config) |
|
|
|
|
{ |
|
|
|
|
var policy = await _policyRepository.GetByOrganizationIdTypeAsync(config.OrganizationId, PolicyType.SingleOrg); |
|
|
|
|
|