Class JdbcEmailCodeRepository

java.lang.Object
com.codename1.backend.security.mfa.JdbcEmailCodeRepository
All Implemented Interfaces:
EmailCodeRepository

public final class JdbcEmailCodeRepository extends Object implements EmailCodeRepository
Mailed codes kept in the server's database, in the cn1_mfa_email table of SecuritySchema. An attempt is counted, and a code used up, by one UPDATE whose condition is the limit or the code itself, so servers sharing the table cannot between them allow one attempt too many or take one code twice.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    clear(String username, String codeHash, boolean signedIn)
    Uses the waiting code up, if it is still the one with codeHash.
    boolean
    countAttempt(String username, int max)
    Counts one attempt against the waiting code.
    find(String username)
    What is held for username, or null.
    boolean
    saveCode(String username, String codeHash, long expiresAt, long sentAt, long sentBefore, int max)
    Keeps a new code for username in place of the one waiting, when the user signs in with a mailed code and the last was sent at or before sentBefore -- or after sentAt, which is a clock that was set back.
    void
    setEnabled(String username, boolean enabled)
    Turns the mailed code on or off for username.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JdbcEmailCodeRepository

      public JdbcEmailCodeRepository(DataSource dataSource)
  • Method Details

    • find

      public EmailCode find(String username)
      Description copied from interface: EmailCodeRepository
      What is held for username, or null.
      Specified by:
      find in interface EmailCodeRepository
    • setEnabled

      public void setEnabled(String username, boolean enabled)
      Description copied from interface: EmailCodeRepository
      Turns the mailed code on or off for username. Turning it off drops any code that is waiting.
      Specified by:
      setEnabled in interface EmailCodeRepository
    • saveCode

      public boolean saveCode(String username, String codeHash, long expiresAt, long sentAt, long sentBefore, int max)
      Description copied from interface: EmailCodeRepository

      Keeps a new code for username in place of the one waiting, when the user signs in with a mailed code and the last was sent at or before sentBefore -- or after sentAt, which is a clock that was set back. Of several callers at once one is answered true, so one mail leaves.

      The attempts counted against the code it replaces are counted against this one too, unless that code had run out or been used: asking for another is not a way to more tries. And a code with max attempts counted is not replaced before it runs out, so the wait that follows them ends at a moment that asking again does not move.

      Specified by:
      saveCode in interface EmailCodeRepository
    • countAttempt

      public boolean countAttempt(String username, int max)
      Description copied from interface: EmailCodeRepository
      Counts one attempt against the waiting code. False when max have been counted already; of several callers at once, no more than max are answered true.
      Specified by:
      countAttempt in interface EmailCodeRepository
    • clear

      public boolean clear(String username, String codeHash, boolean signedIn)
      Description copied from interface: EmailCodeRepository
      Uses the waiting code up, if it is still the one with codeHash. Of two callers with the same code, one is answered true. signedIn says the code was typed in and accepted, which also forgets when it was sent: the next sign-in is then mailed a code at once. A code cleared because its mail failed keeps the time, so a failing send is still spaced out.
      Specified by:
      clear in interface EmailCodeRepository