| | | 1 | | using AsiBackbone.Core.Acknowledgments; |
| | | 2 | | using AsiBackbone.Core.Actors; |
| | | 3 | | |
| | | 4 | | namespace AsiBackbone.AspNetCore.Acknowledgments; |
| | | 5 | | |
| | | 6 | | internal static class AcknowledgmentActorBinding |
| | | 7 | | { |
| | | 8 | | public const string FailureCode = "acknowledgment.challenge.actor_unbound"; |
| | | 9 | | |
| | | 10 | | public const string FailureMessage = |
| | | 11 | | "Acknowledgment challenges require a known, authenticated actor with a distinct host-provided identity."; |
| | | 12 | | |
| | | 13 | | public static bool IsSufficient(IGovernanceActorContext actor) |
| | | 14 | | { |
| | 52 | 15 | | ArgumentNullException.ThrowIfNull(actor); |
| | | 16 | | |
| | 52 | 17 | | return actor.IsKnown |
| | 52 | 18 | | && actor.IsAuthenticated |
| | 52 | 19 | | && HasDistinctIdentity(actor.ActorId, actor.ActorType); |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | public static bool IsSufficient(AcknowledgmentRequest request) |
| | | 23 | | { |
| | 18 | 24 | | ArgumentNullException.ThrowIfNull(request); |
| | | 25 | | |
| | 18 | 26 | | return HasDistinctIdentity(request.ActorId, request.ActorType); |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | private static bool HasDistinctIdentity(string? actorId, GovernanceActorType actorType) |
| | | 30 | | { |
| | 64 | 31 | | return actorType is not GovernanceActorType.Unknown |
| | 64 | 32 | | && !string.IsNullOrWhiteSpace(actorId) |
| | 64 | 33 | | && !string.Equals( |
| | 64 | 34 | | actorId.Trim(), |
| | 64 | 35 | | GovernanceActorContext.UnknownActorId, |
| | 64 | 36 | | StringComparison.Ordinal); |
| | | 37 | | } |
| | | 38 | | } |