Record Class TotpCredential

java.lang.Object
java.lang.Record
com.irurueta.authserver.authorization.domain.totp.TotpCredential
Record Components:
userId - identifier of the user the credential belongs to.
encryptedSecret - the secret, encrypted at rest; copied on the way in and on the way out.
confirmed - whether the user proved possession by entering a first valid code.
lastUsedStep - time step of the last accepted code, or NEVER_USED; later codes must be newer.
createdAt - instant at which the credential was created.

public record TotpCredential(UUID userId, byte[] encryptedSecret, boolean confirmed, long lastUsedStep, Instant createdAt) extends Record
The TOTP credential of one user. The secret is only ever held encrypted.
  • Field Details

    • userId

      private final UUID userId
      The field for the userId record component.
    • encryptedSecret

      private final byte[] encryptedSecret
      The field for the encryptedSecret record component.
    • confirmed

      private final boolean confirmed
      The field for the confirmed record component.
    • lastUsedStep

      private final long lastUsedStep
      The field for the lastUsedStep record component.
    • createdAt

      private final Instant createdAt
      The field for the createdAt record component.
    • NEVER_USED

      public static final long NEVER_USED
      Value of the last used step of a credential that has not accepted any code yet.
      See Also:
  • Constructor Details

    • TotpCredential

      public TotpCredential(UUID userId, byte[] encryptedSecret, boolean confirmed, long lastUsedStep, Instant createdAt)
      Validates the credential and copies the secret.
      Throws:
      IllegalArgumentException - if the user, the secret or the creation instant is missing or empty, or the step is lower than NEVER_USED.
  • Method Details

    • encryptedSecret

      public byte[] encryptedSecret()
      Gives the encrypted secret.
      Returns:
      a copy of the encrypted secret.
    • equals

      public boolean equals(Object other)
      Compares credentials by value, comparing the secret by content.
      Specified by:
      equals in class Record
      Parameters:
      other - the object to compare with.
      Returns:
      true when every component is equal.
    • hashCode

      public int hashCode()
      Computes a hash consistent with equals(Object).
      Specified by:
      hashCode in class Record
      Returns:
      the hash code.
    • toString

      public String toString()
      Describes the credential without its secret.
      Specified by:
      toString in class Record
      Returns:
      a text that never includes the secret.
    • userId

      public UUID userId()
      Returns the value of the userId record component.
      Returns:
      the value of the userId record component
    • confirmed

      public boolean confirmed()
      Returns the value of the confirmed record component.
      Returns:
      the value of the confirmed record component
    • lastUsedStep

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

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