Record Class AuthorityScope

java.lang.Object
java.lang.Record
com.tnsai.accountability.AuthorityScope
Record Components:
allowedActions - whitelist of action types this scope permits; empty set = unrestricted (caller chose not to narrow)
targetSystems - whitelist of target system identifiers (e.g. "github.com/owner/repo"); empty set = unrestricted
spendCeilingUSD - optional hard cap on cumulative spend within the validity window; empty = no cap
validFor - how long the scope remains in force from issuedAt; consumers compare wall-clock against expiresAt() to decide expiry. null = never expires (see permanent())
issuedAt - when the scope was minted

public record AuthorityScope(Set<ActionType> allowedActions, Set<String> targetSystems, Optional<BigDecimal> spendCeilingUSD, Duration validFor, Instant issuedAt) extends Record
Pre-declared bounds on what an agent is allowed to do (TNS-298). Attached to every AgentLiabilityRecord the framework emits so auditors can answer "did this agent stay within its declared authority?" without re-deriving the answer from observability data.

Scope is inclusive — an empty allowedActions means "any action type", an empty targetSystems means "any target". Spend and validity windows are explicit limits when present.

Since:
0.10.0 (TNS-298)
  • Constructor Details

  • Method Details

    • expiresAt

      public Instant expiresAt()
      Wall-clock instant the scope ceases to be valid, or Instant.MAX for a permanent() (no-expiry) scope.
    • isExpired

      public boolean isExpired(Instant now)
      true when now falls strictly past expiresAt(). Always false for a permanent() scope.
    • permits

      public boolean permits(ActionType action)
      Returns:
      true when action is permitted (whitelist empty = permissive; whitelist populated = membership check).
    • permitsTarget

      public boolean permitsTarget(String targetSystem)
      Returns:
      true when targetSystem is permitted (whitelist empty = permissive; populated = membership).
    • unrestricted

      public static AuthorityScope unrestricted(Duration validFor)
      Convenience: maximally-permissive scope; useful as a development default.
    • permanent

      public static AuthorityScope permanent()
      Convenience: a maximally-permissive scope that never expires. Useful for long-lived server beans where a finite unrestricted(Duration) window would otherwise need a sentinel like Duration.ofDays(3650). expiresAt() returns Instant.MAX; isExpired(Instant) is always false.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • allowedActions

      public Set<ActionType> allowedActions()
      Returns the value of the allowedActions record component.
      Returns:
      the value of the allowedActions record component
    • targetSystems

      public Set<String> targetSystems()
      Returns the value of the targetSystems record component.
      Returns:
      the value of the targetSystems record component
    • spendCeilingUSD

      public Optional<BigDecimal> spendCeilingUSD()
      Returns the value of the spendCeilingUSD record component.
      Returns:
      the value of the spendCeilingUSD record component
    • validFor

      public Duration validFor()
      Returns the value of the validFor record component.
      Returns:
      the value of the validFor record component
    • issuedAt

      public Instant issuedAt()
      Returns the value of the issuedAt record component.
      Returns:
      the value of the issuedAt record component