1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 09:32:48 -05:00

[PM-11360] Remove export permission for providers (#5051)

- also fix managed collections export from CLI
This commit is contained in:
Thomas Rittson
2024-12-06 08:07:04 +10:00
committed by GitHub
parent 1f1510f4d4
commit 6a9b7ece2b
13 changed files with 428 additions and 2 deletions

View File

@ -0,0 +1,38 @@
using Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization;
using Bit.Core.Context;
using Bit.Core.Enums;
using Microsoft.AspNetCore.Authorization;
namespace Bit.Api.Tools.Authorization;
public class VaultExportAuthorizationHandler(ICurrentContext currentContext)
: AuthorizationHandler<VaultExportOperationRequirement, OrganizationScope>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
VaultExportOperationRequirement requirement, OrganizationScope organizationScope)
{
var org = currentContext.GetOrganization(organizationScope);
var authorized = requirement switch
{
not null when requirement == VaultExportOperations.ExportWholeVault =>
CanExportWholeVault(org),
not null when requirement == VaultExportOperations.ExportManagedCollections =>
CanExportManagedCollections(org),
_ => false
};
if (authorized)
{
context.Succeed(requirement);
}
return Task.FromResult(0);
}
private bool CanExportWholeVault(CurrentContextOrganization organization) => organization is
{ Type: OrganizationUserType.Owner or OrganizationUserType.Admin } or
{ Type: OrganizationUserType.Custom, Permissions.AccessImportExport: true };
private bool CanExportManagedCollections(CurrentContextOrganization organization) => organization is not null;
}