Record Class Subject

java.lang.Object
java.lang.Record
io.kroxylicious.proxy.authentication.Subject
Record Components:
principals - the set of identifiers associated with this subject.

public record Subject(Set<Principal> principals) extends Record

Represents an actor in the system. Subjects are composed of a possibly-empty set of identifiers represented as Principal instances. An anonymous actor is represented by a Subject with an empty set of principals. As a convenience, anonymous() returns such a subject.

The principals included in a subject might comprise the following:

  • information proven by a client, such as a SASL authorized id,
  • information known about the client, such as the remote peer's IP address,
  • information obtained about the client from a trusted source, such as lookup up role or group information from a directory.
  • Constructor Details

    • Subject

      public Subject(Principal... principals)
      Creates a subject from the given principals.
      Parameters:
      principals - the principals
    • Subject

      public Subject(Set<Principal> principals)
      Creates a subject from the given principal set. Validates that non-empty subjects have exactly one User principal.
      Parameters:
      principals - the principals
  • Method Details

    • anonymous

      public static Subject anonymous()
      Returns the anonymous subject (no principals).
      Returns:
      the anonymous subject
    • uniquePrincipalOfType

      public <P extends Principal> Optional<P> uniquePrincipalOfType(Class<P> uniquePrincipalType)
      Returns the unique principal of the given type, if present.
      Type Parameters:
      P - the principal type
      Parameters:
      uniquePrincipalType - the principal type, which must be annotated with Unique
      Returns:
      the principal, or empty
    • isAnonymous

      public boolean isAnonymous()
      Returns whether this is the anonymous subject.
      Returns:
      true if this subject has no principals
    • allPrincipalsOfType

      public <P extends Principal> Set<P> allPrincipalsOfType(Class<P> principalType)
      Returns all principals of the given type.
      Type Parameters:
      P - the principal type
      Parameters:
      principalType - the principal type
      Returns:
      the matching principals
    • 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.
    • principals

      public Set<Principal> principals()
      Returns the value of the principals record component.
      Returns:
      the value of the principals record component