Record Class SecurityContext

java.lang.Object
java.lang.Record
org.j7m.middleware.security.api.SecurityContext
Record Components:
principal - caller principal
callerRuntimeId - caller runtime id
trustDomain - caller trust domain
credential - credential descriptor
correlationId - correlation id
invocationId - invocation id
remoteEndpoint - remote endpoint when known
authenticated - whether caller authentication succeeded
transportSecurityLevel - transport security level
roles - caller roles
requestMetadata - safe request metadata
createdAt - context creation time
All Implemented Interfaces:
Serializable

public record SecurityContext(Principal principal, String callerRuntimeId, TrustDomain trustDomain, Credential credential, String correlationId, String invocationId, String remoteEndpoint, boolean authenticated, TransportSecurityLevel transportSecurityLevel, Set<String> roles, Map<String,String> requestMetadata, Instant createdAt) extends Record implements Serializable
Immutable per-operation security context.
See Also:
  • Constructor Details

  • Method Details

    • system

      public static SecurityContext system(String runtimeId)
      Returns a development context for a runtime.
      Parameters:
      runtimeId - runtime id
      Returns:
      system context
    • toMetadata

      public Map<String,String> toMetadata()
      Encodes this context into invocation metadata.
      Returns:
      metadata map
    • fromInvocationOptions

      public static SecurityContext fromInvocationOptions(InvocationOptions options, String fallbackRuntimeId)
      Decodes an untrusted security context from invocation options.

      Public invocation metadata is caller controlled. Keys in the sec. namespace are retained only as request metadata for audit redaction and are not trusted as authentication, principal, role, credential, trust-domain, or transport-security evidence.

      Parameters:
      options - invocation options
      fallbackRuntimeId - fallback caller runtime
      Returns:
      decoded context
    • fromTrustedBoundary

      public static SecurityContext fromTrustedBoundary(SecurityContext trusted, InvocationOptions options)
      Returns a trusted transport context with invocation metadata attached.

      This method is intended only for local or transport-authenticated boundaries that have already validated peer identity outside public invocation metadata.

      Parameters:
      trusted - trusted context supplied by the transport or local boundary
      options - invocation options whose public metadata remains untrusted
      Returns:
      trusted context for dispatch
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • principal

      public Principal principal()
      Returns the value of the principal record component.
      Returns:
      the value of the principal record component
    • callerRuntimeId

      public String callerRuntimeId()
      Returns the value of the callerRuntimeId record component.
      Returns:
      the value of the callerRuntimeId record component
    • trustDomain

      public TrustDomain trustDomain()
      Returns the value of the trustDomain record component.
      Returns:
      the value of the trustDomain record component
    • credential

      public Credential credential()
      Returns the value of the credential record component.
      Returns:
      the value of the credential record component
    • correlationId

      public String correlationId()
      Returns the value of the correlationId record component.
      Returns:
      the value of the correlationId record component
    • invocationId

      public String invocationId()
      Returns the value of the invocationId record component.
      Returns:
      the value of the invocationId record component
    • remoteEndpoint

      public String remoteEndpoint()
      Returns the value of the remoteEndpoint record component.
      Returns:
      the value of the remoteEndpoint record component
    • authenticated

      public boolean authenticated()
      Returns the value of the authenticated record component.
      Returns:
      the value of the authenticated record component
    • transportSecurityLevel

      public TransportSecurityLevel transportSecurityLevel()
      Returns the value of the transportSecurityLevel record component.
      Returns:
      the value of the transportSecurityLevel record component
    • roles

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

      public Map<String,String> requestMetadata()
      Returns the value of the requestMetadata record component.
      Returns:
      the value of the requestMetadata record component
    • createdAt

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