-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-12479] - Adding group-details endpoint (#4959)
✨ Added group-details endpoint. Moved group auth handler to AdminConsole directory. --------- Co-authored-by: Matt Bishop <[email protected]>
- Loading branch information
1 parent
25afd50
commit f2bf9ea
Showing
16 changed files
with
323 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/Api/Vault/AuthorizationHandlers/Groups/GroupOperations.cs
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupAuthorizationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#nullable enable | ||
using Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization; | ||
using Bit.Core.Context; | ||
using Bit.Core.Enums; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Groups.Authorization; | ||
|
||
public class GroupAuthorizationHandler(ICurrentContext currentContext) | ||
: AuthorizationHandler<GroupOperationRequirement, OrganizationScope> | ||
{ | ||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, | ||
GroupOperationRequirement requirement, OrganizationScope organizationScope) | ||
{ | ||
var authorized = requirement switch | ||
{ | ||
not null when requirement.Name == nameof(GroupOperations.ReadAll) => | ||
await CanReadAllAsync(organizationScope), | ||
not null when requirement.Name == nameof(GroupOperations.ReadAllDetails) => | ||
await CanViewGroupDetailsAsync(organizationScope), | ||
_ => false | ||
}; | ||
|
||
if (requirement is not null && authorized) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
} | ||
|
||
private async Task<bool> CanReadAllAsync(OrganizationScope organizationScope) => | ||
currentContext.GetOrganization(organizationScope) is not null | ||
|| await currentContext.ProviderUserForOrgAsync(organizationScope); | ||
|
||
private async Task<bool> CanViewGroupDetailsAsync(OrganizationScope organizationScope) => | ||
currentContext.GetOrganization(organizationScope) is | ||
{ Type: OrganizationUserType.Owner } or | ||
{ Type: OrganizationUserType.Admin } or | ||
{ | ||
Permissions: { ManageGroups: true } or | ||
{ ManageUsers: true } | ||
} || | ||
await currentContext.ProviderUserForOrgAsync(organizationScope); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Authorization.Infrastructure; | ||
|
||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Groups.Authorization; | ||
|
||
public class GroupOperationRequirement : OperationAuthorizationRequirement | ||
{ | ||
public GroupOperationRequirement(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
|
||
public static class GroupOperations | ||
{ | ||
public static readonly GroupOperationRequirement ReadAll = new(nameof(ReadAll)); | ||
public static readonly GroupOperationRequirement ReadAllDetails = new(nameof(ReadAllDetails)); | ||
} |
1 change: 1 addition & 0 deletions
1
...atures/OrganizationUsers/Authorization/OrganizationUserUserDetailsAuthorizationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
...es/OrganizationUsers/Authorization/OrganizationUserUserMiniDetailsAuthorizationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nUsers/Authorization/OrganizationScope.cs → ...Shared/Authorization/OrganizationScope.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.