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 Summary
FieldsModifier and TypeFieldDescriptionprivate final intThe field for theattemptsrecord component.private final StringThe field for thebindingIdrecord component.private final OttChannelThe field for thechannelrecord component.private final StringThe field for thecodeHashrecord component.private final InstantThe field for thecreatedAtrecord component.private final InstantThe field for theexpiresAtrecord component.private final UUIDThe field for theidrecord component.private final OttPurposeThe field for thepurposerecord component.private final StringThe field for theusernamerecord component. -
Constructor Summary
ConstructorsConstructorDescriptionOneTimeCode(UUID id, String username, OttChannel channel, OttPurpose purpose, String codeHash, String bindingId, int attempts, Instant expiresAt, Instant createdAt) Validates the code. -
Method Summary
Modifier and TypeMethodDescriptionintattempts()Returns the value of theattemptsrecord component.Returns the value of thebindingIdrecord component.channel()Returns the value of thechannelrecord component.codeHash()Returns the value of thecodeHashrecord component.Returns the value of thecreatedAtrecord 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.id()Returns the value of theidrecord component.booleanisExpiredAt(Instant now) Tells whether the code has expired.purpose()Returns the value of thepurposerecord component.final StringtoString()Returns a string representation of this record class.username()Returns the value of theusernamerecord component.
-
Field Details
-
id
The field for theidrecord component. -
username
The field for theusernamerecord component. -
channel
The field for thechannelrecord component. -
purpose
The field for thepurposerecord component. -
codeHash
The field for thecodeHashrecord component. -
bindingId
The field for thebindingIdrecord component. -
attempts
private final int attemptsThe field for theattemptsrecord component. -
expiresAt
The field for theexpiresAtrecord component. -
createdAt
The field for thecreatedAtrecord 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
Tells whether the code has expired.- Parameters:
now- current instant.- Returns:
truewhen the code 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 '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
username
Returns the value of theusernamerecord component.- Returns:
- the value of the
usernamerecord component
-
channel
Returns the value of thechannelrecord component.- Returns:
- the value of the
channelrecord component
-
purpose
Returns the value of thepurposerecord component.- Returns:
- the value of the
purposerecord component
-
codeHash
Returns the value of thecodeHashrecord component.- Returns:
- the value of the
codeHashrecord component
-
bindingId
Returns the value of thebindingIdrecord component.- Returns:
- the value of the
bindingIdrecord 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
-
createdAt
Returns the value of thecreatedAtrecord component.- Returns:
- the value of the
createdAtrecord component
-