feat: harden SaaS authentication and authorization

This commit is contained in:
2026-07-28 12:15:51 +08:00
parent f22f329d33
commit 5d2248efee
123 changed files with 9090 additions and 2822 deletions

View File

@@ -1,15 +1,43 @@
using System.Text.Json;
using Tiku.Application.Security;
using Tiku.Domain.Operations;
namespace Tiku.Application.Backoffice;
public sealed record BackofficeActor(Guid UserId, Guid? TenantId, bool IsPlatform);
public sealed record BackofficeActor(Guid UserId, Guid? TenantId, bool IsPlatform)
{
public static BackofficeActor FromTenantAccess(CurrentAccessSnapshot access)
{
if (access.UserId is not { } userId ||
access.TenantId is not { } tenantId ||
!access.IsCurrentTenantMember)
{
throw new InvalidOperationException("Tenant backoffice actor was not resolved.");
}
return new BackofficeActor(userId, tenantId, false);
}
public static BackofficeActor FromPlatformAccess(CurrentAccessSnapshot access)
{
if (access.UserId is not { } userId || !access.IsUserActive)
{
throw new InvalidOperationException("Platform backoffice actor was not resolved.");
}
return new BackofficeActor(userId, null, true);
}
}
public sealed record BackofficeBootstrap(
IReadOnlyCollection<BackofficePermissionItem> Permissions,
IReadOnlyCollection<BackofficeMenuItem> Menus,
IReadOnlyCollection<BackofficeRoleItem> Roles);
public sealed record BackofficeUiBootstrap(
IReadOnlyCollection<string> PermissionCodes,
IReadOnlyCollection<BackofficeMenuItem> Menus);
public sealed record BackofficePermissionItem(
Guid Id,
string Code,