mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 17:12:49 -05:00
[AC-1139] Modified CollectionsController.Get to check access before getting collections
This commit is contained in:
@ -136,9 +136,12 @@ public class CollectionsController : Controller
|
|||||||
|
|
||||||
if (FlexibleCollectionsIsEnabled)
|
if (FlexibleCollectionsIsEnabled)
|
||||||
{
|
{
|
||||||
orgCollections = await _collectionRepository.GetManyByOrganizationIdAsync(orgId);
|
var readAll = (await _authorizationService.AuthorizeAsync(User, null, CollectionOperations.ReadAll(orgId))).Succeeded;
|
||||||
var readAllAuthorized = (await _authorizationService.AuthorizeAsync(User, orgCollections, CollectionOperations.ReadAll)).Succeeded;
|
if (readAll)
|
||||||
if (!readAllAuthorized)
|
{
|
||||||
|
orgCollections = await _collectionRepository.GetManyByOrganizationIdAsync(orgId);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
|
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
|
||||||
orgCollections = collections.Where(c => c.OrganizationId == orgId);
|
orgCollections = collections.Where(c => c.OrganizationId == orgId);
|
||||||
|
@ -2,13 +2,26 @@
|
|||||||
|
|
||||||
namespace Bit.Api.Vault.AuthorizationHandlers.Collections;
|
namespace Bit.Api.Vault.AuthorizationHandlers.Collections;
|
||||||
|
|
||||||
public class CollectionOperationRequirement : OperationAuthorizationRequirement { }
|
public class CollectionOperationRequirement : OperationAuthorizationRequirement
|
||||||
|
{
|
||||||
|
public Guid OrganizationId { get; set; }
|
||||||
|
|
||||||
|
public CollectionOperationRequirement() { }
|
||||||
|
|
||||||
|
public CollectionOperationRequirement(string name, Guid organizationId)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
OrganizationId = organizationId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class CollectionOperations
|
public static class CollectionOperations
|
||||||
{
|
{
|
||||||
public static readonly CollectionOperationRequirement Create = new() { Name = nameof(Create) };
|
public static readonly CollectionOperationRequirement Create = new() { Name = nameof(Create) };
|
||||||
public static readonly CollectionOperationRequirement ReadAll = new() { Name = nameof(ReadAll) };
|
public static CollectionOperationRequirement ReadAll(Guid organizationId)
|
||||||
public static readonly CollectionOperationRequirement Update = new() { Name = nameof(Update) };
|
{
|
||||||
|
return new CollectionOperationRequirement(nameof(ReadAll), organizationId);
|
||||||
|
}
|
||||||
public static readonly CollectionOperationRequirement Delete = new() { Name = nameof(Delete) };
|
public static readonly CollectionOperationRequirement Delete = new() { Name = nameof(Delete) };
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The operation that represents creating, updating, or removing collection access.
|
/// The operation that represents creating, updating, or removing collection access.
|
||||||
|
Reference in New Issue
Block a user