Interface EmailChangeOtpPlugin

All Superinterfaces:
io.meeds.web.security.plugin.OtpPlugin

public interface EmailChangeOtpPlugin extends io.meeds.web.security.plugin.OtpPlugin
The OTP method of the email change: the code goes to the new address, and it confirms a change to that address only. It is stored bound to the address it was sent to (bindCode(String, String)), so the flow validates and consumes it through OtpService with the bound value of the code typed and of the address being set, never with the code alone. A change also needs a code of the email method, sent to the address of the account, and the former address is told once the change is written.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    The check of the new address, run under the send lock
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    bindCode(String otpCode, String email)
    The value a code of this method is stored, validated and consumed as: the code and the address, lower-cased and trimmed.
    <R> R
    generateOtpCode(String userName, String newEmail, EmailChangeOtpPlugin.AddressCheck<R> addressCheck)
    Takes the send lock of the user first, then runs the check of the address, then sends a new code to the address when the check accepts it.
    void
    sendChangeNotice(String userName, String formerEmail)
    Tells the former address of the user that the email of their account changed, without naming the new one, so that a change the owner of the account did not make is noticed where they still read their mail.

    Methods inherited from interface io.meeds.web.security.plugin.OtpPlugin

    canUse, consumeOtp, generateOtpCode, getCodeTtlMinutes, getName, getSendIntervalSeconds, validateOtp
  • Field Details

  • Method Details

    • generateOtpCode

      <R> R generateOtpCode(String userName, String newEmail, EmailChangeOtpPlugin.AddressCheck<R> addressCheck) throws Exception
      Takes the send lock of the user first, then runs the check of the address, then sends a new code to the address when the check accepts it. The lock holds for the send interval whatever the check answers, so a refused address is rate-limited like a send, and a request made while the lock holds is refused before the address is checked.
      Type Parameters:
      R - the type of the check's refusal
      Parameters:
      userName - the user changing their email
      newEmail - the address to set
      addressCheck - answers the refusal of the address, or null to send
      Returns:
      the check's refusal, or null when the code was sent
      Throws:
      IllegalStateException - when the lock is already held: nothing is checked or sent
      Exception - when the check fails
    • sendChangeNotice

      void sendChangeNotice(String userName, String formerEmail)
      Tells the former address of the user that the email of their account changed, without naming the new one, so that a change the owner of the account did not make is noticed where they still read their mail. Best effort: a failure to send is logged, never thrown.
      Parameters:
      userName - the user whose email changed
      formerEmail - the address of the account before the change
    • bindCode

      static String bindCode(String otpCode, String email)
      The value a code of this method is stored, validated and consumed as: the code and the address, lower-cased and trimmed. A generated code holds digits only, so a typed code that holds anything else binds to nothing and the value is unambiguous: a code sent to one address never confirms another.
      Parameters:
      otpCode - the code, as sent or as typed
      email - the address it was sent to, or the address being set
      Returns:
      the bound value, null when the code or the address is blank or the code is not made of digits