Class EmailChangeEmailOtpPlugin

java.lang.Object
io.meeds.social.security.plugin.EmailOtpPlugin
io.meeds.social.security.plugin.EmailChangeEmailOtpPlugin
All Implemented Interfaces:
io.meeds.social.security.plugin.EmailChangeOtpPlugin, io.meeds.web.security.plugin.OtpPlugin

@Service public class EmailChangeEmailOtpPlugin extends EmailOtpPlugin implements io.meeds.social.security.plugin.EmailChangeOtpPlugin
The code of an email change: sent to the new address, never to the address of the account, and stored bound to that address (EmailChangeOtpPlugin.bindCode(String, String)), so it proves that the user receives mail there and confirms a change to that address only. Generation, TTL, length and send interval are those of EmailOtpPlugin (the meeds.apiKey.otp.email.* settings), as are its caches, under the purpose-bound key of this method. The send lock is taken first, on every request, refused ones included, and holds per user whatever the address; a wrong code keeps it. Wrong guesses are bounded as the OTP service bounds them, per user over meeds.apiKey.otp.maxTentatives.ttl (validateOtp(String, String)). Once the change is written, the former address is told of it (sendChangeNotice(String, String)).
  • Constructor Details

    • EmailChangeEmailOtpPlugin

      public EmailChangeEmailOtpPlugin()
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface io.meeds.web.security.plugin.OtpPlugin
      Overrides:
      getName in class EmailOtpPlugin
    • generateOtpCode

      public void generateOtpCode(String userName)
      Refused: a code of this method goes to the new address only, which the generic send does not name
      Specified by:
      generateOtpCode in interface io.meeds.web.security.plugin.OtpPlugin
      Overrides:
      generateOtpCode in class EmailOtpPlugin
      Throws:
      IllegalArgumentException - always
    • generateOtpCode

      public <R> R generateOtpCode(String userName, String newEmail, io.meeds.social.security.plugin.EmailChangeOtpPlugin.AddressCheck<R> addressCheck) throws Exception
      Specified by:
      generateOtpCode in interface io.meeds.social.security.plugin.EmailChangeOtpPlugin
      Throws:
      Exception
    • validateOtp

      public boolean validateOtp(String userName, String otpCode)
      Bounds the wrong guesses at the user's code as the OTP service bounds the other methods: per user, meeds.apiKey.otp.maxTentatives.count of them, in a count that lives meeds.apiKey.otp.maxTentatives.ttl minutes after the last one and that a valid code clears. At the limit the code is dropped, and every code is refused until the count expires: a new send does not start it again. The OTP service's own count does not bound this code: it is cleared by any valid code, and the email change checks the code of the current address in the same request. Guesses are counted one at a time on a server, so concurrent requests never count as one.
      Specified by:
      validateOtp in interface io.meeds.web.security.plugin.OtpPlugin
      Overrides:
      validateOtp in class EmailOtpPlugin
    • sendChangeNotice

      public void sendChangeNotice(String userName, String formerEmail)
      Best effort: a mail server failure is logged and never undoes the change the user confirmed with both codes
      Specified by:
      sendChangeNotice in interface io.meeds.social.security.plugin.EmailChangeOtpPlugin
    • getEmailBodyPath

      public String getEmailBodyPath()
    • getEmailSubjectKey

      protected String getEmailSubjectKey()
      Overrides:
      getEmailSubjectKey in class EmailOtpPlugin
    • getStoredCode

      protected String getStoredCode(String otpCode, String recipientEmail)
      Description copied from class: EmailOtpPlugin
      The value a sent code is stored as. The code itself here: the email, API key, account deactivation and administrator session methods compare the typed code alone
      Overrides:
      getStoredCode in class EmailOtpPlugin
      Parameters:
      otpCode - the generated code
      recipientEmail - the address the code is sent to, null for the address of the user's account
      Returns:
      the value to store