Record Class PhoneVerification

java.lang.Object
java.lang.Record
com.irurueta.authserver.authorization.domain.sms.PhoneVerification
Record Components:
userId - identifier of the user verifying the number.
phone - the number being verified.
codeHash - hash of the code sent, never the code itself.
attempts - number of wrong submissions so far.
expiresAt - instant after which the code is no longer valid.

public record PhoneVerification(UUID userId, PhoneNumber phone, String codeHash, int attempts, Instant expiresAt) extends Record
A pending verification of a phone number: the code that was sent to it, hashed, until the user types it.
  • Field Details

    • userId

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

      private final PhoneNumber phone
      The field for the phone record component.
    • codeHash

      private final String codeHash
      The field for the codeHash 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.
  • Constructor Details

    • PhoneVerification

      public PhoneVerification(UUID userId, PhoneNumber phone, String codeHash, int attempts, Instant expiresAt)
      Validates the verification.
      Throws:
      IllegalArgumentException - if the user, number or expiry is missing, the hash is blank or the attempts are negative.
  • Method Details

    • isExpiredAt

      public boolean isExpiredAt(Instant now)
      Tells whether the verification has expired.
      Parameters:
      now - current instant.
      Returns:
      true when it 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.
    • userId

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

      public PhoneNumber phone()
      Returns the value of the phone record component.
      Returns:
      the value of the phone record component
    • codeHash

      public String codeHash()
      Returns the value of the codeHash record component.
      Returns:
      the value of the codeHash 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