-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathActors.cs
More file actions
32 lines (28 loc) · 1.24 KB
/
Actors.cs
File metadata and controls
32 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Trellis.Authorization;
namespace AuthorizationExample;
/// <summary>
/// Test actors with varying permissions.
/// </summary>
public static class Actors
{
public static readonly Actor Alice = Actor.Create("alice", new HashSet<string> { "Documents.Publish" });
public static readonly Actor Bob = Actor.Create("bob", new HashSet<string>());
public static readonly Actor Charlie = Actor.Create("charlie", new HashSet<string> { "Documents.Publish", "Documents.Delete", "Documents.EditAny" });
public static void PrintActors()
{
Console.WriteLine("Actors:");
Console.WriteLine(" Alice — Owner Permissions: Documents.Publish");
Console.WriteLine(" Bob — Contributor Permissions: (none)");
Console.WriteLine(" Charlie — Admin Permissions: Documents.Publish, Documents.Delete, Documents.EditAny");
Console.WriteLine();
}
}
/// <summary>
/// Simple IActorProvider for console applications.
/// In a web app, this would extract the actor from HttpContext.User.
/// </summary>
public sealed class InMemoryActorProvider(Actor initialActor) : IActorProvider
{
public Actor CurrentActor { get; set; } = initialActor;
public Actor GetCurrentActor() => CurrentActor;
}