using Connected.Entities.Caching; using Connected.Security.Identity; namespace Common.Security.Identity; internal interface IRoleCache : IEntityCacheClient { } internal sealed class RoleCache : EntityCacheClient, IRoleCache { public RoleCache(IEntityCacheContext context) : base(context, Role.CacheKey) { } protected override Task OnInitialized() { /* * Register system or predefined roles. This roles cannot be changed. They differ * from other roles in that they have a negative ids. */ /* * Full control role. This role passed all authorization policies. */ Set(-1, new Role { Id = -1, Name = Roles.FullControl }, TimeSpan.Zero); /* * Implicit role assigned to every authenticated user. */ Set(-2, new Role { Id = -2, Name = Roles.Authenticated }, TimeSpan.Zero); /* * Implicit role assigned to non authenticated user. */ Set(-3, new Role { Id = -3, Name = Roles.Anonymous }, TimeSpan.Zero); /* * Implicit role assigned to every user * regardless if it's authenticated or not. */ Set(-4, new Role { Id = -4, Name = Roles.Everyone }, TimeSpan.Zero); return Task.CompletedTask; } }