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 (default US).
allowedCountries - ISO 3166-1 regions an SMS may be sent to (default US, ES, GB).
costPerCountryMicros - cost of one SMS by region; a region absent here costs defaultCostMicros.
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 Details

    • defaultRegion

      private final String defaultRegion
      The field for the defaultRegion record component.
    • allowedCountries

      private final Set<String> allowedCountries
      The field for the allowedCountries record component.
    • costPerCountryMicros

      private final Map<String,Long> costPerCountryMicros
      The field for the costPerCountryMicros record component.
    • defaultCostMicros

      private final long defaultCostMicros
      The field for the defaultCostMicros record component.
    • window

      private final Duration window
      The field for the window record component.
    • windowCapMicros

      private final long windowCapMicros
      The field for the windowCapMicros record component.
    • dailyCapMicros

      private final long dailyCapMicros
      The field for the dailyCapMicros record component.
    • verificationCodeLength

      private final int verificationCodeLength
      The field for the verificationCodeLength record component.
    • verificationCodeTtl

      private final Duration verificationCodeTtl
      The field for the verificationCodeTtl record component.
    • verificationMaxAttempts

      private final int verificationMaxAttempts
      The field for the verificationMaxAttempts record component.
    • ledgerRetention

      private final Duration ledgerRetention
      The field for the ledgerRetention record component.
    • DEFAULT_REGION

      private static final String DEFAULT_REGION
      Default region.
      See Also:
    • DEFAULT_COUNTRIES

      private static final Set<String> DEFAULT_COUNTRIES
      Default allowed regions.
    • DEFAULT_WINDOW_MINUTES

      private static final long DEFAULT_WINDOW_MINUTES
      Default spending window, in minutes.
      See Also:
    • DEFAULT_CODE_LENGTH

      private static final int DEFAULT_CODE_LENGTH
      Default digits of the verification code.
      See Also:
    • DEFAULT_CODE_TTL_MINUTES

      private static final long DEFAULT_CODE_TTL_MINUTES
      Default validity of the verification code, in minutes.
      See Also:
    • DEFAULT_MAX_ATTEMPTS

      private static final int DEFAULT_MAX_ATTEMPTS
      Default attempts of the verification code.
      See Also:
    • DEFAULT_RETENTION_DAYS

      private static final long DEFAULT_RETENTION_DAYS
      Default retention of the ledger, in days.
      See Also:
    • REGION_PATTERN

      private static final String 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

      private static void requireRegion(String region, String key)
      Rejects a value that is not an upper-case ISO region code.
      Parameters:
      region - the value.
      key - the key of the setting below authserver.sms.
    • requireNotNegative

      private static void requireNotNegative(Long value, String key)
      Rejects a negative amount.
      Parameters:
      value - the amount.
      key - the key of the setting below authserver.sms.
    • numberOrDefault

      private static int numberOrDefault(int value, int defaultValue, String key)
      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 below authserver.sms.
      Returns:
      the number to use.
    • durationOrDefault

      private static Duration durationOrDefault(Duration value, Duration defaultValue, String key)
      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 below authserver.sms.
      Returns:
      the duration to use.
    • 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.
    • defaultRegion

      public String defaultRegion()
      Returns the value of the defaultRegion record component.
      Returns:
      the value of the defaultRegion record component
    • allowedCountries

      public Set<String> allowedCountries()
      Returns the value of the allowedCountries record component.
      Returns:
      the value of the allowedCountries record component
    • costPerCountryMicros

      public Map<String,Long> costPerCountryMicros()
      Returns the value of the costPerCountryMicros record component.
      Returns:
      the value of the costPerCountryMicros record component
    • defaultCostMicros

      public long defaultCostMicros()
      Returns the value of the defaultCostMicros record component.
      Returns:
      the value of the defaultCostMicros record component
    • window

      public Duration window()
      Returns the value of the window record component.
      Returns:
      the value of the window record component
    • windowCapMicros

      public long windowCapMicros()
      Returns the value of the windowCapMicros record component.
      Returns:
      the value of the windowCapMicros record component
    • dailyCapMicros

      public long dailyCapMicros()
      Returns the value of the dailyCapMicros record component.
      Returns:
      the value of the dailyCapMicros record component
    • verificationCodeLength

      public int verificationCodeLength()
      Returns the value of the verificationCodeLength record component.
      Returns:
      the value of the verificationCodeLength record component
    • verificationCodeTtl

      public Duration verificationCodeTtl()
      Returns the value of the verificationCodeTtl record component.
      Returns:
      the value of the verificationCodeTtl record component
    • verificationMaxAttempts

      public int verificationMaxAttempts()
      Returns the value of the verificationMaxAttempts record component.
      Returns:
      the value of the verificationMaxAttempts record component
    • ledgerRetention

      public Duration ledgerRetention()
      Returns the value of the ledgerRetention record component.
      Returns:
      the value of the ledgerRetention record component