Record Class CredentialRecord

java.lang.Object
java.lang.Record
com.svenruppert.jsentinel.credential.store.CredentialRecord
Record Components:
username - case-sensitive identifier; never null or blank
encodedHash - full Phase-1a envelope as stored
status - current lifecycle status
version - optimistic-lock counter, starts at 1
createdAt - when the record was first written
updatedAt - when the record was last written

public record CredentialRecord(String username, String encodedHash, CredentialStatus status, long version, Instant createdAt, Instant updatedAt) extends Record
Persisted credential row, returned by CredentialStore reads and used as the compare-and-swap witness on writes.

The version field is a monotonically increasing optimistic-lock counter: every successful update returns a new record with version + 1. CAS callers normally hand back the encodedHash as the witness, but the version field is exposed for adapters that prefer numeric optimistic-lock comparisons.

toString() never exposes encodedHash() (CWE-522 / CWE-209).

  • Constructor Details

    • CredentialRecord

      public CredentialRecord(String username, String encodedHash, CredentialStatus status, long version, Instant createdAt, Instant updatedAt)
      Creates an instance of a CredentialRecord record class.
      Parameters:
      username - the value for the username record component
      encodedHash - the value for the encodedHash record component
      status - the value for the status record component
      version - the value for the version record component
      createdAt - the value for the createdAt record component
      updatedAt - the value for the updatedAt record component
  • Method Details

    • initial

      public static CredentialRecord initial(String username, String encodedHash, CredentialStatus status, Instant now)
      Convenience: build a fresh record at version 1 with timestamps equal to now.
    • withHash

      public CredentialRecord withHash(String newEncodedHash, Instant when)
      Returns a new record with the supplied hash and timestamp, version bumped by one.
    • withStatus

      public CredentialRecord withStatus(CredentialStatus newStatus, Instant when)
      Returns a new record with the supplied status and timestamp, version bumped by one.
    • toString

      public 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.
    • username

      public String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • encodedHash

      public String encodedHash()
      Returns the value of the encodedHash record component.
      Returns:
      the value of the encodedHash record component
    • status

      public CredentialStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • version

      public long version()
      Returns the value of the version record component.
      Returns:
      the value of the version record component
    • createdAt

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

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