Record Class SmsProperties
java.lang.Object
java.lang.Record
com.irurueta.authserver.authorization.application.sms.SmsProperties
- Record Components:
defaultRegion- ISO 3166-1 region assumed for a number typed without a country code (defaultUS).allowedCountries- ISO 3166-1 regions an SMS may be sent to (defaultUS,ES,GB).costPerCountryMicros- cost of one SMS by region; a region absent here costsdefaultCostMicros.defaultCostMicros- cost of an SMS to a region without its own cost (default 50000).window- length of the spending window (default one hour).windowCapMicros- spending allowed in a window (default 5000000).dailyCapMicros- spending allowed in 24 hours (default 20000000).verificationCodeLength- digits of the code that verifies a phone (default 6).verificationCodeTtl- how long that code is valid (default 10 minutes).verificationMaxAttempts- attempts allowed for that code (default 5).ledgerRetention- how long the cost ledger keeps its rows, at least one day (default 2 days).
@ConfigurationProperties("authserver.sms")
public record SmsProperties(String defaultRegion, Set<String> allowedCountries, Map<String,Long> costPerCountryMicros, long defaultCostMicros, Duration window, long windowCapMicros, long dailyCapMicros, int verificationCodeLength, Duration verificationCodeTtl, int verificationMaxAttempts, Duration ledgerRetention)
extends Record
Settings of the SMS channel, bound from
authserver.sms.* once and validated at startup. A missing (or zero,
for a number) value takes its default, so the application starts without any setting.
Costs and caps are in micros of the billing currency (one millionth), so they stay integers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe field for theallowedCountriesrecord component.The field for thecostPerCountryMicrosrecord component.private final longThe field for thedailyCapMicrosrecord component.private static final intDefault digits of the verification code.private static final longDefault validity of the verification code, in minutes.Default allowed regions.private static final intDefault attempts of the verification code.private static final StringDefault region.private static final longDefault retention of the ledger, in days.private static final longDefault spending window, in minutes.private final longThe field for thedefaultCostMicrosrecord component.private final StringThe field for thedefaultRegionrecord component.private final DurationThe field for theledgerRetentionrecord component.private static final StringPattern of a region code.private final intThe field for theverificationCodeLengthrecord component.private final DurationThe field for theverificationCodeTtlrecord component.private final intThe field for theverificationMaxAttemptsrecord component.private final DurationThe field for thewindowrecord component.private final longThe field for thewindowCapMicrosrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionSmsProperties(String defaultRegion, Set<String> allowedCountries, Map<String, Long> costPerCountryMicros, long defaultCostMicros, Duration window, long windowCapMicros, long dailyCapMicros, int verificationCodeLength, Duration verificationCodeTtl, int verificationMaxAttempts, Duration ledgerRetention) Applies the defaults and validates the settings. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theallowedCountriesrecord component.Returns the value of thecostPerCountryMicrosrecord component.longReturns the value of thedailyCapMicrosrecord component.longReturns the value of thedefaultCostMicrosrecord component.Returns the value of thedefaultRegionrecord component.private static DurationdurationOrDefault(Duration value, Duration defaultValue, String key) Keeps a positive duration, replaces a missing or zero one by its default and rejects a negative one.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theledgerRetentionrecord component.private static intnumberOrDefault(int value, int defaultValue, String key) Keeps a positive number, replaces zero by its default and rejects a negative one.private static voidrequireNotNegative(Long value, String key) Rejects a negative amount.private static voidrequireRegion(String region, String key) Rejects a value that is not an upper-case ISO region code.final StringtoString()Returns a string representation of this record class.intReturns the value of theverificationCodeLengthrecord component.Returns the value of theverificationCodeTtlrecord component.intReturns the value of theverificationMaxAttemptsrecord component.window()Returns the value of thewindowrecord component.longReturns the value of thewindowCapMicrosrecord component.
-
Field Details
-
defaultRegion
The field for thedefaultRegionrecord component. -
allowedCountries
The field for theallowedCountriesrecord component. -
costPerCountryMicros
The field for thecostPerCountryMicrosrecord component. -
defaultCostMicros
private final long defaultCostMicrosThe field for thedefaultCostMicrosrecord component. -
window
The field for thewindowrecord component. -
windowCapMicros
private final long windowCapMicrosThe field for thewindowCapMicrosrecord component. -
dailyCapMicros
private final long dailyCapMicrosThe field for thedailyCapMicrosrecord component. -
verificationCodeLength
private final int verificationCodeLengthThe field for theverificationCodeLengthrecord component. -
verificationCodeTtl
The field for theverificationCodeTtlrecord component. -
verificationMaxAttempts
private final int verificationMaxAttemptsThe field for theverificationMaxAttemptsrecord component. -
ledgerRetention
The field for theledgerRetentionrecord component. -
DEFAULT_REGION
Default region.- See Also:
-
DEFAULT_COUNTRIES
Default allowed regions. -
DEFAULT_WINDOW_MINUTES
private static final long DEFAULT_WINDOW_MINUTESDefault spending window, in minutes.- See Also:
-
DEFAULT_CODE_LENGTH
private static final int DEFAULT_CODE_LENGTHDefault digits of the verification code.- See Also:
-
DEFAULT_CODE_TTL_MINUTES
private static final long DEFAULT_CODE_TTL_MINUTESDefault validity of the verification code, in minutes.- See Also:
-
DEFAULT_MAX_ATTEMPTS
private static final int DEFAULT_MAX_ATTEMPTSDefault attempts of the verification code.- See Also:
-
DEFAULT_RETENTION_DAYS
private static final long DEFAULT_RETENTION_DAYSDefault retention of the ledger, in days.- See Also:
-
REGION_PATTERN
Pattern of a region code.- See Also:
-
-
Constructor Details
-
SmsProperties
public SmsProperties(@DefaultValue("US") String defaultRegion, @DefaultValue({"US","ES","GB"}) Set<String> allowedCountries, Map<String, Long> costPerCountryMicros, @DefaultValue("50000") long defaultCostMicros, @DefaultValue("PT1H") Duration window, @DefaultValue("5000000") long windowCapMicros, @DefaultValue("20000000") long dailyCapMicros, @DefaultValue("6") int verificationCodeLength, @DefaultValue("PT10M") Duration verificationCodeTtl, @DefaultValue("5") int verificationMaxAttempts, @DefaultValue("P2D") Duration ledgerRetention) Applies the defaults and validates the settings.- Throws:
IllegalArgumentException- if a region is not an upper-case ISO code, a cost or cap is negative, a number or duration is negative, or the retention is shorter than one day.
-
-
Method Details
-
requireRegion
Rejects a value that is not an upper-case ISO region code.- Parameters:
region- the value.key- the key of the setting belowauthserver.sms.
-
requireNotNegative
Rejects a negative amount.- Parameters:
value- the amount.key- the key of the setting belowauthserver.sms.
-
numberOrDefault
Keeps a positive number, replaces zero by its default and rejects a negative one.- Parameters:
value- the configured number.defaultValue- the default.key- the key of the setting belowauthserver.sms.- Returns:
- the number to use.
-
durationOrDefault
Keeps a positive duration, replaces a missing or zero one by its default and rejects a negative one.- Parameters:
value- the configured duration.defaultValue- the default.key- the key of the setting belowauthserver.sms.- Returns:
- the duration to use.
-
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 '=='. -
defaultRegion
Returns the value of thedefaultRegionrecord component.- Returns:
- the value of the
defaultRegionrecord component
-
allowedCountries
Returns the value of theallowedCountriesrecord component.- Returns:
- the value of the
allowedCountriesrecord component
-
costPerCountryMicros
Returns the value of thecostPerCountryMicrosrecord component.- Returns:
- the value of the
costPerCountryMicrosrecord component
-
defaultCostMicros
public long defaultCostMicros()Returns the value of thedefaultCostMicrosrecord component.- Returns:
- the value of the
defaultCostMicrosrecord component
-
window
Returns the value of thewindowrecord component.- Returns:
- the value of the
windowrecord component
-
windowCapMicros
public long windowCapMicros()Returns the value of thewindowCapMicrosrecord component.- Returns:
- the value of the
windowCapMicrosrecord component
-
dailyCapMicros
public long dailyCapMicros()Returns the value of thedailyCapMicrosrecord component.- Returns:
- the value of the
dailyCapMicrosrecord component
-
verificationCodeLength
public int verificationCodeLength()Returns the value of theverificationCodeLengthrecord component.- Returns:
- the value of the
verificationCodeLengthrecord component
-
verificationCodeTtl
Returns the value of theverificationCodeTtlrecord component.- Returns:
- the value of the
verificationCodeTtlrecord component
-
verificationMaxAttempts
public int verificationMaxAttempts()Returns the value of theverificationMaxAttemptsrecord component.- Returns:
- the value of the
verificationMaxAttemptsrecord component
-
ledgerRetention
Returns the value of theledgerRetentionrecord component.- Returns:
- the value of the
ledgerRetentionrecord component
-