Record Class OneTimeCode

java.lang.Object
java.lang.Record
com.irurueta.authserver.authorization.domain.ott.OneTimeCode
Record Components:
id - identifier of the stored code.
username - user name of the account the code was issued to.
channel - channel the code was delivered through.
purpose - what the code is used for.
codeHash - hash of the code, never the code itself.
bindingId - identifier binding the code to the requesting browser session.
attempts - number of wrong submissions so far.
expiresAt - instant after which the code is no longer valid.
createdAt - instant at which the code was issued.

public record OneTimeCode(UUID id, String username, OttChannel channel, OttPurpose purpose, String codeHash, String bindingId, int attempts, Instant expiresAt, Instant createdAt) extends Record
A numeric one-time code that was issued to a user. Only the hash of the code is kept. The binding identifier is held by the browser that requested the code (in its session), so the code only works there.
  • Field Details

    • id

      private final UUID id
      The field for the id record component.
    • username

      private final String username
      The field for the username record component.
    • channel

      private final OttChannel channel
      The field for the channel record component.
    • purpose

      private final OttPurpose purpose
      The field for the purpose record component.
    • codeHash

      private final String codeHash
      The field for the codeHash record component.
    • bindingId

      private final String bindingId
      The field for the bindingId record component.
    • attempts

      private final int attempts
      The field for the attempts record component.
    • expiresAt

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

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

    • OneTimeCode

      public OneTimeCode(UUID id, String username, OttChannel channel, OttPurpose purpose, String codeHash, String bindingId, int attempts, Instant expiresAt, Instant createdAt)
      Validates the code.
      Throws:
      IllegalArgumentException - if the id, channel, purpose or an instant is missing, the user name, hash or binding is blank, the attempts are negative or the code expires before it was created.
  • Method Details

    • isExpiredAt

      public boolean isExpiredAt(Instant now)
      Tells whether the code has expired.
      Parameters:
      now - current instant.
      Returns:
      true when the code expires at or before now.
    • 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 '=='.
      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.
    • id

      public UUID id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • username

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

      public OttChannel channel()
      Returns the value of the channel record component.
      Returns:
      the value of the channel record component
    • purpose

      public OttPurpose purpose()
      Returns the value of the purpose record component.
      Returns:
      the value of the purpose record component
    • codeHash

      public String codeHash()
      Returns the value of the codeHash record component.
      Returns:
      the value of the codeHash record component
    • bindingId

      public String bindingId()
      Returns the value of the bindingId record component.
      Returns:
      the value of the bindingId record component
    • attempts

      public int attempts()
      Returns the value of the attempts record component.
      Returns:
      the value of the attempts record component
    • expiresAt

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

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