Record Class SecondFactorLockout

java.lang.Object
java.lang.Record
com.irurueta.authserver.authorization.domain.mfa.SecondFactorLockout
Record Components:
failedCount - consecutive failed attempts, never negative.
lockedUntil - instant until which the second factor is locked, or null when it is not locked.

public record SecondFactorLockout(int failedCount, Instant lockedUntil) extends Record
The failed-attempt state of the second factor of one user.
  • Field Details

    • failedCount

      private final int failedCount
      The field for the failedCount record component.
    • lockedUntil

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

    • SecondFactorLockout

      public SecondFactorLockout(int failedCount, Instant lockedUntil)
      Validates the state.
      Throws:
      IllegalArgumentException - if the counter is negative.
  • Method Details

    • none

      public static SecondFactorLockout none()
      Creates the state of a user with no failed attempts.
      Returns:
      the clean state.
    • isLocked

      public boolean isLocked(Instant now)
      Tells whether the second factor is locked at an instant.
      Parameters:
      now - the instant to check.
      Returns:
      true when a lock exists and has not ended yet.
    • 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.
    • failedCount

      public int failedCount()
      Returns the value of the failedCount record component.
      Returns:
      the value of the failedCount record component
    • lockedUntil

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