using ZB.MOM.WW.MxGateway.Server.Security.Authentication; using ZB.MOM.WW.MxGateway.Server.Sessions; namespace ZB.MOM.WW.MxGateway.Server.Security.Authorization; public interface IConstraintEnforcer { /// /// Gets a value indicating whether any read constraint applies to an identity at all, so a /// bulk caller can hoist the question out of its per-item loop. /// /// The API key identity. /// when at least one read constraint applies; otherwise . /// /// Every per-item / call for /// an unconstrained identity allows the item, so skipping the loop removes work without /// changing a decision. The default implementation answers — an /// implementation that does not model constraints (test doubles, allow-all enforcers) keeps /// being consulted per item rather than being silently bypassed. /// bool HasReadConstraints(ApiKeyIdentity? identity) => true; /// /// Gets a value indicating whether any write constraint applies to an identity at all, the /// write-side counterpart of . /// /// The API key identity. /// when at least one write constraint applies; otherwise . /// The same conservative default as applies. bool HasWriteConstraints(ApiKeyIdentity? identity) => true; /// Checks whether a read constraint is satisfied for a tag address. /// The API key identity. /// Tag address to check. /// Token to observe for cancellation. /// The constraint failure details if denied; otherwise null. Task CheckReadTagAsync( ApiKeyIdentity? identity, string tagAddress, CancellationToken cancellationToken); /// Checks whether a read constraint is satisfied for an item handle. /// The API key identity. /// The gateway session. /// The MXAccess server handle. /// The MXAccess item handle. /// Token to observe for cancellation. /// The constraint failure details if denied; otherwise null. Task CheckReadHandleAsync( ApiKeyIdentity? identity, GatewaySession session, int serverHandle, int itemHandle, CancellationToken cancellationToken); /// Checks whether a write constraint is satisfied for an item handle. /// The API key identity. /// The gateway session. /// The MXAccess server handle. /// The MXAccess item handle. /// Token to observe for cancellation. /// The constraint failure details if denied; otherwise null. Task CheckWriteHandleAsync( ApiKeyIdentity? identity, GatewaySession session, int serverHandle, int itemHandle, CancellationToken cancellationToken); /// Records a constraint denial for audit and metrics. /// The API key identity. /// The kind of command denied. /// The target of the denied command. /// The constraint failure details. /// /// The per-request client correlation id, if any. Stored on the audit record's /// CorrelationId when it parses as a GUID; otherwise left null. /// /// Token to observe for cancellation. /// A task that represents the asynchronous operation. Task RecordDenialAsync( ApiKeyIdentity? identity, string commandKind, string target, ConstraintFailure failure, string? correlationId, CancellationToken cancellationToken); }