| | | 1 | | using System.Security.Claims; |
| | | 2 | | using Elsa.Common; |
| | | 3 | | using Elsa.Common.Multitenancy; |
| | | 4 | | using Elsa.Identity.Notifications; |
| | | 5 | | using Elsa.Mediator.Contracts; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Identity.Services; |
| | | 9 | | |
| | | 10 | | /// <summary>Publishes role and assignment changes for audit subscribers.</summary> |
| | | 11 | | /// <remarks> |
| | | 12 | | /// Follows ADR 0007: typed, redacted notifications over the mediator, with no audit persistence owned |
| | | 13 | | /// here. A future audit module subscribes, stores, and sets its own retention policy without coupling |
| | | 14 | | /// identity administration to an audit database. |
| | | 15 | | /// </remarks> |
| | | 16 | | [UsedImplicitly] |
| | 22 | 17 | | public class RoleSecurityNotifier(INotificationSender notificationSender, ITenantAccessor tenantAccessor, ISystemClock c |
| | | 18 | | { |
| | | 19 | | /// <summary>Publishes a role creation, update, or deletion.</summary> |
| | | 20 | | public Task RoleChangedAsync(ClaimsPrincipal? actor, string operation, string roleId, string roleName, IReadOnlyColl |
| | 4 | 21 | | notificationSender.SendAsync( |
| | 4 | 22 | | new RoleChanged(Context(actor, $"Role '{roleName}' {operation}."), operation, roleId, roleName, permissions) |
| | 4 | 23 | | cancellationToken); |
| | | 24 | | |
| | | 25 | | /// <summary>Publishes a change to the roles a user holds.</summary> |
| | | 26 | | public Task UserRolesChangedAsync(ClaimsPrincipal? actor, string userId, IReadOnlyCollection<string> assigned, IRead |
| | 0 | 27 | | notificationSender.SendAsync( |
| | 0 | 28 | | new UserRoleAssignmentChanged(Context(actor, $"Roles changed for user '{userId}': {assigned.Count} assigned, |
| | 0 | 29 | | cancellationToken); |
| | | 30 | | |
| | | 31 | | private RoleSecurityEventContext Context(ClaimsPrincipal? actor, string summary) => |
| | 4 | 32 | | new(actor?.Identity?.Name, tenantAccessor.TenantId, clock.UtcNow, summary); |
| | | 33 | | } |