2022-06-29 19:46:41 -04:00
using System.Text.Json ;
2023-10-19 01:27:56 +10:00
using Bit.Api.AdminConsole.Models.Request.Organizations ;
using Bit.Api.AdminConsole.Models.Response ;
using Bit.Api.AdminConsole.Models.Response.Organizations ;
2023-04-14 13:25:56 -04:00
using Bit.Api.Auth.Models.Request.Accounts ;
using Bit.Api.Auth.Models.Request.Organizations ;
using Bit.Api.Auth.Models.Response.Organizations ;
2021-12-14 15:05:07 +00:00
using Bit.Api.Models.Request.Accounts ;
using Bit.Api.Models.Request.Organizations ;
using Bit.Api.Models.Response ;
2023-05-10 12:52:08 -07:00
using Bit.Core ;
2023-11-23 07:07:37 +10:00
using Bit.Core.AdminConsole.Enums ;
2024-05-22 12:59:19 -04:00
using Bit.Core.AdminConsole.Models.Business.Tokenables ;
2023-11-23 07:07:37 +10:00
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies ;
2023-10-27 07:47:44 +10:00
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationApiKeys.Interfaces ;
2024-12-05 21:18:02 -06:00
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations ;
2025-01-27 10:58:08 +00:00
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces ;
2024-10-16 10:33:00 +01:00
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces ;
2025-03-21 10:07:55 -04:00
using Bit.Core.AdminConsole.OrganizationFeatures.Policies ;
using Bit.Core.AdminConsole.OrganizationFeatures.Policies.PolicyRequirements ;
2023-10-27 03:38:29 +10:00
using Bit.Core.AdminConsole.Repositories ;
2023-05-10 12:52:08 -07:00
using Bit.Core.Auth.Enums ;
2023-04-14 13:25:56 -04:00
using Bit.Core.Auth.Repositories ;
using Bit.Core.Auth.Services ;
2024-06-14 15:34:47 -04:00
using Bit.Core.Billing.Enums ;
2024-04-19 10:09:18 -04:00
using Bit.Core.Billing.Extensions ;
2025-02-27 07:55:46 -05:00
using Bit.Core.Billing.Pricing ;
2024-05-23 10:17:00 -04:00
using Bit.Core.Billing.Services ;
2017-03-02 00:15:05 -05:00
using Bit.Core.Context ;
2020-10-20 02:48:10 -04:00
using Bit.Core.Enums ;
2017-03-02 00:15:05 -05:00
using Bit.Core.Exceptions ;
2018-03-23 09:44:48 -04:00
using Bit.Core.Repositories ;
2017-03-02 00:15:05 -05:00
using Bit.Core.Services ;
2021-02-22 15:35:16 -06:00
using Bit.Core.Settings ;
2024-05-22 12:59:19 -04:00
using Bit.Core.Tokens ;
2017-08-14 20:57:45 -04:00
using Bit.Core.Utilities ;
2017-03-02 00:15:05 -05:00
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
2023-10-19 01:27:56 +10:00
namespace Bit.Api.AdminConsole.Controllers ;
2017-03-03 21:53:27 -05:00
2017-03-02 00:15:05 -05:00
[Route("organizations")]
[Authorize("Application")]
2017-03-03 21:53:27 -05:00
public class OrganizationsController : Controller
2022-08-29 16:06:55 -04:00
{
2017-03-02 00:15:05 -05:00
private readonly IOrganizationRepository _organizationRepository ;
2017-03-03 00:07:11 -05:00
private readonly IOrganizationUserRepository _organizationUserRepository ;
2021-09-15 12:23:47 -05:00
private readonly IPolicyRepository _policyRepository ;
2017-03-03 00:07:11 -05:00
private readonly IOrganizationService _organizationService ;
2017-03-02 00:15:05 -05:00
private readonly IUserService _userService ;
2017-03-03 21:53:27 -05:00
private readonly ICurrentContext _currentContext ;
2021-10-06 10:39:13 +02:00
private readonly ISsoConfigRepository _ssoConfigRepository ;
private readonly ISsoConfigService _ssoConfigService ;
2022-11-28 17:39:09 -07:00
private readonly IGetOrganizationApiKeyQuery _getOrganizationApiKeyQuery ;
2022-05-10 17:12:09 -04:00
private readonly IRotateOrganizationApiKeyCommand _rotateOrganizationApiKeyCommand ;
2022-11-28 17:39:09 -07:00
private readonly ICreateOrganizationApiKeyCommand _createOrganizationApiKeyCommand ;
2022-05-10 17:12:09 -04:00
private readonly IOrganizationApiKeyRepository _organizationApiKeyRepository ;
2023-05-10 12:52:08 -07:00
private readonly IFeatureService _featureService ;
2017-08-14 22:05:37 -04:00
private readonly GlobalSettings _globalSettings ;
2024-04-19 10:09:18 -04:00
private readonly IProviderRepository _providerRepository ;
2024-05-23 10:17:00 -04:00
private readonly IProviderBillingService _providerBillingService ;
2024-05-22 12:59:19 -04:00
private readonly IDataProtectorTokenFactory < OrgDeleteTokenable > _orgDeleteTokenDataFactory ;
2024-10-16 10:33:00 +01:00
private readonly IRemoveOrganizationUserCommand _removeOrganizationUserCommand ;
2024-12-05 21:18:02 -06:00
private readonly ICloudOrganizationSignUpCommand _cloudOrganizationSignUpCommand ;
2025-01-27 10:58:08 +00:00
private readonly IOrganizationDeleteCommand _organizationDeleteCommand ;
2025-03-21 10:07:55 -04:00
private readonly IPolicyRequirementQuery _policyRequirementQuery ;
2025-02-27 07:55:46 -05:00
private readonly IPricingClient _pricingClient ;
2025-04-09 15:23:29 +01:00
private readonly IOrganizationUpdateKeysCommand _organizationUpdateKeysCommand ;
2022-08-29 16:06:55 -04:00
2017-04-06 13:21:26 -04:00
public OrganizationsController (
2017-03-02 00:15:05 -05:00
IOrganizationRepository organizationRepository ,
2017-03-03 00:07:11 -05:00
IOrganizationUserRepository organizationUserRepository ,
2021-09-15 12:23:47 -05:00
IPolicyRepository policyRepository ,
2017-03-03 00:07:11 -05:00
IOrganizationService organizationService ,
2017-04-05 16:13:40 -04:00
IUserService userService ,
2021-02-04 12:54:21 -06:00
ICurrentContext currentContext ,
2021-10-06 10:39:13 +02:00
ISsoConfigRepository ssoConfigRepository ,
ISsoConfigService ssoConfigService ,
2022-11-28 17:39:09 -07:00
IGetOrganizationApiKeyQuery getOrganizationApiKeyQuery ,
2022-05-10 17:12:09 -04:00
IRotateOrganizationApiKeyCommand rotateOrganizationApiKeyCommand ,
2022-11-28 17:39:09 -07:00
ICreateOrganizationApiKeyCommand createOrganizationApiKeyCommand ,
2022-05-10 17:12:09 -04:00
IOrganizationApiKeyRepository organizationApiKeyRepository ,
2023-05-10 12:52:08 -07:00
IFeatureService featureService ,
2023-05-15 07:38:41 -07:00
GlobalSettings globalSettings ,
2024-04-19 10:09:18 -04:00
IProviderRepository providerRepository ,
2024-05-23 10:17:00 -04:00
IProviderBillingService providerBillingService ,
2024-10-16 10:33:00 +01:00
IDataProtectorTokenFactory < OrgDeleteTokenable > orgDeleteTokenDataFactory ,
2024-12-05 21:18:02 -06:00
IRemoveOrganizationUserCommand removeOrganizationUserCommand ,
2025-01-27 10:58:08 +00:00
ICloudOrganizationSignUpCommand cloudOrganizationSignUpCommand ,
2025-02-27 07:55:46 -05:00
IOrganizationDeleteCommand organizationDeleteCommand ,
2025-03-21 10:07:55 -04:00
IPolicyRequirementQuery policyRequirementQuery ,
2025-04-09 15:23:29 +01:00
IPricingClient pricingClient ,
IOrganizationUpdateKeysCommand organizationUpdateKeysCommand )
2022-08-29 16:06:55 -04:00
{
2017-03-03 21:53:27 -05:00
_organizationRepository = organizationRepository ;
_organizationUserRepository = organizationUserRepository ;
2017-04-06 13:21:26 -04:00
_policyRepository = policyRepository ;
_organizationService = organizationService ;
2017-03-02 00:15:05 -05:00
_userService = userService ;
2017-04-06 13:21:26 -04:00
_currentContext = currentContext ;
2021-10-06 10:39:13 +02:00
_ssoConfigRepository = ssoConfigRepository ;
_ssoConfigService = ssoConfigService ;
2022-11-28 17:39:09 -07:00
_getOrganizationApiKeyQuery = getOrganizationApiKeyQuery ;
2017-04-06 13:21:26 -04:00
_rotateOrganizationApiKeyCommand = rotateOrganizationApiKeyCommand ;
2022-11-28 17:39:09 -07:00
_createOrganizationApiKeyCommand = createOrganizationApiKeyCommand ;
2022-05-10 17:12:09 -04:00
_organizationApiKeyRepository = organizationApiKeyRepository ;
2023-05-10 12:52:08 -07:00
_featureService = featureService ;
2017-08-14 22:05:37 -04:00
_globalSettings = globalSettings ;
2024-04-19 10:09:18 -04:00
_providerRepository = providerRepository ;
2024-05-23 10:17:00 -04:00
_providerBillingService = providerBillingService ;
2024-05-22 12:59:19 -04:00
_orgDeleteTokenDataFactory = orgDeleteTokenDataFactory ;
2024-10-16 10:33:00 +01:00
_removeOrganizationUserCommand = removeOrganizationUserCommand ;
2024-12-05 21:18:02 -06:00
_cloudOrganizationSignUpCommand = cloudOrganizationSignUpCommand ;
2025-01-27 10:58:08 +00:00
_organizationDeleteCommand = organizationDeleteCommand ;
2025-03-21 10:07:55 -04:00
_policyRequirementQuery = policyRequirementQuery ;
2025-02-27 07:55:46 -05:00
_pricingClient = pricingClient ;
2025-04-09 15:23:29 +01:00
_organizationUpdateKeysCommand = organizationUpdateKeysCommand ;
2022-08-29 15:53:48 -04:00
}
2017-03-02 00:15:05 -05:00
[HttpGet("{id}")]
2017-04-06 13:21:26 -04:00
public async Task < OrganizationResponseModel > Get ( string id )
2022-08-29 16:06:55 -04:00
{
2017-04-06 13:21:26 -04:00
var orgIdGuid = new Guid ( id ) ;
if ( ! await _currentContext . OrganizationOwner ( orgIdGuid ) )
2022-08-29 16:06:55 -04:00
{
2017-04-06 13:21:26 -04:00
throw new NotFoundException ( ) ;
2017-03-03 21:53:27 -05:00
}
2019-02-18 15:40:47 -05:00
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
if ( organization = = null )
2017-04-06 13:21:26 -04:00
{
throw new NotFoundException ( ) ;
}
2025-02-27 07:55:46 -05:00
var plan = await _pricingClient . GetPlan ( organization . PlanType ) ;
return new OrganizationResponseModel ( organization , plan ) ;
2017-04-06 13:21:26 -04:00
}
2021-09-15 12:23:47 -05:00
[HttpGet("")]
public async Task < ListResponseModel < ProfileOrganizationResponseModel > > GetUser ( )
2022-08-29 16:06:55 -04:00
{
2021-09-15 12:23:47 -05:00
var userId = _userService . GetProperUserId ( User ) . Value ;
var organizations = await _organizationUserRepository . GetManyDetailsByUserAsync ( userId ,
OrganizationUserStatusType . Confirmed ) ;
2024-10-17 16:06:32 +01:00
2025-04-08 14:38:44 -05:00
var organizationsClaimingActiveUser = await _userService . GetOrganizationsClaimingUserAsync ( userId ) ;
var organizationIdsClaimingActiveUser = organizationsClaimingActiveUser . Select ( o = > o . Id ) ;
2024-10-17 16:06:32 +01:00
2025-04-08 14:38:44 -05:00
var responses = organizations . Select ( o = > new ProfileOrganizationResponseModel ( o , organizationIdsClaimingActiveUser ) ) ;
2021-09-15 12:23:47 -05:00
return new ListResponseModel < ProfileOrganizationResponseModel > ( responses ) ;
}
[HttpGet("{identifier}/auto-enroll-status")]
public async Task < OrganizationAutoEnrollStatusResponseModel > GetAutoEnrollStatus ( string identifier )
2022-08-29 16:06:55 -04:00
{
2021-09-15 12:23:47 -05:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
if ( user = = null )
2022-08-29 16:06:55 -04:00
{
2021-09-15 12:23:47 -05:00
throw new UnauthorizedAccessException ( ) ;
}
2021-12-16 15:35:09 +01:00
2021-09-15 12:23:47 -05:00
var organization = await _organizationRepository . GetByIdentifierAsync ( identifier ) ;
if ( organization = = null )
2022-08-29 16:06:55 -04:00
{
2021-09-15 12:23:47 -05:00
throw new NotFoundException ( ) ;
}
2017-03-02 00:15:05 -05:00
2017-04-05 16:13:40 -04:00
var organizationUser = await _organizationUserRepository . GetByOrganizationAsync ( organization . Id , user . Id ) ;
if ( organizationUser = = null )
2017-03-02 00:15:05 -05:00
{
2017-06-02 13:17:46 -04:00
throw new NotFoundException ( ) ;
}
2025-03-21 10:07:55 -04:00
if ( _featureService . IsEnabled ( FeatureFlagKeys . PolicyRequirements ) )
{
var resetPasswordPolicyRequirement = await _policyRequirementQuery . GetAsync < ResetPasswordPolicyRequirement > ( user . Id ) ;
return new OrganizationAutoEnrollStatusResponseModel ( organization . Id , resetPasswordPolicyRequirement . AutoEnrollEnabled ( organization . Id ) ) ;
}
var resetPasswordPolicy = await _policyRepository . GetByOrganizationIdTypeAsync ( organization . Id , PolicyType . ResetPassword ) ;
2017-03-03 00:07:11 -05:00
if ( resetPasswordPolicy = = null | | ! resetPasswordPolicy . Enabled | | resetPasswordPolicy . Data = = null )
2022-08-29 16:06:55 -04:00
{
2017-04-05 16:13:40 -04:00
return new OrganizationAutoEnrollStatusResponseModel ( organization . Id , false ) ;
2017-03-02 00:15:05 -05:00
}
2017-08-14 20:57:45 -04:00
var data = JsonSerializer . Deserialize < ResetPasswordDataModel > ( resetPasswordPolicy . Data , JsonHelpers . IgnoreCase ) ;
return new OrganizationAutoEnrollStatusResponseModel ( organization . Id , data ? . AutoEnrollEnabled ? ? false ) ;
2025-03-21 10:07:55 -04:00
2022-08-29 16:06:55 -04:00
}
2017-08-14 20:57:45 -04:00
[HttpPost("")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task < OrganizationResponseModel > Post ( [ FromBody ] OrganizationCreateRequestModel model )
2022-08-29 16:06:55 -04:00
{
2017-08-14 20:57:45 -04:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
2017-06-02 13:17:46 -04:00
if ( user = = null )
2017-08-14 20:57:45 -04:00
{
throw new UnauthorizedAccessException ( ) ;
}
var organizationSignup = model . ToOrganizationSignup ( user ) ;
2024-12-05 21:18:02 -06:00
var result = await _cloudOrganizationSignUpCommand . SignUpOrganizationAsync ( organizationSignup ) ;
2025-02-27 07:55:46 -05:00
var plan = await _pricingClient . GetPlanOrThrow ( result . Organization . PlanType ) ;
return new OrganizationResponseModel ( result . Organization , plan ) ;
2017-08-14 20:57:45 -04:00
}
2024-09-27 19:39:44 +01:00
[HttpPost("create-without-payment")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task < OrganizationResponseModel > CreateWithoutPaymentAsync ( [ FromBody ] OrganizationNoPaymentCreateRequest model )
{
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
if ( user = = null )
{
throw new UnauthorizedAccessException ( ) ;
}
var organizationSignup = model . ToOrganizationSignup ( user ) ;
2024-12-05 21:18:02 -06:00
var result = await _cloudOrganizationSignUpCommand . SignUpOrganizationAsync ( organizationSignup ) ;
2025-02-27 07:55:46 -05:00
var plan = await _pricingClient . GetPlanOrThrow ( result . Organization . PlanType ) ;
return new OrganizationResponseModel ( result . Organization , plan ) ;
2024-09-27 19:39:44 +01:00
}
2017-03-02 00:15:05 -05:00
[HttpPut("{id}")]
2022-05-10 12:19:22 +10:00
[HttpPost("{id}")]
public async Task < OrganizationResponseModel > Put ( string id , [ FromBody ] OrganizationUpdateRequestModel model )
2022-08-29 16:06:55 -04:00
{
2022-05-10 12:19:22 +10:00
var orgIdGuid = new Guid ( id ) ;
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
if ( organization = = null )
2022-08-29 16:06:55 -04:00
{
2022-05-10 12:19:22 +10:00
throw new NotFoundException ( ) ;
2022-08-29 16:06:55 -04:00
}
2022-05-10 12:19:22 +10:00
2024-03-05 10:56:48 +00:00
var updateBilling = ! _globalSettings . SelfHosted & & ( model . BusinessName ! = organization . DisplayBusinessName ( ) | |
[SG-147] Organization Domain Claiming Feature (#2704)
* [SG-696] Organization Domain Claiming DB Objects and Migrations (#2394)
* model organization domain claiming
* Added migration scripts and db objects for mssql
* create and implement sql repository abstraction
* Added ef migrations for mysql and postgres. Removed time without timezone in previous migration
* made update on sql migration to use create or alter statement
* removed active column from OrganizationDomain table and decided to go with the hard delete approach
* Ran dotnet restore evaluate
* created DNS service verification using DNSClient (#2401)
* [SG-678] Api Endpoints for Domain Claiming (#2430)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* changed logic for setting the initial value for the NextRunCount
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Added stored procedure to get organization sso details by email address
* Added endpoint to get sso details of an organization with email
* Added organizationDomainRepository to OrganizationController test
* merged with master and fixed conflicts
* [SG-661] Background Domain Verification Service (#2455)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* Added stored procedure to get unverified domains by nextrundate
* Renamed stored procedure name
* Added domain verification service interface
* Added GetManyByNextRunDate to repository
* Added verification domain service implementation
* changed logic for setting the initial value for the NextRunCount
* This commit should be signed using my SSH key
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Implemented EF core version on the repository
* Created background job implementation and logic
* popped stash
* Updated stored procedure and EF script
* Lint fix
* Added logic to set next job count and the next run date when a verification is false
* Added logic to set next job count and the next run date when a verification is false
* Updated stored procedure name on repository
* Removed test trigger
* Lint fix
* Added trigger for job
* Added job count update after successful domain verification
* Lint fix
* Lint fix
* [SG-682] Add Event Log Entries to Organization Domain (#2492)
* Added domain name property to Event related objects
* Added organization domain claiming event types
* Created migration script and updated related event scripts to include domanName
* Added EF Migrations
* Renamed postres script file extension
* Added DomainName property to response model
* Added abstraction to interface
* Added system name to enum
* dotnet formattinfg fix
* Added events to organization domain actions
* Added LastCheckedDate property to domain
* Migrations and stored procedure updates with new column
* Added new stored procedure to get domain by org id and domain name
* Log organization domain event abstract method
* Ef migrattion to add new LastCheckedDate column
* Added duplicate domain exception
* Modified create command to include domain verification and last checked date and renamed methods used
* removed variable
* changed service lifetime
* Renamed trigger
* Initialed property in constructor
* Ensured domain name is stored as lower case
* Fixed suggestions from review
* Fixed suggestions from review
* Return Conflict Status on Organization Domain APIs (#2498)
* Added conflict response to end point to help translate error message on the client better
* Added conflict response to end point to help translate error message on the client better
* Set message with exception message or generic message
* Added last check date to response model (#2499)
* Fix/Check to throw exception when domain is claimed by another organization (#2503)
* Added check to ensure domain claimed by another organization cannot be verified
* Made error message consistent
* [SG-660] Organization Domain Maintenance (#2502)
* Added email template
* Mail service abstraction and implementation
* Mail template model
* Initial delete job commit
* Added SPs to get all unverifed domains after 72 hours and another to delete unverified domains after 7 days
* Moved all organization domain scripts to single file
* Added new scripts implementation for sqlserver and EF core
* Renamed service
* Formatting fix
* Added background service to send warning email and delete expired domains
* Renamed variable
* Added implementation for email warning to organization admins and for deleting expired domains after 7 days
* Added formatting
* Modified read if expired script to limit result to 4 days
* Added send mail abstract method and implementation
* Model used in build mail body
* Completed maintenace service
* Added comment to make logic clear
* Fixed cron expression (#2505)
* Modified procedure and methods to handle flexible verification adn expiration period (#2517)
* Merged with master
* [SG-908] Unit Tests for Organization Domain Claiming Feature (#2522)
* added test controlleer class
* added unit test for create command
* Added query tests
* Added tests for delete and verify command
* Formated code and added some more unit tests
* Fixed lint
* Added log event assertion to create command tests
* Added log event assertion to delete command tests
* Added unit tests for organization domain controller
* Added unit tests for organization domain service
* Modified test after merge
* fixed comment
* fixed comment
* fixed lint
* Defect/SG-977 - Org domain event logs missing details (#2573)
* SG-977 - (1) Refactor EventSystemUser.SSO to be EventSystemUser.DomainVerification to better match SCIM property and for easier display and translation on web client (2) Add new DeviceType of Server to be used on SCIM and Domain Verification logs so event log will show Server as client.
* SG-977 - SCIM bugfix - Restoring / Revoking user access via Jumpcloud activation / suspension did not properly log the events as SCIM events so the client side showed Unknown for both Client and Member.
* Run autoformat to fix lint errors
* SG-977 - Fixed broken test due to new device type logic in event service
* SG-976 - Add admin log and clean up log verbiage for domain verification (#2574)
* SG-976 - Add admin log and clean up log verbiage for domain verification
* SG-976 - (1) Use logInformation extension without exception (2) Clarify verbiage of logs
* SG-955 - On domain verification error or failure, set last checked da… (#2541)
* SG-955 - On domain verification error or failure, set last checked date on the org domain.
* SG-955 - Refactoring VerifyOrganizationDomain event logging to avoid duplication and increase efficiency (based on Gbubemi's PR feedback)
* Org Domain Background Verification service - set last checked date (#2599)
* Refactored OrganizationDomain repository to work with latest changes on code base
* Fixed formatting
* [SG-957] Cannot Delete Organizations due to FK Constraint (#2602)
* Added stored procedure to fix FX contstraint issue when deleting an organization
* Update stored procedures related to organization delete with OrganizationDomain_OrganizationDelete SP
* Fixed formatting
* Updated SP
* SG-990 - Log expired domains that are going to be deleted.
* Fix lint errors with auto format
* /home/runner/work/server/server/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs(107,2): error FINALNEWLINE: Fix final newline. Insert '\n'.
* Added missing bracket to fix compile error.
* Added imports for Domain Claiming classes that were lost on merge.
* Fixing broken unit tests + adding proper behavior for newly added SCIM logic changing device type
* Fix lint errors again
* Included domain name set in constructor (#2618)
* [SG-1001] Error Thrown When Verifying Sub Domains (#2621)
* Renamed exception to a more generic name that receives error message from the dns client and also added updates to job count and next run date
* Improved error logs by adding dns client error message
* Fixed formatting
* [SG-1001] Added event logs when a domain is not verified due to thrown exception (#2623)
* Added eevent logs when a domain is not verified due to thrown exception
* Fixed formatting
* Org Domain Verification - Small refactor to improve method/model name… (#2641)
* Org Domain Verification - Small refactor to improve method/model names and method locations - required refactoring of controller routes (I confirmed all behavior still functional)
* Fixed organization test controller issue
* Fixed lint
* Autoformat org domain controller
* Removing whitespace for lint argh, why does Rider not do this.
---------
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
* Tweak name of Request model to match Response model for ClaimedOrgDomain call
* [SG-1009] Users with Custom Role and "Manage SSO" permission don't receive verification failed email (#2645)
* Modified condition to pick up unverified domains after said period
* Fix to get emails of custom users with manage sso rights
* Formatted code
* Removed return that made background job exit on successful validation (#2648)
* [SG-1014] Unit Tests for Get Organization Sso Details (#2655)
* Added unit tests for GetOrgDomainSsoDetails
* renamed variable
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so … (#2657)
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so that claimed domain results will come back if an org has not yet setup a policy
* Removed migration as not needed
* Updated OrganizationDomainSsoDetails_ReadByEmail from original creation migration to use outer join & handle null policy results (and still return results)
* Fixed lint formatting
---------
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Jared Snider <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2023-02-15 14:26:41 -05:00
model . BillingEmail ! = organization . BillingEmail ) ;
2017-03-02 00:15:05 -05:00
2018-07-16 17:20:57 -04:00
var hasRequiredPermissions = updateBilling
2023-04-14 11:13:16 +01:00
? await _currentContext . EditSubscription ( orgIdGuid )
2017-04-08 16:41:40 -04:00
: await _currentContext . OrganizationOwner ( orgIdGuid ) ;
2020-06-17 20:02:38 -04:00
2019-08-09 23:56:26 -04:00
if ( ! hasRequiredPermissions )
2022-08-29 14:53:16 -04:00
{
2019-08-09 23:56:26 -04:00
throw new NotFoundException ( ) ;
2017-04-10 11:49:53 -04:00
}
2018-09-13 16:03:04 -04:00
2021-09-23 06:36:08 -04:00
await _organizationService . UpdateAsync ( model . ToOrganization ( organization , _globalSettings ) , updateBilling ) ;
2025-02-27 07:55:46 -05:00
var plan = await _pricingClient . GetPlan ( organization . PlanType ) ;
return new OrganizationResponseModel ( organization , plan ) ;
2021-09-23 06:36:08 -04:00
}
2018-12-31 13:34:02 -05:00
[HttpPost("{id}/storage")]
[SelfHosted(NotSelfHostedOnly = true)]
public async Task < PaymentResponseModel > PostStorage ( string id , [ FromBody ] StorageRequestModel model )
2022-08-29 16:06:55 -04:00
{
2018-12-31 13:34:02 -05:00
var orgIdGuid = new Guid ( id ) ;
2023-04-14 11:13:16 +01:00
if ( ! await _currentContext . EditSubscription ( orgIdGuid ) )
2022-08-29 16:06:55 -04:00
{
2018-12-31 13:34:02 -05:00
throw new NotFoundException ( ) ;
2017-04-10 11:49:53 -04:00
}
2018-09-13 16:03:04 -04:00
2017-04-10 18:20:21 -04:00
var result = await _organizationService . AdjustStorageAsync ( orgIdGuid , model . StorageGbAdjustment . Value ) ;
[SG-147] Organization Domain Claiming Feature (#2704)
* [SG-696] Organization Domain Claiming DB Objects and Migrations (#2394)
* model organization domain claiming
* Added migration scripts and db objects for mssql
* create and implement sql repository abstraction
* Added ef migrations for mysql and postgres. Removed time without timezone in previous migration
* made update on sql migration to use create or alter statement
* removed active column from OrganizationDomain table and decided to go with the hard delete approach
* Ran dotnet restore evaluate
* created DNS service verification using DNSClient (#2401)
* [SG-678] Api Endpoints for Domain Claiming (#2430)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* changed logic for setting the initial value for the NextRunCount
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Added stored procedure to get organization sso details by email address
* Added endpoint to get sso details of an organization with email
* Added organizationDomainRepository to OrganizationController test
* merged with master and fixed conflicts
* [SG-661] Background Domain Verification Service (#2455)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* Added stored procedure to get unverified domains by nextrundate
* Renamed stored procedure name
* Added domain verification service interface
* Added GetManyByNextRunDate to repository
* Added verification domain service implementation
* changed logic for setting the initial value for the NextRunCount
* This commit should be signed using my SSH key
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Implemented EF core version on the repository
* Created background job implementation and logic
* popped stash
* Updated stored procedure and EF script
* Lint fix
* Added logic to set next job count and the next run date when a verification is false
* Added logic to set next job count and the next run date when a verification is false
* Updated stored procedure name on repository
* Removed test trigger
* Lint fix
* Added trigger for job
* Added job count update after successful domain verification
* Lint fix
* Lint fix
* [SG-682] Add Event Log Entries to Organization Domain (#2492)
* Added domain name property to Event related objects
* Added organization domain claiming event types
* Created migration script and updated related event scripts to include domanName
* Added EF Migrations
* Renamed postres script file extension
* Added DomainName property to response model
* Added abstraction to interface
* Added system name to enum
* dotnet formattinfg fix
* Added events to organization domain actions
* Added LastCheckedDate property to domain
* Migrations and stored procedure updates with new column
* Added new stored procedure to get domain by org id and domain name
* Log organization domain event abstract method
* Ef migrattion to add new LastCheckedDate column
* Added duplicate domain exception
* Modified create command to include domain verification and last checked date and renamed methods used
* removed variable
* changed service lifetime
* Renamed trigger
* Initialed property in constructor
* Ensured domain name is stored as lower case
* Fixed suggestions from review
* Fixed suggestions from review
* Return Conflict Status on Organization Domain APIs (#2498)
* Added conflict response to end point to help translate error message on the client better
* Added conflict response to end point to help translate error message on the client better
* Set message with exception message or generic message
* Added last check date to response model (#2499)
* Fix/Check to throw exception when domain is claimed by another organization (#2503)
* Added check to ensure domain claimed by another organization cannot be verified
* Made error message consistent
* [SG-660] Organization Domain Maintenance (#2502)
* Added email template
* Mail service abstraction and implementation
* Mail template model
* Initial delete job commit
* Added SPs to get all unverifed domains after 72 hours and another to delete unverified domains after 7 days
* Moved all organization domain scripts to single file
* Added new scripts implementation for sqlserver and EF core
* Renamed service
* Formatting fix
* Added background service to send warning email and delete expired domains
* Renamed variable
* Added implementation for email warning to organization admins and for deleting expired domains after 7 days
* Added formatting
* Modified read if expired script to limit result to 4 days
* Added send mail abstract method and implementation
* Model used in build mail body
* Completed maintenace service
* Added comment to make logic clear
* Fixed cron expression (#2505)
* Modified procedure and methods to handle flexible verification adn expiration period (#2517)
* Merged with master
* [SG-908] Unit Tests for Organization Domain Claiming Feature (#2522)
* added test controlleer class
* added unit test for create command
* Added query tests
* Added tests for delete and verify command
* Formated code and added some more unit tests
* Fixed lint
* Added log event assertion to create command tests
* Added log event assertion to delete command tests
* Added unit tests for organization domain controller
* Added unit tests for organization domain service
* Modified test after merge
* fixed comment
* fixed comment
* fixed lint
* Defect/SG-977 - Org domain event logs missing details (#2573)
* SG-977 - (1) Refactor EventSystemUser.SSO to be EventSystemUser.DomainVerification to better match SCIM property and for easier display and translation on web client (2) Add new DeviceType of Server to be used on SCIM and Domain Verification logs so event log will show Server as client.
* SG-977 - SCIM bugfix - Restoring / Revoking user access via Jumpcloud activation / suspension did not properly log the events as SCIM events so the client side showed Unknown for both Client and Member.
* Run autoformat to fix lint errors
* SG-977 - Fixed broken test due to new device type logic in event service
* SG-976 - Add admin log and clean up log verbiage for domain verification (#2574)
* SG-976 - Add admin log and clean up log verbiage for domain verification
* SG-976 - (1) Use logInformation extension without exception (2) Clarify verbiage of logs
* SG-955 - On domain verification error or failure, set last checked da… (#2541)
* SG-955 - On domain verification error or failure, set last checked date on the org domain.
* SG-955 - Refactoring VerifyOrganizationDomain event logging to avoid duplication and increase efficiency (based on Gbubemi's PR feedback)
* Org Domain Background Verification service - set last checked date (#2599)
* Refactored OrganizationDomain repository to work with latest changes on code base
* Fixed formatting
* [SG-957] Cannot Delete Organizations due to FK Constraint (#2602)
* Added stored procedure to fix FX contstraint issue when deleting an organization
* Update stored procedures related to organization delete with OrganizationDomain_OrganizationDelete SP
* Fixed formatting
* Updated SP
* SG-990 - Log expired domains that are going to be deleted.
* Fix lint errors with auto format
* /home/runner/work/server/server/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs(107,2): error FINALNEWLINE: Fix final newline. Insert '\n'.
* Added missing bracket to fix compile error.
* Added imports for Domain Claiming classes that were lost on merge.
* Fixing broken unit tests + adding proper behavior for newly added SCIM logic changing device type
* Fix lint errors again
* Included domain name set in constructor (#2618)
* [SG-1001] Error Thrown When Verifying Sub Domains (#2621)
* Renamed exception to a more generic name that receives error message from the dns client and also added updates to job count and next run date
* Improved error logs by adding dns client error message
* Fixed formatting
* [SG-1001] Added event logs when a domain is not verified due to thrown exception (#2623)
* Added eevent logs when a domain is not verified due to thrown exception
* Fixed formatting
* Org Domain Verification - Small refactor to improve method/model name… (#2641)
* Org Domain Verification - Small refactor to improve method/model names and method locations - required refactoring of controller routes (I confirmed all behavior still functional)
* Fixed organization test controller issue
* Fixed lint
* Autoformat org domain controller
* Removing whitespace for lint argh, why does Rider not do this.
---------
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
* Tweak name of Request model to match Response model for ClaimedOrgDomain call
* [SG-1009] Users with Custom Role and "Manage SSO" permission don't receive verification failed email (#2645)
* Modified condition to pick up unverified domains after said period
* Fix to get emails of custom users with manage sso rights
* Formatted code
* Removed return that made background job exit on successful validation (#2648)
* [SG-1014] Unit Tests for Get Organization Sso Details (#2655)
* Added unit tests for GetOrgDomainSsoDetails
* renamed variable
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so … (#2657)
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so that claimed domain results will come back if an org has not yet setup a policy
* Removed migration as not needed
* Updated OrganizationDomainSsoDetails_ReadByEmail from original creation migration to use outer join & handle null policy results (and still return results)
* Fixed lint formatting
---------
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Jared Snider <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2023-02-15 14:26:41 -05:00
return new PaymentResponseModel { Success = true , PaymentIntentClientSecret = result } ;
2022-08-29 14:53:16 -04:00
}
2017-04-06 13:21:26 -04:00
[HttpPost("{id}/leave")]
2024-10-16 10:33:00 +01:00
public async Task Leave ( Guid id )
2022-08-29 16:06:55 -04:00
{
2024-10-16 10:33:00 +01:00
if ( ! await _currentContext . OrganizationUser ( id ) )
2022-08-29 15:53:48 -04:00
{
2017-04-06 13:21:26 -04:00
throw new NotFoundException ( ) ;
2017-03-02 00:15:05 -05:00
}
2017-08-14 22:05:37 -04:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
2017-06-02 13:17:46 -04:00
2024-10-16 10:33:00 +01:00
var ssoConfig = await _ssoConfigRepository . GetByOrganizationIdAsync ( id ) ;
2023-05-10 12:52:08 -07:00
if ( ssoConfig ? . GetData ( ) ? . MemberDecryptionType = = MemberDecryptionType . KeyConnector & & user . UsesKeyConnector )
2022-08-29 16:06:55 -04:00
{
2017-04-11 10:52:28 -04:00
throw new BadRequestException ( "Your organization's Single Sign-On settings prevent you from leaving." ) ;
2017-03-02 00:15:05 -05:00
}
2018-09-13 16:03:04 -04:00
2025-05-13 07:17:54 +10:00
if ( ( await _userService . GetOrganizationsClaimingUserAsync ( user . Id ) ) . Any ( x = > x . Id = = id ) )
2024-11-07 14:10:00 -05:00
{
2025-04-08 14:38:44 -05:00
throw new BadRequestException ( "Claimed user account cannot leave claiming organization. Contact your organization administrator for additional details." ) ;
2024-11-07 14:10:00 -05:00
}
2024-12-10 11:14:34 +00:00
await _removeOrganizationUserCommand . UserLeaveAsync ( id , user . Id ) ;
2022-08-29 14:53:16 -04:00
}
2017-08-14 21:25:06 -04:00
2017-03-02 00:15:05 -05:00
[HttpDelete("{id}")]
[HttpPost("{id}/delete")]
2017-08-14 22:05:37 -04:00
public async Task Delete ( string id , [ FromBody ] SecretVerificationRequestModel model )
2022-08-29 16:06:55 -04:00
{
2017-08-14 22:05:37 -04:00
var orgIdGuid = new Guid ( id ) ;
if ( ! await _currentContext . OrganizationOwner ( orgIdGuid ) )
2022-08-29 14:53:16 -04:00
{
2017-05-13 12:00:40 -04:00
throw new NotFoundException ( ) ;
2022-08-29 15:53:48 -04:00
}
2017-05-13 12:00:40 -04:00
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
2020-03-27 14:36:37 -04:00
if ( organization = = null )
2022-08-29 16:06:55 -04:00
{
2017-05-13 12:00:40 -04:00
throw new NotFoundException ( ) ;
2017-08-14 21:25:06 -04:00
}
2017-05-13 17:08:56 -04:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
if ( user = = null )
2017-05-13 12:00:40 -04:00
{
2017-10-09 16:58:37 -04:00
throw new UnauthorizedAccessException ( ) ;
}
2021-07-08 17:05:32 +02:00
if ( ! await _userService . VerifySecretAsync ( user , model . Secret ) )
2022-08-29 16:06:55 -04:00
{
2021-07-08 17:05:32 +02:00
await Task . Delay ( 2000 ) ;
throw new BadRequestException ( string . Empty , "User verification failed." ) ;
2022-08-29 16:06:55 -04:00
}
2024-04-19 10:09:18 -04:00
2024-11-15 09:30:03 -05:00
if ( organization . IsValidClient ( ) )
2022-08-29 16:06:55 -04:00
{
2024-04-19 10:09:18 -04:00
var provider = await _providerRepository . GetByOrganizationIdAsync ( organization . Id ) ;
if ( provider . IsBillable ( ) )
{
2024-05-23 10:17:00 -04:00
await _providerBillingService . ScaleSeats (
2024-04-19 10:09:18 -04:00
provider ,
organization . PlanType ,
- organization . Seats ? ? 0 ) ;
}
2017-05-13 12:00:40 -04:00
}
2024-04-19 10:09:18 -04:00
2025-01-27 10:58:08 +00:00
await _organizationDeleteCommand . DeleteAsync ( organization ) ;
2022-08-29 16:06:55 -04:00
}
2017-05-13 12:00:40 -04:00
2024-05-22 12:59:19 -04:00
[HttpPost("{id}/delete-recover-token")]
[AllowAnonymous]
public async Task PostDeleteRecoverToken ( Guid id , [ FromBody ] OrganizationVerifyDeleteRecoverRequestModel model )
{
var organization = await _organizationRepository . GetByIdAsync ( id ) ;
if ( organization = = null )
{
throw new NotFoundException ( ) ;
}
if ( ! _orgDeleteTokenDataFactory . TryUnprotect ( model . Token , out var data ) | | ! data . IsValid ( organization ) )
{
throw new BadRequestException ( "Invalid token." ) ;
}
2024-11-15 09:30:03 -05:00
if ( organization . IsValidClient ( ) )
2024-05-22 12:59:19 -04:00
{
var provider = await _providerRepository . GetByOrganizationIdAsync ( organization . Id ) ;
if ( provider . IsBillable ( ) )
{
2024-05-23 10:17:00 -04:00
await _providerBillingService . ScaleSeats (
2024-05-22 12:59:19 -04:00
provider ,
organization . PlanType ,
- organization . Seats ? ? 0 ) ;
}
}
2025-01-27 10:58:08 +00:00
await _organizationDeleteCommand . DeleteAsync ( organization ) ;
2024-05-22 12:59:19 -04:00
}
2022-05-10 17:12:09 -04:00
[HttpPost("{id}/api-key")]
public async Task < ApiKeyResponseModel > ApiKey ( string id , [ FromBody ] OrganizationApiKeyRequestModel model )
2022-08-29 16:06:55 -04:00
{
2022-05-10 17:12:09 -04:00
var orgIdGuid = new Guid ( id ) ;
if ( ! await HasApiKeyAccessAsync ( orgIdGuid , model . Type ) )
2019-03-04 09:52:43 -05:00
{
throw new NotFoundException ( ) ;
}
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
2022-07-14 15:58:48 -04:00
if ( organization = = null )
2022-08-29 16:06:55 -04:00
{
2019-03-04 09:52:43 -05:00
throw new NotFoundException ( ) ;
}
2022-05-10 17:12:09 -04:00
if ( model . Type = = OrganizationApiKeyType . BillingSync | | model . Type = = OrganizationApiKeyType . Scim )
2022-08-29 15:53:48 -04:00
{
2022-05-10 17:12:09 -04:00
// Non-enterprise orgs should not be able to create or view an apikey of billing sync/scim key types
2025-02-27 07:55:46 -05:00
var productTier = organization . PlanType . GetProductTier ( ) ;
if ( productTier is not ProductTierType . Enterprise and not ProductTierType . Teams )
2022-08-29 15:53:48 -04:00
{
2022-05-10 17:12:09 -04:00
throw new NotFoundException ( ) ;
2022-08-29 15:53:48 -04:00
}
2022-08-29 16:06:55 -04:00
}
2022-05-10 17:12:09 -04:00
2022-11-28 17:39:09 -07:00
var organizationApiKey = await _getOrganizationApiKeyQuery
. GetOrganizationApiKeyAsync ( organization . Id , model . Type ) ? ?
await _createOrganizationApiKeyCommand . CreateAsync ( organization . Id , model . Type ) ;
2019-03-04 09:52:43 -05:00
2022-05-10 17:12:09 -04:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
if ( user = = null )
2022-08-29 16:06:55 -04:00
{
2022-05-10 17:12:09 -04:00
throw new UnauthorizedAccessException ( ) ;
2019-03-04 09:52:43 -05:00
}
2020-08-11 14:19:56 -04:00
2022-07-14 15:58:48 -04:00
if ( model . Type ! = OrganizationApiKeyType . Scim
& & ! await _userService . VerifySecretAsync ( user , model . Secret ) )
{
2022-05-10 17:12:09 -04:00
await Task . Delay ( 2000 ) ;
2022-07-14 15:58:48 -04:00
throw new BadRequestException ( "MasterPasswordHash" , "Invalid password." ) ;
2022-08-29 16:06:55 -04:00
}
else
{
2022-07-14 15:58:48 -04:00
var response = new ApiKeyResponseModel ( organizationApiKey ) ;
2019-03-04 09:52:43 -05:00
return response ;
2022-08-29 15:53:48 -04:00
}
2022-08-29 16:06:55 -04:00
}
2022-08-29 15:53:48 -04:00
2020-06-08 17:40:18 -04:00
[HttpGet("{id}/api-key-information/{type?}")]
[SG-147] Organization Domain Claiming Feature (#2704)
* [SG-696] Organization Domain Claiming DB Objects and Migrations (#2394)
* model organization domain claiming
* Added migration scripts and db objects for mssql
* create and implement sql repository abstraction
* Added ef migrations for mysql and postgres. Removed time without timezone in previous migration
* made update on sql migration to use create or alter statement
* removed active column from OrganizationDomain table and decided to go with the hard delete approach
* Ran dotnet restore evaluate
* created DNS service verification using DNSClient (#2401)
* [SG-678] Api Endpoints for Domain Claiming (#2430)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* changed logic for setting the initial value for the NextRunCount
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Added stored procedure to get organization sso details by email address
* Added endpoint to get sso details of an organization with email
* Added organizationDomainRepository to OrganizationController test
* merged with master and fixed conflicts
* [SG-661] Background Domain Verification Service (#2455)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* Added stored procedure to get unverified domains by nextrundate
* Renamed stored procedure name
* Added domain verification service interface
* Added GetManyByNextRunDate to repository
* Added verification domain service implementation
* changed logic for setting the initial value for the NextRunCount
* This commit should be signed using my SSH key
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Implemented EF core version on the repository
* Created background job implementation and logic
* popped stash
* Updated stored procedure and EF script
* Lint fix
* Added logic to set next job count and the next run date when a verification is false
* Added logic to set next job count and the next run date when a verification is false
* Updated stored procedure name on repository
* Removed test trigger
* Lint fix
* Added trigger for job
* Added job count update after successful domain verification
* Lint fix
* Lint fix
* [SG-682] Add Event Log Entries to Organization Domain (#2492)
* Added domain name property to Event related objects
* Added organization domain claiming event types
* Created migration script and updated related event scripts to include domanName
* Added EF Migrations
* Renamed postres script file extension
* Added DomainName property to response model
* Added abstraction to interface
* Added system name to enum
* dotnet formattinfg fix
* Added events to organization domain actions
* Added LastCheckedDate property to domain
* Migrations and stored procedure updates with new column
* Added new stored procedure to get domain by org id and domain name
* Log organization domain event abstract method
* Ef migrattion to add new LastCheckedDate column
* Added duplicate domain exception
* Modified create command to include domain verification and last checked date and renamed methods used
* removed variable
* changed service lifetime
* Renamed trigger
* Initialed property in constructor
* Ensured domain name is stored as lower case
* Fixed suggestions from review
* Fixed suggestions from review
* Return Conflict Status on Organization Domain APIs (#2498)
* Added conflict response to end point to help translate error message on the client better
* Added conflict response to end point to help translate error message on the client better
* Set message with exception message or generic message
* Added last check date to response model (#2499)
* Fix/Check to throw exception when domain is claimed by another organization (#2503)
* Added check to ensure domain claimed by another organization cannot be verified
* Made error message consistent
* [SG-660] Organization Domain Maintenance (#2502)
* Added email template
* Mail service abstraction and implementation
* Mail template model
* Initial delete job commit
* Added SPs to get all unverifed domains after 72 hours and another to delete unverified domains after 7 days
* Moved all organization domain scripts to single file
* Added new scripts implementation for sqlserver and EF core
* Renamed service
* Formatting fix
* Added background service to send warning email and delete expired domains
* Renamed variable
* Added implementation for email warning to organization admins and for deleting expired domains after 7 days
* Added formatting
* Modified read if expired script to limit result to 4 days
* Added send mail abstract method and implementation
* Model used in build mail body
* Completed maintenace service
* Added comment to make logic clear
* Fixed cron expression (#2505)
* Modified procedure and methods to handle flexible verification adn expiration period (#2517)
* Merged with master
* [SG-908] Unit Tests for Organization Domain Claiming Feature (#2522)
* added test controlleer class
* added unit test for create command
* Added query tests
* Added tests for delete and verify command
* Formated code and added some more unit tests
* Fixed lint
* Added log event assertion to create command tests
* Added log event assertion to delete command tests
* Added unit tests for organization domain controller
* Added unit tests for organization domain service
* Modified test after merge
* fixed comment
* fixed comment
* fixed lint
* Defect/SG-977 - Org domain event logs missing details (#2573)
* SG-977 - (1) Refactor EventSystemUser.SSO to be EventSystemUser.DomainVerification to better match SCIM property and for easier display and translation on web client (2) Add new DeviceType of Server to be used on SCIM and Domain Verification logs so event log will show Server as client.
* SG-977 - SCIM bugfix - Restoring / Revoking user access via Jumpcloud activation / suspension did not properly log the events as SCIM events so the client side showed Unknown for both Client and Member.
* Run autoformat to fix lint errors
* SG-977 - Fixed broken test due to new device type logic in event service
* SG-976 - Add admin log and clean up log verbiage for domain verification (#2574)
* SG-976 - Add admin log and clean up log verbiage for domain verification
* SG-976 - (1) Use logInformation extension without exception (2) Clarify verbiage of logs
* SG-955 - On domain verification error or failure, set last checked da… (#2541)
* SG-955 - On domain verification error or failure, set last checked date on the org domain.
* SG-955 - Refactoring VerifyOrganizationDomain event logging to avoid duplication and increase efficiency (based on Gbubemi's PR feedback)
* Org Domain Background Verification service - set last checked date (#2599)
* Refactored OrganizationDomain repository to work with latest changes on code base
* Fixed formatting
* [SG-957] Cannot Delete Organizations due to FK Constraint (#2602)
* Added stored procedure to fix FX contstraint issue when deleting an organization
* Update stored procedures related to organization delete with OrganizationDomain_OrganizationDelete SP
* Fixed formatting
* Updated SP
* SG-990 - Log expired domains that are going to be deleted.
* Fix lint errors with auto format
* /home/runner/work/server/server/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs(107,2): error FINALNEWLINE: Fix final newline. Insert '\n'.
* Added missing bracket to fix compile error.
* Added imports for Domain Claiming classes that were lost on merge.
* Fixing broken unit tests + adding proper behavior for newly added SCIM logic changing device type
* Fix lint errors again
* Included domain name set in constructor (#2618)
* [SG-1001] Error Thrown When Verifying Sub Domains (#2621)
* Renamed exception to a more generic name that receives error message from the dns client and also added updates to job count and next run date
* Improved error logs by adding dns client error message
* Fixed formatting
* [SG-1001] Added event logs when a domain is not verified due to thrown exception (#2623)
* Added eevent logs when a domain is not verified due to thrown exception
* Fixed formatting
* Org Domain Verification - Small refactor to improve method/model name… (#2641)
* Org Domain Verification - Small refactor to improve method/model names and method locations - required refactoring of controller routes (I confirmed all behavior still functional)
* Fixed organization test controller issue
* Fixed lint
* Autoformat org domain controller
* Removing whitespace for lint argh, why does Rider not do this.
---------
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
* Tweak name of Request model to match Response model for ClaimedOrgDomain call
* [SG-1009] Users with Custom Role and "Manage SSO" permission don't receive verification failed email (#2645)
* Modified condition to pick up unverified domains after said period
* Fix to get emails of custom users with manage sso rights
* Formatted code
* Removed return that made background job exit on successful validation (#2648)
* [SG-1014] Unit Tests for Get Organization Sso Details (#2655)
* Added unit tests for GetOrgDomainSsoDetails
* renamed variable
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so … (#2657)
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so that claimed domain results will come back if an org has not yet setup a policy
* Removed migration as not needed
* Updated OrganizationDomainSsoDetails_ReadByEmail from original creation migration to use outer join & handle null policy results (and still return results)
* Fixed lint formatting
---------
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Jared Snider <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2023-02-15 14:26:41 -05:00
public async Task < ListResponseModel < OrganizationApiKeyInformation > > ApiKeyInformation ( Guid id ,
[FromRoute] OrganizationApiKeyType ? type )
2022-08-29 16:06:55 -04:00
{
2020-06-08 17:40:18 -04:00
if ( ! await HasApiKeyAccessAsync ( id , type ) )
2022-08-29 15:53:48 -04:00
{
2022-05-10 17:12:09 -04:00
throw new NotFoundException ( ) ;
2022-07-14 15:58:48 -04:00
}
2021-07-08 17:05:32 +02:00
var apiKeys = await _organizationApiKeyRepository . GetManyByOrganizationIdTypeAsync ( id , type ) ;
2020-06-08 17:40:18 -04:00
return new ListResponseModel < OrganizationApiKeyInformation > (
apiKeys . Select ( k = > new OrganizationApiKeyInformation ( k ) ) ) ;
}
[HttpPost("{id}/rotate-api-key")]
2022-05-10 17:12:09 -04:00
public async Task < ApiKeyResponseModel > RotateApiKey ( string id , [ FromBody ] OrganizationApiKeyRequestModel model )
2022-08-29 16:06:55 -04:00
{
2020-12-01 16:43:07 -05:00
var orgIdGuid = new Guid ( id ) ;
if ( ! await HasApiKeyAccessAsync ( orgIdGuid , model . Type ) )
2022-08-29 16:06:55 -04:00
{
2020-12-01 16:43:07 -05:00
throw new NotFoundException ( ) ;
2022-08-29 14:53:16 -04:00
}
2020-06-08 17:40:18 -04:00
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
if ( organization = = null )
{
throw new NotFoundException ( ) ;
}
2022-11-28 17:39:09 -07:00
var organizationApiKey = await _getOrganizationApiKeyQuery
[SG-147] Organization Domain Claiming Feature (#2704)
* [SG-696] Organization Domain Claiming DB Objects and Migrations (#2394)
* model organization domain claiming
* Added migration scripts and db objects for mssql
* create and implement sql repository abstraction
* Added ef migrations for mysql and postgres. Removed time without timezone in previous migration
* made update on sql migration to use create or alter statement
* removed active column from OrganizationDomain table and decided to go with the hard delete approach
* Ran dotnet restore evaluate
* created DNS service verification using DNSClient (#2401)
* [SG-678] Api Endpoints for Domain Claiming (#2430)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* changed logic for setting the initial value for the NextRunCount
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Added stored procedure to get organization sso details by email address
* Added endpoint to get sso details of an organization with email
* Added organizationDomainRepository to OrganizationController test
* merged with master and fixed conflicts
* [SG-661] Background Domain Verification Service (#2455)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* Added stored procedure to get unverified domains by nextrundate
* Renamed stored procedure name
* Added domain verification service interface
* Added GetManyByNextRunDate to repository
* Added verification domain service implementation
* changed logic for setting the initial value for the NextRunCount
* This commit should be signed using my SSH key
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Implemented EF core version on the repository
* Created background job implementation and logic
* popped stash
* Updated stored procedure and EF script
* Lint fix
* Added logic to set next job count and the next run date when a verification is false
* Added logic to set next job count and the next run date when a verification is false
* Updated stored procedure name on repository
* Removed test trigger
* Lint fix
* Added trigger for job
* Added job count update after successful domain verification
* Lint fix
* Lint fix
* [SG-682] Add Event Log Entries to Organization Domain (#2492)
* Added domain name property to Event related objects
* Added organization domain claiming event types
* Created migration script and updated related event scripts to include domanName
* Added EF Migrations
* Renamed postres script file extension
* Added DomainName property to response model
* Added abstraction to interface
* Added system name to enum
* dotnet formattinfg fix
* Added events to organization domain actions
* Added LastCheckedDate property to domain
* Migrations and stored procedure updates with new column
* Added new stored procedure to get domain by org id and domain name
* Log organization domain event abstract method
* Ef migrattion to add new LastCheckedDate column
* Added duplicate domain exception
* Modified create command to include domain verification and last checked date and renamed methods used
* removed variable
* changed service lifetime
* Renamed trigger
* Initialed property in constructor
* Ensured domain name is stored as lower case
* Fixed suggestions from review
* Fixed suggestions from review
* Return Conflict Status on Organization Domain APIs (#2498)
* Added conflict response to end point to help translate error message on the client better
* Added conflict response to end point to help translate error message on the client better
* Set message with exception message or generic message
* Added last check date to response model (#2499)
* Fix/Check to throw exception when domain is claimed by another organization (#2503)
* Added check to ensure domain claimed by another organization cannot be verified
* Made error message consistent
* [SG-660] Organization Domain Maintenance (#2502)
* Added email template
* Mail service abstraction and implementation
* Mail template model
* Initial delete job commit
* Added SPs to get all unverifed domains after 72 hours and another to delete unverified domains after 7 days
* Moved all organization domain scripts to single file
* Added new scripts implementation for sqlserver and EF core
* Renamed service
* Formatting fix
* Added background service to send warning email and delete expired domains
* Renamed variable
* Added implementation for email warning to organization admins and for deleting expired domains after 7 days
* Added formatting
* Modified read if expired script to limit result to 4 days
* Added send mail abstract method and implementation
* Model used in build mail body
* Completed maintenace service
* Added comment to make logic clear
* Fixed cron expression (#2505)
* Modified procedure and methods to handle flexible verification adn expiration period (#2517)
* Merged with master
* [SG-908] Unit Tests for Organization Domain Claiming Feature (#2522)
* added test controlleer class
* added unit test for create command
* Added query tests
* Added tests for delete and verify command
* Formated code and added some more unit tests
* Fixed lint
* Added log event assertion to create command tests
* Added log event assertion to delete command tests
* Added unit tests for organization domain controller
* Added unit tests for organization domain service
* Modified test after merge
* fixed comment
* fixed comment
* fixed lint
* Defect/SG-977 - Org domain event logs missing details (#2573)
* SG-977 - (1) Refactor EventSystemUser.SSO to be EventSystemUser.DomainVerification to better match SCIM property and for easier display and translation on web client (2) Add new DeviceType of Server to be used on SCIM and Domain Verification logs so event log will show Server as client.
* SG-977 - SCIM bugfix - Restoring / Revoking user access via Jumpcloud activation / suspension did not properly log the events as SCIM events so the client side showed Unknown for both Client and Member.
* Run autoformat to fix lint errors
* SG-977 - Fixed broken test due to new device type logic in event service
* SG-976 - Add admin log and clean up log verbiage for domain verification (#2574)
* SG-976 - Add admin log and clean up log verbiage for domain verification
* SG-976 - (1) Use logInformation extension without exception (2) Clarify verbiage of logs
* SG-955 - On domain verification error or failure, set last checked da… (#2541)
* SG-955 - On domain verification error or failure, set last checked date on the org domain.
* SG-955 - Refactoring VerifyOrganizationDomain event logging to avoid duplication and increase efficiency (based on Gbubemi's PR feedback)
* Org Domain Background Verification service - set last checked date (#2599)
* Refactored OrganizationDomain repository to work with latest changes on code base
* Fixed formatting
* [SG-957] Cannot Delete Organizations due to FK Constraint (#2602)
* Added stored procedure to fix FX contstraint issue when deleting an organization
* Update stored procedures related to organization delete with OrganizationDomain_OrganizationDelete SP
* Fixed formatting
* Updated SP
* SG-990 - Log expired domains that are going to be deleted.
* Fix lint errors with auto format
* /home/runner/work/server/server/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs(107,2): error FINALNEWLINE: Fix final newline. Insert '\n'.
* Added missing bracket to fix compile error.
* Added imports for Domain Claiming classes that were lost on merge.
* Fixing broken unit tests + adding proper behavior for newly added SCIM logic changing device type
* Fix lint errors again
* Included domain name set in constructor (#2618)
* [SG-1001] Error Thrown When Verifying Sub Domains (#2621)
* Renamed exception to a more generic name that receives error message from the dns client and also added updates to job count and next run date
* Improved error logs by adding dns client error message
* Fixed formatting
* [SG-1001] Added event logs when a domain is not verified due to thrown exception (#2623)
* Added eevent logs when a domain is not verified due to thrown exception
* Fixed formatting
* Org Domain Verification - Small refactor to improve method/model name… (#2641)
* Org Domain Verification - Small refactor to improve method/model names and method locations - required refactoring of controller routes (I confirmed all behavior still functional)
* Fixed organization test controller issue
* Fixed lint
* Autoformat org domain controller
* Removing whitespace for lint argh, why does Rider not do this.
---------
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
* Tweak name of Request model to match Response model for ClaimedOrgDomain call
* [SG-1009] Users with Custom Role and "Manage SSO" permission don't receive verification failed email (#2645)
* Modified condition to pick up unverified domains after said period
* Fix to get emails of custom users with manage sso rights
* Formatted code
* Removed return that made background job exit on successful validation (#2648)
* [SG-1014] Unit Tests for Get Organization Sso Details (#2655)
* Added unit tests for GetOrgDomainSsoDetails
* renamed variable
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so … (#2657)
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so that claimed domain results will come back if an org has not yet setup a policy
* Removed migration as not needed
* Updated OrganizationDomainSsoDetails_ReadByEmail from original creation migration to use outer join & handle null policy results (and still return results)
* Fixed lint formatting
---------
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Jared Snider <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2023-02-15 14:26:41 -05:00
. GetOrganizationApiKeyAsync ( organization . Id , model . Type ) ? ?
await _createOrganizationApiKeyCommand . CreateAsync ( organization . Id , model . Type ) ;
2021-12-16 15:35:09 +01:00
2021-05-19 09:40:32 -05:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
2020-06-08 17:40:18 -04:00
if ( user = = null )
2022-08-29 15:53:48 -04:00
{
2020-06-08 17:40:18 -04:00
throw new UnauthorizedAccessException ( ) ;
2022-08-29 14:53:16 -04:00
}
2021-05-19 09:40:32 -05:00
if ( model . Type ! = OrganizationApiKeyType . Scim
& & ! await _userService . VerifySecretAsync ( user , model . Secret ) )
2022-08-29 16:06:55 -04:00
{
2021-05-19 09:40:32 -05:00
await Task . Delay ( 2000 ) ;
throw new BadRequestException ( "MasterPasswordHash" , "Invalid password." ) ;
}
2022-08-29 16:06:55 -04:00
else
{
2022-05-10 17:12:09 -04:00
await _rotateOrganizationApiKeyCommand . RotateApiKeyAsync ( organizationApiKey ) ;
2020-12-01 16:43:07 -05:00
var response = new ApiKeyResponseModel ( organizationApiKey ) ;
2019-03-04 09:52:43 -05:00
return response ;
2022-08-29 16:06:55 -04:00
}
}
2021-05-19 09:40:32 -05:00
private async Task < bool > HasApiKeyAccessAsync ( Guid orgId , OrganizationApiKeyType ? type )
2022-08-29 16:06:55 -04:00
{
2021-05-19 09:40:32 -05:00
return type switch
2022-08-29 14:53:16 -04:00
{
2021-05-19 09:40:32 -05:00
OrganizationApiKeyType . Scim = > await _currentContext . ManageScim ( orgId ) ,
2021-07-08 17:05:32 +02:00
_ = > await _currentContext . OrganizationOwner ( orgId ) ,
2021-05-19 09:40:32 -05:00
} ;
}
2021-12-16 15:35:09 +01:00
2023-08-15 15:10:56 +02:00
[HttpGet("{id}/public-key")]
public async Task < OrganizationPublicKeyResponseModel > GetPublicKey ( string id )
2022-08-29 16:06:55 -04:00
{
2021-10-06 10:39:13 +02:00
var org = await _organizationRepository . GetByIdAsync ( new Guid ( id ) ) ;
if ( org = = null )
2022-08-29 16:06:55 -04:00
{
2021-10-06 10:39:13 +02:00
throw new NotFoundException ( ) ;
}
2023-08-15 15:10:56 +02:00
return new OrganizationPublicKeyResponseModel ( org ) ;
}
2024-09-06 10:09:01 +05:30
[Obsolete("TDL-136 Renamed to public-key (2023.8), left for backwards compatibility with older clients.")]
2023-08-15 15:10:56 +02:00
[HttpGet("{id}/keys")]
public async Task < OrganizationPublicKeyResponseModel > GetKeys ( string id )
{
return await GetPublicKey ( id ) ;
2021-10-06 10:39:13 +02:00
}
[HttpPost("{id}/keys")]
2025-04-09 15:23:29 +01:00
public async Task < OrganizationKeysResponseModel > PostKeys ( Guid id , [ FromBody ] OrganizationKeysRequestModel model )
2022-08-29 16:06:55 -04:00
{
2021-10-06 10:39:13 +02:00
var user = await _userService . GetUserByPrincipalAsync ( User ) ;
if ( user = = null )
2022-08-29 15:53:48 -04:00
{
2021-11-17 11:46:35 +01:00
throw new UnauthorizedAccessException ( ) ;
2022-08-29 15:53:48 -04:00
}
2021-10-06 10:39:13 +02:00
2025-04-09 15:23:29 +01:00
var org = await _organizationUpdateKeysCommand . UpdateOrganizationKeysAsync ( id , model . PublicKey ,
[SG-147] Organization Domain Claiming Feature (#2704)
* [SG-696] Organization Domain Claiming DB Objects and Migrations (#2394)
* model organization domain claiming
* Added migration scripts and db objects for mssql
* create and implement sql repository abstraction
* Added ef migrations for mysql and postgres. Removed time without timezone in previous migration
* made update on sql migration to use create or alter statement
* removed active column from OrganizationDomain table and decided to go with the hard delete approach
* Ran dotnet restore evaluate
* created DNS service verification using DNSClient (#2401)
* [SG-678] Api Endpoints for Domain Claiming (#2430)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* changed logic for setting the initial value for the NextRunCount
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Added stored procedure to get organization sso details by email address
* Added endpoint to get sso details of an organization with email
* Added organizationDomainRepository to OrganizationController test
* merged with master and fixed conflicts
* [SG-661] Background Domain Verification Service (#2455)
* Added stored procedure to read claimed domains
* Updated Organization Domain Repository to include method to get claimed domains
* Updated domain entity and added request model
* Implemented organization domain respository and regsitered it in the various extensions
* Added create endpoint, request, responses and command
* Added endpoint to get domain by domain entry id
* Ran lint fix
* Added new stored procedure to get domains by organizattion id
* Moved migration scripts to init migration and added new procedure
* Renamed from domainId to Id
* Added and implemented GetDomainByOrganizationId
* Completed GetDomainByOrgId endpoint and started work on verify domain endpoint
* Updated the OrganizationDomain update procedure
* Added delete command and include other endpoints in the controller
* Remove test item from controller
* Remove test item from controller
* Changed access to allow admin, owners and manage sso roles
* Added stored procedure to get unverified domains by nextrundate
* Renamed stored procedure name
* Added domain verification service interface
* Added GetManyByNextRunDate to repository
* Added verification domain service implementation
* changed logic for setting the initial value for the NextRunCount
* This commit should be signed using my SSH key
* Renamed NextRunCount to JobRunCount
* Renamed NextRunCount to JobRunCount on mysql
* Renamed NextRunCount to JobRunCount on postgres
* Removed chaining pattern and added logic to get next run date
* Lint fix
* Implemented EF core version on the repository
* Created background job implementation and logic
* popped stash
* Updated stored procedure and EF script
* Lint fix
* Added logic to set next job count and the next run date when a verification is false
* Added logic to set next job count and the next run date when a verification is false
* Updated stored procedure name on repository
* Removed test trigger
* Lint fix
* Added trigger for job
* Added job count update after successful domain verification
* Lint fix
* Lint fix
* [SG-682] Add Event Log Entries to Organization Domain (#2492)
* Added domain name property to Event related objects
* Added organization domain claiming event types
* Created migration script and updated related event scripts to include domanName
* Added EF Migrations
* Renamed postres script file extension
* Added DomainName property to response model
* Added abstraction to interface
* Added system name to enum
* dotnet formattinfg fix
* Added events to organization domain actions
* Added LastCheckedDate property to domain
* Migrations and stored procedure updates with new column
* Added new stored procedure to get domain by org id and domain name
* Log organization domain event abstract method
* Ef migrattion to add new LastCheckedDate column
* Added duplicate domain exception
* Modified create command to include domain verification and last checked date and renamed methods used
* removed variable
* changed service lifetime
* Renamed trigger
* Initialed property in constructor
* Ensured domain name is stored as lower case
* Fixed suggestions from review
* Fixed suggestions from review
* Return Conflict Status on Organization Domain APIs (#2498)
* Added conflict response to end point to help translate error message on the client better
* Added conflict response to end point to help translate error message on the client better
* Set message with exception message or generic message
* Added last check date to response model (#2499)
* Fix/Check to throw exception when domain is claimed by another organization (#2503)
* Added check to ensure domain claimed by another organization cannot be verified
* Made error message consistent
* [SG-660] Organization Domain Maintenance (#2502)
* Added email template
* Mail service abstraction and implementation
* Mail template model
* Initial delete job commit
* Added SPs to get all unverifed domains after 72 hours and another to delete unverified domains after 7 days
* Moved all organization domain scripts to single file
* Added new scripts implementation for sqlserver and EF core
* Renamed service
* Formatting fix
* Added background service to send warning email and delete expired domains
* Renamed variable
* Added implementation for email warning to organization admins and for deleting expired domains after 7 days
* Added formatting
* Modified read if expired script to limit result to 4 days
* Added send mail abstract method and implementation
* Model used in build mail body
* Completed maintenace service
* Added comment to make logic clear
* Fixed cron expression (#2505)
* Modified procedure and methods to handle flexible verification adn expiration period (#2517)
* Merged with master
* [SG-908] Unit Tests for Organization Domain Claiming Feature (#2522)
* added test controlleer class
* added unit test for create command
* Added query tests
* Added tests for delete and verify command
* Formated code and added some more unit tests
* Fixed lint
* Added log event assertion to create command tests
* Added log event assertion to delete command tests
* Added unit tests for organization domain controller
* Added unit tests for organization domain service
* Modified test after merge
* fixed comment
* fixed comment
* fixed lint
* Defect/SG-977 - Org domain event logs missing details (#2573)
* SG-977 - (1) Refactor EventSystemUser.SSO to be EventSystemUser.DomainVerification to better match SCIM property and for easier display and translation on web client (2) Add new DeviceType of Server to be used on SCIM and Domain Verification logs so event log will show Server as client.
* SG-977 - SCIM bugfix - Restoring / Revoking user access via Jumpcloud activation / suspension did not properly log the events as SCIM events so the client side showed Unknown for both Client and Member.
* Run autoformat to fix lint errors
* SG-977 - Fixed broken test due to new device type logic in event service
* SG-976 - Add admin log and clean up log verbiage for domain verification (#2574)
* SG-976 - Add admin log and clean up log verbiage for domain verification
* SG-976 - (1) Use logInformation extension without exception (2) Clarify verbiage of logs
* SG-955 - On domain verification error or failure, set last checked da… (#2541)
* SG-955 - On domain verification error or failure, set last checked date on the org domain.
* SG-955 - Refactoring VerifyOrganizationDomain event logging to avoid duplication and increase efficiency (based on Gbubemi's PR feedback)
* Org Domain Background Verification service - set last checked date (#2599)
* Refactored OrganizationDomain repository to work with latest changes on code base
* Fixed formatting
* [SG-957] Cannot Delete Organizations due to FK Constraint (#2602)
* Added stored procedure to fix FX contstraint issue when deleting an organization
* Update stored procedures related to organization delete with OrganizationDomain_OrganizationDelete SP
* Fixed formatting
* Updated SP
* SG-990 - Log expired domains that are going to be deleted.
* Fix lint errors with auto format
* /home/runner/work/server/server/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs(107,2): error FINALNEWLINE: Fix final newline. Insert '\n'.
* Added missing bracket to fix compile error.
* Added imports for Domain Claiming classes that were lost on merge.
* Fixing broken unit tests + adding proper behavior for newly added SCIM logic changing device type
* Fix lint errors again
* Included domain name set in constructor (#2618)
* [SG-1001] Error Thrown When Verifying Sub Domains (#2621)
* Renamed exception to a more generic name that receives error message from the dns client and also added updates to job count and next run date
* Improved error logs by adding dns client error message
* Fixed formatting
* [SG-1001] Added event logs when a domain is not verified due to thrown exception (#2623)
* Added eevent logs when a domain is not verified due to thrown exception
* Fixed formatting
* Org Domain Verification - Small refactor to improve method/model name… (#2641)
* Org Domain Verification - Small refactor to improve method/model names and method locations - required refactoring of controller routes (I confirmed all behavior still functional)
* Fixed organization test controller issue
* Fixed lint
* Autoformat org domain controller
* Removing whitespace for lint argh, why does Rider not do this.
---------
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
* Tweak name of Request model to match Response model for ClaimedOrgDomain call
* [SG-1009] Users with Custom Role and "Manage SSO" permission don't receive verification failed email (#2645)
* Modified condition to pick up unverified domains after said period
* Fix to get emails of custom users with manage sso rights
* Formatted code
* Removed return that made background job exit on successful validation (#2648)
* [SG-1014] Unit Tests for Get Organization Sso Details (#2655)
* Added unit tests for GetOrgDomainSsoDetails
* renamed variable
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so … (#2657)
* Adjust OrganizationDomainSsoDetails_ReadByEmail to use outer join so that claimed domain results will come back if an org has not yet setup a policy
* Removed migration as not needed
* Updated OrganizationDomainSsoDetails_ReadByEmail from original creation migration to use outer join & handle null policy results (and still return results)
* Fixed lint formatting
---------
Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
Co-authored-by: Jared Snider <jsnider@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
2023-02-15 14:26:41 -05:00
model . EncryptedPrivateKey ) ;
2021-10-06 10:39:13 +02:00
return new OrganizationKeysResponseModel ( org ) ;
2022-08-29 16:06:55 -04:00
}
2021-10-06 10:39:13 +02:00
2021-11-17 11:46:35 +01:00
[HttpGet("{id:guid}/sso")]
public async Task < OrganizationSsoResponseModel > GetSso ( Guid id )
2022-08-29 16:06:55 -04:00
{
2021-11-17 11:46:35 +01:00
if ( ! await _currentContext . ManageSso ( id ) )
2022-08-29 16:06:55 -04:00
{
2021-11-17 11:46:35 +01:00
throw new NotFoundException ( ) ;
2022-08-29 14:53:16 -04:00
}
2021-10-06 10:39:13 +02:00
var organization = await _organizationRepository . GetByIdAsync ( id ) ;
if ( organization = = null )
2022-08-29 14:53:16 -04:00
{
2021-10-06 10:39:13 +02:00
throw new NotFoundException ( ) ;
}
2022-08-29 14:53:16 -04:00
2021-05-19 09:40:32 -05:00
var ssoConfig = await _ssoConfigRepository . GetByOrganizationIdAsync ( id ) ;
2022-08-29 14:53:16 -04:00
2019-02-18 15:40:47 -05:00
return new OrganizationSsoResponseModel ( organization , _globalSettings , ssoConfig ) ;
2022-08-29 16:06:55 -04:00
}
2022-08-29 14:53:16 -04:00
2021-10-06 10:39:13 +02:00
[HttpPost("{id:guid}/sso")]
2021-11-22 19:55:25 +10:00
public async Task < OrganizationSsoResponseModel > PostSso ( Guid id , [ FromBody ] OrganizationSsoRequestModel model )
2022-08-29 16:06:55 -04:00
{
2021-11-22 19:55:25 +10:00
if ( ! await _currentContext . ManageSso ( id ) )
2022-08-29 16:06:55 -04:00
{
2021-11-22 19:55:25 +10:00
throw new NotFoundException ( ) ;
2022-08-29 16:06:55 -04:00
}
2022-08-29 15:53:48 -04:00
2022-05-10 12:19:22 +10:00
var organization = await _organizationRepository . GetByIdAsync ( id ) ;
if ( organization = = null )
2022-08-29 16:06:55 -04:00
{
2022-05-10 12:19:22 +10:00
throw new NotFoundException ( ) ;
2022-08-29 15:53:48 -04:00
}
2022-08-29 16:06:55 -04:00
2021-10-06 10:39:13 +02:00
var ssoConfig = await _ssoConfigRepository . GetByOrganizationIdAsync ( id ) ;
2019-02-18 15:40:47 -05:00
ssoConfig = ssoConfig = = null ? model . ToSsoConfig ( id ) : model . ToSsoConfig ( ssoConfig ) ;
2022-11-02 09:57:33 -07:00
organization . Identifier = model . Identifier ;
2022-08-29 16:06:55 -04:00
2019-02-18 15:40:47 -05:00
await _ssoConfigService . SaveAsync ( ssoConfig , organization ) ;
2022-11-02 09:57:33 -07:00
await _organizationService . UpdateAsync ( organization ) ;
2022-08-29 16:06:55 -04:00
2018-07-16 17:20:57 -04:00
return new OrganizationSsoResponseModel ( organization , _globalSettings , ssoConfig ) ;
2017-03-02 00:15:05 -05:00
}
[AC-1373] Flexible Collections (#3245)
* [AC-1117] Add manage permission (#3126)
* Update sql files to add Manage permission
* Add migration script
* Rename collection manage migration file to remove duplicate migration date
* Migrations
* Add manage to models
* Add manage to repository
* Add constraint to Manage columns
* Migration lint fixes
* Add manage to OrganizationUserUserDetails_ReadWithCollectionsById
* Add missing manage fields
* Add 'Manage' to UserCollectionDetails
* Use CREATE OR ALTER where possible
* [AC-1374] Limit collection creation/deletion to Owner/Admin (#3145)
* feat: update org table with new column, write migration, refs AC-1374
* feat: update views with new column, refs AC-1374
* feat: Alter sprocs (org create/update) to include new column, refs AC-1374
* feat: update entity/data/request/response models to handle new column, refs AC-1374
* feat: update necessary Provider related views during migration, refs AC-1374
* fix: update org create to default new column to false, refs AC-1374
* feat: added new API/request model for collection management and removed property from update request model, refs AC-1374
* fix: renamed migration script to be after secrets manage beta column changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: add ef migrations to reflect mssql changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: update API signature to accept Guid and explain Cd verbiage, refs AC-1374
* fix: merge conflict resolution
* [AC-1174] CollectionUser and CollectionGroup authorization handlers (#3194)
* [AC-1174] Introduce BulkAuthorizationHandler.cs
* [AC-1174] Introduce CollectionUserAuthorizationHandler
* [AC-1174] Add CreateForNewCollection CollectionUser requirement
* [AC-1174] Add some more details to CollectionCustomization
* [AC-1174] Formatting
* [AC-1174] Add CollectionGroupOperation.cs
* [AC-1174] Introduce CollectionGroupAuthorizationHandler.cs
* [AC-1174] Cleanup CollectionFixture customization
Implement and use re-usable extension method to support seeded Guids
* [AC-1174] Introduce WithValueFromList AutoFixtureExtensions
Modify CollectionCustomization to use multiple organization Ids for auto generated test data
* [AC-1174] Simplify CollectionUserAuthorizationHandler.cs
Modify the authorization handler to only perform authorization logic. Validation logic will need to be handled by any calling commands/controllers instead.
* [AC-1174] Introduce shared CollectionAccessAuthorizationHandlerBase
A shared base authorization handler was created for both CollectionUser and CollectionGroup resources, as they share the same underlying management authorization logic.
* [AC-1174] Update CollectionUserAuthorizationHandler and CollectionGroupAuthorizationHandler to use the new CollectionAccessAuthorizationHandlerBase class
* [AC-1174] Formatting
* [AC-1174] Cleanup typo and redundant ToList() call
* [AC-1174] Add check for provider users
* [AC-1174] Reduce nested loops
* [AC-1174] Introduce ICollectionAccess.cs
* [AC-1174] Remove individual CollectionGroup and CollectionUser auth handlers and use base class instead
* [AC-1174] Tweak unit test to fail minimally
* [AC-1174] Reorganize authorization handlers in Core project
* [AC-1174] Introduce new AddCoreAuthorizationHandlers() extension method
* [AC-1174] Move CollectionAccessAuthorizationHandler into Api project
* [AC-1174] Move CollectionFixture to Vault folder
* [AC-1174] Rename operation to CreateUpdateDelete
* [AC-1174] Require single organization for collection access authorization handler
- Add requirement that all target collections must belong to the same organization
- Simplify logic related to multiple organizations
- Update tests and helpers
- Use ToHashSet to improve lookup time
* [AC-1174] Fix null reference exception
* [AC-1174] Throw bad request exception when collections belong to different organizations
* [AC-1174] Switch to CollectionAuthorizationHandler instead of CollectionAccessAuthorizationHandler to reduce complexity
* Fix improper merge conflict resolution
* fix: add permission check for collection management api, refs AC-1647 (#3252)
* [AC-1125] Enforce org setting for creating/deleting collections (#3241)
* [AC-1117] Add manage permission (#3126)
* Update sql files to add Manage permission
* Add migration script
* Rename collection manage migration file to remove duplicate migration date
* Migrations
* Add manage to models
* Add manage to repository
* Add constraint to Manage columns
* Migration lint fixes
* Add manage to OrganizationUserUserDetails_ReadWithCollectionsById
* Add missing manage fields
* Add 'Manage' to UserCollectionDetails
* Use CREATE OR ALTER where possible
* [AC-1374] Limit collection creation/deletion to Owner/Admin (#3145)
* feat: update org table with new column, write migration, refs AC-1374
* feat: update views with new column, refs AC-1374
* feat: Alter sprocs (org create/update) to include new column, refs AC-1374
* feat: update entity/data/request/response models to handle new column, refs AC-1374
* feat: update necessary Provider related views during migration, refs AC-1374
* fix: update org create to default new column to false, refs AC-1374
* feat: added new API/request model for collection management and removed property from update request model, refs AC-1374
* fix: renamed migration script to be after secrets manage beta column changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: add ef migrations to reflect mssql changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: update API signature to accept Guid and explain Cd verbiage, refs AC-1374
* feat: created collection auth handler/operations, added LimitCollectionCdOwnerAdmin to CurrentContentOrganization, refs AC-1125
* feat: create vault service collection extensions and register with base services, refs AC-1125
* feat: deprecated CurrentContext.CreateNewCollections, refs AC-1125
* feat: deprecate DeleteAnyCollection for single resource usages, refs AC-1125
* feat: move service registration to api, update references, refs AC-1125
* feat: add bulk delete authorization handler, refs AC-1125
* feat: always assign user and give manage access on create, refs AC-1125
* fix: updated CurrentContextOrganization type, refs AC-1125
* feat: combined existing collection authorization handlers/operations, refs AC-1125
* fix: OrganizationServiceTests -> CurrentContentOrganization typo, refs AC-1125
* fix: format, refs AC-1125
* fix: update collection controller tests, refs AC-1125
* fix: dotnet format, refs AC-1125
* feat: removed extra BulkAuthorizationHandler, refs AC-1125
* fix: dotnet format, refs AC-1125
* fix: change string to guid for org id, update bulk delete request model, refs AC-1125
* fix: remove delete many collection check, refs AC-1125
* fix: clean up collection auth handler, refs AC-1125
* fix: format fix for CollectionOperations, refs AC-1125
* fix: removed unnecessary owner check, add org null check to custom permission validation, refs AC-1125
* fix: remove unused methods in CurrentContext, refs AC-1125
* fix: removed obsolete test, fixed failling delete many test, refs AC-1125
* fix: CollectionAuthorizationHandlerTests fixes, refs AC-1125
* fix: OrganizationServiceTests fix broken test by mocking GetOrganization, refs AC-1125
* fix: CollectionAuthorizationHandler - remove unused repository, refs AC-1125
* feat: moved UserId null check to common method, refs AC-1125
* fix: updated auth handler tests to remove dependency on requirement for common code checks, refs AC-1125
* feat: updated conditionals/comments for create/delete methods within colleciton auth handler, refs AC-1125
* feat: added create/delete collection auth handler success methods, refs AC-1125
* fix: new up permissions to prevent excessive null checks, refs AC-1125
* fix: remove old reference to CreateNewCollections, refs AC-1125
* fix: typo within ViewAssignedCollections method, refs AC-1125
---------
Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com>
* refactor: remove organizationId from CollectionBulkDeleteRequestModel, refs AC-1649 (#3282)
* [AC-1174] Bulk Collection Management (#3229)
* [AC-1174] Update SelectionReadOnlyRequestModel to use Guid for Id property
* [AC-1174] Introduce initial bulk-access collection endpoint
* [AC-1174] Introduce BulkAddCollectionAccessCommand and validation logic/tests
* [AC-1174] Add CreateOrUpdateAccessMany method to CollectionRepository
* [AC-1174] Add event logs for bulk add collection access command
* [AC-1174] Add User_BumpAccountRevisionDateByCollectionIds and database migration script
* [AC-1174] Implement EF repository method
* [AC-1174] Improve null checks
* [AC-1174] Remove unnecessary BulkCollectionAccessRequestModel helpers
* [AC-1174] Add unit tests for new controller endpoint
* [AC-1174] Fix formatting
* [AC-1174] Remove comment
* [AC-1174] Remove redundant organizationId parameter
* [AC-1174] Ensure user and group Ids are distinct
* [AC-1174] Cleanup tests based on PR feedback
* [AC-1174] Formatting
* [AC-1174] Update CollectionGroup alias in the sproc
* [AC-1174] Add some additional comments to SQL sproc
* [AC-1174] Add comment explaining additional SaveChangesAsync call
---------
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
* [AC-1646] Rename LimitCollectionCdOwnerAdmin column (#3300)
* Rename LimitCollectionCdOwnerAdmin -> LimitCollectionCreationDeletion
* Rename and bump migration script
* [AC-1666] Removed EditAnyCollection from Create/Delete permission checks (#3301)
* fix: remove EditAnyCollection from Create/Delete permission check, refs AC-1666
* fix: updated comment, refs AC-1666
* [AC-1669] Bug - Remove obsolete assignUserId from CollectionService.SaveAsync(...) (#3312)
* fix: remove AssignUserId from CollectionService.SaveAsync, refs AC-1669
* fix: add manage access conditional before creating collection, refs AC-1669
* fix: move access logic for create/update, fix all tests, refs AC-1669
* fix: add CollectionAccessSelection fixture, update tests, update bad reqeuest message, refs AC-1669
* fix: format, refs AC-1669
* fix: update null params with specific arg.is null checks, refs Ac-1669
* fix: update attribute class name, refs AC-1669
* [AC-1713] [Flexible collections] Add feature flags to server (#3334)
* Add feature flags for FlexibleCollections and BulkCollectionAccess
* Flag new routes and behaviour
---------
Co-authored-by: Rui Tomé <108268980+r-tome@users.noreply.github.com>
* Add joint codeownership for auth handlers (#3346)
* [AC-1717] Update default values for LimitCollectionCreationDeletion (#3365)
* Change default value in organization create sproc to 1
* Drop old column name still present in some QA instances
* Set LimitCollectionCreationDeletion value in code based on feature flag
* Fix: add missing namespace after merging in master
* Fix: add missing namespace after merging in master
* [AC-1683] Fix DB migrations for new Manage permission (#3307)
* [AC-1683] Update migration script and introduce V2 procedures and types
* [AC-1683] Update repository calls to use new V2 procedures / types
* [AC-1684] Update bulk add collection migration script to use new V2 type
* [AC-1683] Undo Manage changes to more original procedures
* [AC-1683] Restore whitespace changes
* [AC-1683] Clarify comments regarding explicit column lists
* [AC-1683] Update migration script dates
* [AC-1683] Split the migration script for readability
* [AC-1683] Re-name SelectReadOnlyArray_V2 to CollectionAccessSelectionType
* [AC-1648] [Flexible Collections] Bump migration scripts before feature branch merge (#3371)
* Bump dates on sql migration scripts
* Bump date on ef migrations
---------
Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com>
Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com>
Co-authored-by: Vincent Salucci <vincesalucci21@gmail.com>
Co-authored-by: Shane Melton <smelton@bitwarden.com>
Co-authored-by: Rui Tomé <108268980+r-tome@users.noreply.github.com>
2023-11-01 19:30:52 +10:00
[HttpPut("{id}/collection-management")]
public async Task < OrganizationResponseModel > PutCollectionManagement ( Guid id , [ FromBody ] OrganizationCollectionManagementUpdateRequestModel model )
{
var organization = await _organizationRepository . GetByIdAsync ( id ) ;
if ( organization = = null )
{
throw new NotFoundException ( ) ;
}
if ( ! await _currentContext . OrganizationOwner ( id ) )
{
throw new NotFoundException ( ) ;
}
2024-10-18 11:00:01 -04:00
await _organizationService . UpdateAsync ( model . ToOrganization ( organization , _featureService ) , eventType : EventType . Organization_CollectionManagement_Updated ) ;
2025-02-27 07:55:46 -05:00
var plan = await _pricingClient . GetPlan ( organization . PlanType ) ;
return new OrganizationResponseModel ( organization , plan ) ;
[AC-1373] Flexible Collections (#3245)
* [AC-1117] Add manage permission (#3126)
* Update sql files to add Manage permission
* Add migration script
* Rename collection manage migration file to remove duplicate migration date
* Migrations
* Add manage to models
* Add manage to repository
* Add constraint to Manage columns
* Migration lint fixes
* Add manage to OrganizationUserUserDetails_ReadWithCollectionsById
* Add missing manage fields
* Add 'Manage' to UserCollectionDetails
* Use CREATE OR ALTER where possible
* [AC-1374] Limit collection creation/deletion to Owner/Admin (#3145)
* feat: update org table with new column, write migration, refs AC-1374
* feat: update views with new column, refs AC-1374
* feat: Alter sprocs (org create/update) to include new column, refs AC-1374
* feat: update entity/data/request/response models to handle new column, refs AC-1374
* feat: update necessary Provider related views during migration, refs AC-1374
* fix: update org create to default new column to false, refs AC-1374
* feat: added new API/request model for collection management and removed property from update request model, refs AC-1374
* fix: renamed migration script to be after secrets manage beta column changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: add ef migrations to reflect mssql changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: update API signature to accept Guid and explain Cd verbiage, refs AC-1374
* fix: merge conflict resolution
* [AC-1174] CollectionUser and CollectionGroup authorization handlers (#3194)
* [AC-1174] Introduce BulkAuthorizationHandler.cs
* [AC-1174] Introduce CollectionUserAuthorizationHandler
* [AC-1174] Add CreateForNewCollection CollectionUser requirement
* [AC-1174] Add some more details to CollectionCustomization
* [AC-1174] Formatting
* [AC-1174] Add CollectionGroupOperation.cs
* [AC-1174] Introduce CollectionGroupAuthorizationHandler.cs
* [AC-1174] Cleanup CollectionFixture customization
Implement and use re-usable extension method to support seeded Guids
* [AC-1174] Introduce WithValueFromList AutoFixtureExtensions
Modify CollectionCustomization to use multiple organization Ids for auto generated test data
* [AC-1174] Simplify CollectionUserAuthorizationHandler.cs
Modify the authorization handler to only perform authorization logic. Validation logic will need to be handled by any calling commands/controllers instead.
* [AC-1174] Introduce shared CollectionAccessAuthorizationHandlerBase
A shared base authorization handler was created for both CollectionUser and CollectionGroup resources, as they share the same underlying management authorization logic.
* [AC-1174] Update CollectionUserAuthorizationHandler and CollectionGroupAuthorizationHandler to use the new CollectionAccessAuthorizationHandlerBase class
* [AC-1174] Formatting
* [AC-1174] Cleanup typo and redundant ToList() call
* [AC-1174] Add check for provider users
* [AC-1174] Reduce nested loops
* [AC-1174] Introduce ICollectionAccess.cs
* [AC-1174] Remove individual CollectionGroup and CollectionUser auth handlers and use base class instead
* [AC-1174] Tweak unit test to fail minimally
* [AC-1174] Reorganize authorization handlers in Core project
* [AC-1174] Introduce new AddCoreAuthorizationHandlers() extension method
* [AC-1174] Move CollectionAccessAuthorizationHandler into Api project
* [AC-1174] Move CollectionFixture to Vault folder
* [AC-1174] Rename operation to CreateUpdateDelete
* [AC-1174] Require single organization for collection access authorization handler
- Add requirement that all target collections must belong to the same organization
- Simplify logic related to multiple organizations
- Update tests and helpers
- Use ToHashSet to improve lookup time
* [AC-1174] Fix null reference exception
* [AC-1174] Throw bad request exception when collections belong to different organizations
* [AC-1174] Switch to CollectionAuthorizationHandler instead of CollectionAccessAuthorizationHandler to reduce complexity
* Fix improper merge conflict resolution
* fix: add permission check for collection management api, refs AC-1647 (#3252)
* [AC-1125] Enforce org setting for creating/deleting collections (#3241)
* [AC-1117] Add manage permission (#3126)
* Update sql files to add Manage permission
* Add migration script
* Rename collection manage migration file to remove duplicate migration date
* Migrations
* Add manage to models
* Add manage to repository
* Add constraint to Manage columns
* Migration lint fixes
* Add manage to OrganizationUserUserDetails_ReadWithCollectionsById
* Add missing manage fields
* Add 'Manage' to UserCollectionDetails
* Use CREATE OR ALTER where possible
* [AC-1374] Limit collection creation/deletion to Owner/Admin (#3145)
* feat: update org table with new column, write migration, refs AC-1374
* feat: update views with new column, refs AC-1374
* feat: Alter sprocs (org create/update) to include new column, refs AC-1374
* feat: update entity/data/request/response models to handle new column, refs AC-1374
* feat: update necessary Provider related views during migration, refs AC-1374
* fix: update org create to default new column to false, refs AC-1374
* feat: added new API/request model for collection management and removed property from update request model, refs AC-1374
* fix: renamed migration script to be after secrets manage beta column changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: add ef migrations to reflect mssql changes, refs AC-1374
* fix: dotnet format, refs AC-1374
* feat: update API signature to accept Guid and explain Cd verbiage, refs AC-1374
* feat: created collection auth handler/operations, added LimitCollectionCdOwnerAdmin to CurrentContentOrganization, refs AC-1125
* feat: create vault service collection extensions and register with base services, refs AC-1125
* feat: deprecated CurrentContext.CreateNewCollections, refs AC-1125
* feat: deprecate DeleteAnyCollection for single resource usages, refs AC-1125
* feat: move service registration to api, update references, refs AC-1125
* feat: add bulk delete authorization handler, refs AC-1125
* feat: always assign user and give manage access on create, refs AC-1125
* fix: updated CurrentContextOrganization type, refs AC-1125
* feat: combined existing collection authorization handlers/operations, refs AC-1125
* fix: OrganizationServiceTests -> CurrentContentOrganization typo, refs AC-1125
* fix: format, refs AC-1125
* fix: update collection controller tests, refs AC-1125
* fix: dotnet format, refs AC-1125
* feat: removed extra BulkAuthorizationHandler, refs AC-1125
* fix: dotnet format, refs AC-1125
* fix: change string to guid for org id, update bulk delete request model, refs AC-1125
* fix: remove delete many collection check, refs AC-1125
* fix: clean up collection auth handler, refs AC-1125
* fix: format fix for CollectionOperations, refs AC-1125
* fix: removed unnecessary owner check, add org null check to custom permission validation, refs AC-1125
* fix: remove unused methods in CurrentContext, refs AC-1125
* fix: removed obsolete test, fixed failling delete many test, refs AC-1125
* fix: CollectionAuthorizationHandlerTests fixes, refs AC-1125
* fix: OrganizationServiceTests fix broken test by mocking GetOrganization, refs AC-1125
* fix: CollectionAuthorizationHandler - remove unused repository, refs AC-1125
* feat: moved UserId null check to common method, refs AC-1125
* fix: updated auth handler tests to remove dependency on requirement for common code checks, refs AC-1125
* feat: updated conditionals/comments for create/delete methods within colleciton auth handler, refs AC-1125
* feat: added create/delete collection auth handler success methods, refs AC-1125
* fix: new up permissions to prevent excessive null checks, refs AC-1125
* fix: remove old reference to CreateNewCollections, refs AC-1125
* fix: typo within ViewAssignedCollections method, refs AC-1125
---------
Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com>
* refactor: remove organizationId from CollectionBulkDeleteRequestModel, refs AC-1649 (#3282)
* [AC-1174] Bulk Collection Management (#3229)
* [AC-1174] Update SelectionReadOnlyRequestModel to use Guid for Id property
* [AC-1174] Introduce initial bulk-access collection endpoint
* [AC-1174] Introduce BulkAddCollectionAccessCommand and validation logic/tests
* [AC-1174] Add CreateOrUpdateAccessMany method to CollectionRepository
* [AC-1174] Add event logs for bulk add collection access command
* [AC-1174] Add User_BumpAccountRevisionDateByCollectionIds and database migration script
* [AC-1174] Implement EF repository method
* [AC-1174] Improve null checks
* [AC-1174] Remove unnecessary BulkCollectionAccessRequestModel helpers
* [AC-1174] Add unit tests for new controller endpoint
* [AC-1174] Fix formatting
* [AC-1174] Remove comment
* [AC-1174] Remove redundant organizationId parameter
* [AC-1174] Ensure user and group Ids are distinct
* [AC-1174] Cleanup tests based on PR feedback
* [AC-1174] Formatting
* [AC-1174] Update CollectionGroup alias in the sproc
* [AC-1174] Add some additional comments to SQL sproc
* [AC-1174] Add comment explaining additional SaveChangesAsync call
---------
Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
* [AC-1646] Rename LimitCollectionCdOwnerAdmin column (#3300)
* Rename LimitCollectionCdOwnerAdmin -> LimitCollectionCreationDeletion
* Rename and bump migration script
* [AC-1666] Removed EditAnyCollection from Create/Delete permission checks (#3301)
* fix: remove EditAnyCollection from Create/Delete permission check, refs AC-1666
* fix: updated comment, refs AC-1666
* [AC-1669] Bug - Remove obsolete assignUserId from CollectionService.SaveAsync(...) (#3312)
* fix: remove AssignUserId from CollectionService.SaveAsync, refs AC-1669
* fix: add manage access conditional before creating collection, refs AC-1669
* fix: move access logic for create/update, fix all tests, refs AC-1669
* fix: add CollectionAccessSelection fixture, update tests, update bad reqeuest message, refs AC-1669
* fix: format, refs AC-1669
* fix: update null params with specific arg.is null checks, refs Ac-1669
* fix: update attribute class name, refs AC-1669
* [AC-1713] [Flexible collections] Add feature flags to server (#3334)
* Add feature flags for FlexibleCollections and BulkCollectionAccess
* Flag new routes and behaviour
---------
Co-authored-by: Rui Tomé <108268980+r-tome@users.noreply.github.com>
* Add joint codeownership for auth handlers (#3346)
* [AC-1717] Update default values for LimitCollectionCreationDeletion (#3365)
* Change default value in organization create sproc to 1
* Drop old column name still present in some QA instances
* Set LimitCollectionCreationDeletion value in code based on feature flag
* Fix: add missing namespace after merging in master
* Fix: add missing namespace after merging in master
* [AC-1683] Fix DB migrations for new Manage permission (#3307)
* [AC-1683] Update migration script and introduce V2 procedures and types
* [AC-1683] Update repository calls to use new V2 procedures / types
* [AC-1684] Update bulk add collection migration script to use new V2 type
* [AC-1683] Undo Manage changes to more original procedures
* [AC-1683] Restore whitespace changes
* [AC-1683] Clarify comments regarding explicit column lists
* [AC-1683] Update migration script dates
* [AC-1683] Split the migration script for readability
* [AC-1683] Re-name SelectReadOnlyArray_V2 to CollectionAccessSelectionType
* [AC-1648] [Flexible Collections] Bump migration scripts before feature branch merge (#3371)
* Bump dates on sql migration scripts
* Bump date on ef migrations
---------
Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com>
Co-authored-by: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com>
Co-authored-by: Vincent Salucci <vincesalucci21@gmail.com>
Co-authored-by: Shane Melton <smelton@bitwarden.com>
Co-authored-by: Rui Tomé <108268980+r-tome@users.noreply.github.com>
2023-11-01 19:30:52 +10:00
}
2024-12-10 09:55:03 -05:00
[HttpGet("{id}/plan-type")]
public async Task < PlanType > GetPlanType ( string id )
{
var orgIdGuid = new Guid ( id ) ;
var organization = await _organizationRepository . GetByIdAsync ( orgIdGuid ) ;
if ( organization = = null )
{
throw new NotFoundException ( ) ;
}
return organization . PlanType ;
}
2017-03-02 00:15:05 -05:00
}