improve caching for sites with many registered users

This commit is contained in:
sbwalker
2024-03-12 10:27:32 -04:00
parent 7cc328ed3b
commit 0c8dc63085
2 changed files with 31 additions and 5 deletions

View File

@ -1,5 +1,6 @@
using System.Linq;
using System.Security.Claims;
using Oqtane.Shared;
namespace Oqtane.Extensions
{
@ -70,5 +71,17 @@ namespace Oqtane.Extensions
}
return -1;
}
public static bool IsOnlyInRole(this ClaimsPrincipal claimsPrincipal, string role)
{
var identity = claimsPrincipal.Identities.FirstOrDefault(item => item.AuthenticationType == Constants.AuthenticationScheme);
if (identity != null)
{
// check if user has role claim specified and no other role claims
return identity.Claims.Any(item => item.Type == ClaimTypes.Role && item.Value == role) &&
!identity.Claims.Any(item => item.Type == ClaimTypes.Role && item.Value != role);
}
return false;
}
}
}