Class OttPolicy
java.lang.Object
com.irurueta.authserver.authorization.domain.ott.OttPolicy
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the length of the numeric code.booleanisExhausted(int attempts) Tells whether a code has used up its attempts.intGets the wrong submissions tolerated per code.private static voidrequirePositive(Duration value, String name) Rejects a missing, zero or negative duration.Gets the lifetime of a token of a kind.
-
Field Details
-
codeLength
private final int codeLengthLength of the numeric code, in digits. -
codeTtl
Lifetime of a numeric code. -
linkTtl
Lifetime of a magic link. -
maxAttempts
private final int maxAttemptsWrong submissions tolerated before a code is rejected for good.
-
-
Constructor Details
-
OttPolicy
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
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:
truewhenattemptsreaches the limit.
-
requirePositive
Rejects a missing, zero or negative duration.- Parameters:
value- value to check.name- name of the value, for the message.
-