namespace HopFrame.Security.Authorization;
internal static class PermissionValidator {
///
/// Checks for the user to have the specified permission
/// Permission system:
/// - "*" -> all rights
/// - "group.[name]" -> group member
/// - "[namespace].[name]" -> single permission
/// - "[namespace].*" -> all permissions in the namespace
///
/// The permission the user needs
/// All the permissions the user has (includes group permissions)
///
public static bool IncludesPermission(string permission, string[] permissions) {
if (permission == "*") return true;
if (permissions.Contains(permission)) return true;
foreach (var perm in permissions) {
if (!perm.EndsWith(".*")) continue;
var permissionGroup = perm.Replace(".*", "");
if (permission.StartsWith(permissionGroup)) return true;
}
return false;
}
}