mirror of
https://github.com/bitwarden/server.git
synced 2025-04-29 00:32:18 -05:00
Do not use delegate
This commit is contained in:
parent
336228e3b4
commit
5d5fb7fb27
@ -10,11 +10,6 @@ namespace Bit.Api.AdminConsole.Authorization;
|
|||||||
|
|
||||||
public static class OrganizationClaimsExtensions
|
public static class OrganizationClaimsExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// A delegate that returns true if the user has the specified claim type for an organization, false otherwise.
|
|
||||||
/// </summary>
|
|
||||||
private delegate bool HasClaim(string claimType);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a user's claims and returns an object representing their claims for the specified organization.
|
/// Parses a user's claims and returns an object representing their claims for the specified organization.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,9 +42,10 @@ public static class OrganizationClaimsExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="HasClaim"/> delegate specific to the user and organization.
|
/// Returns a function for evaluating claims for the specified user and organizationId.
|
||||||
|
/// The function returns true if the claim type exists and false otherwise.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static HasClaim GetClaimsParser(ClaimsPrincipal user, Guid organizationId)
|
private static Func<string, bool> GetClaimsParser(ClaimsPrincipal user, Guid organizationId)
|
||||||
{
|
{
|
||||||
// Group claims by ClaimType
|
// Group claims by ClaimType
|
||||||
var claimsDict = user.Claims
|
var claimsDict = user.Claims
|
||||||
@ -79,7 +75,7 @@ public static class OrganizationClaimsExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static OrganizationUserType? GetRoleFromClaims(HasClaim hasClaim)
|
private static OrganizationUserType? GetRoleFromClaims(Func<string, bool> hasClaim)
|
||||||
{
|
{
|
||||||
if (hasClaim(Claims.OrganizationOwner))
|
if (hasClaim(Claims.OrganizationOwner))
|
||||||
{
|
{
|
||||||
@ -104,7 +100,7 @@ public static class OrganizationClaimsExtensions
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Permissions GetPermissionsFromClaims(HasClaim hasClaim)
|
private static Permissions GetPermissionsFromClaims(Func<string, bool> hasClaim)
|
||||||
=> new()
|
=> new()
|
||||||
{
|
{
|
||||||
AccessEventLogs = hasClaim(Claims.CustomPermissions.AccessEventLogs),
|
AccessEventLogs = hasClaim(Claims.CustomPermissions.AccessEventLogs),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user