java.lang.Object
com.irurueta.authserver.authorization.domain.ott.OttPolicy

public final class OttPolicy extends Object
The rules of one-time tokens: how long each kind lives, how long a code is and how many wrong submissions are tolerated. It is pure: it knows nothing about storage or delivery.
  • Field Details

    • codeLength

      private final int codeLength
      Length of the numeric code, in digits.
    • codeTtl

      private final Duration codeTtl
      Lifetime of a numeric code.
    • linkTtl

      private final Duration linkTtl
      Lifetime of a magic link.
    • maxAttempts

      private final int maxAttempts
      Wrong submissions tolerated before a code is rejected for good.
  • Constructor Details

    • OttPolicy

      public OttPolicy(int codeLength, Duration codeTtl, Duration linkTtl, int maxAttempts)
      Creates the policy.
      Parameters:
      codeLength - length of the numeric code, in digits; positive.
      codeTtl - lifetime of a numeric code; positive.
      linkTtl - lifetime of a magic link; positive.
      maxAttempts - wrong submissions tolerated per code; positive.
      Throws:
      IllegalArgumentException - if a number is not positive or a lifetime is missing, zero or negative.
  • Method Details

    • codeLength

      public int codeLength()
      Gets the length of the numeric code.
      Returns:
      number of digits.
    • ttl

      public Duration ttl(OttKind kind)
      Gets the lifetime of a token of a kind.
      Parameters:
      kind - kind of token.
      Returns:
      the lifetime.
    • maxAttempts

      public int maxAttempts()
      Gets the wrong submissions tolerated per code.
      Returns:
      the limit.
    • isExhausted

      public boolean isExhausted(int attempts)
      Tells whether a code has used up its attempts.
      Parameters:
      attempts - wrong submissions so far.
      Returns:
      true when attempts reaches the limit.
    • requirePositive

      private static void requirePositive(Duration value, String name)
      Rejects a missing, zero or negative duration.
      Parameters:
      value - value to check.
      name - name of the value, for the message.