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 Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe field for theattemptsrecord component.private final StringThe field for thecodeHashrecord component.private final InstantThe field for theexpiresAtrecord component.private final PhoneNumberThe field for thephonerecord component.private final UUIDThe field for theuserIdrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionPhoneVerification(UUID userId, PhoneNumber phone, String codeHash, int attempts, Instant expiresAt) Validates the verification. -
Method Summary
Modifier and TypeMethodDescriptionintattempts()Returns the value of theattemptsrecord component.codeHash()Returns the value of thecodeHashrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theexpiresAtrecord component.final inthashCode()Returns a hash code value for this object.booleanisExpiredAt(Instant now) Tells whether the verification has expired.phone()Returns the value of thephonerecord component.final StringtoString()Returns a string representation of this record class.userId()Returns the value of theuserIdrecord component.
-
Field Details
-
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
Tells whether the verification has expired.- Parameters:
now- current instant.- Returns:
truewhen it expires at or beforenow.
-
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
userId
Returns the value of theuserIdrecord component.- Returns:
- the value of the
userIdrecord component
-
phone
Returns the value of thephonerecord component.- Returns:
- the value of the
phonerecord component
-
codeHash
Returns the value of thecodeHashrecord component.- Returns:
- the value of the
codeHashrecord component
-
attempts
public int attempts()Returns the value of theattemptsrecord component.- Returns:
- the value of the
attemptsrecord component
-
expiresAt
Returns the value of theexpiresAtrecord component.- Returns:
- the value of the
expiresAtrecord component
-