mirror of
https://github.com/bitwarden/server.git
synced 2025-04-26 23:32:19 -05:00

- Add Authorize<T> attribute - Add IOrganizationRequirement and example implementation - Add OrganizationRequirementHandler - Add extension methods (replacing ICurrentContext) - Move custom permissions claim definitions --- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
21 lines
617 B
C#
21 lines
617 B
C#
#nullable enable
|
|
|
|
using Bit.Core.Context;
|
|
using Bit.Core.Enums;
|
|
|
|
namespace Bit.Api.AdminConsole.Authorization.Requirements;
|
|
|
|
public class ManageUsersRequirement : IOrganizationRequirement
|
|
{
|
|
public async Task<bool> AuthorizeAsync(
|
|
CurrentContextOrganization? organizationClaims,
|
|
Func<Task<bool>> isProviderUserForOrg)
|
|
=> organizationClaims switch
|
|
{
|
|
{ Type: OrganizationUserType.Owner } => true,
|
|
{ Type: OrganizationUserType.Admin } => true,
|
|
{ Permissions.ManageUsers: true } => true,
|
|
_ => await isProviderUserForOrg()
|
|
};
|
|
}
|