Class JdbcOneTimeTokenRepository

java.lang.Object
com.codename1.backend.security.mail.JdbcOneTimeTokenRepository
All Implemented Interfaces:
OneTimeTokenRepository

public final class JdbcOneTimeTokenRepository extends Object implements OneTimeTokenRepository
Tokens kept in the server's database, in the cn1_one_time_token table of SecuritySchema. A token is used up by one DELETE that names it, and counted as used only when that removed exactly one row, so two servers handed the same link let one of them through.
  • Constructor Details

    • JdbcOneTimeTokenRepository

      public JdbcOneTimeTokenRepository(DataSource dataSource)
  • Method Details

    • save

      public void save(String tokenHash, String purpose, String username, long now, long expiresAt)
      Description copied from interface: OneTimeTokenRepository

      Keeps a token for username, in place of any that user had for purpose: the newest link is the only one that works.

      Parameters
      • tokenHash: the token's hash
      • purpose: what the token may be used for
      • username: whose it is
      • now: the moment, epoch milliseconds; tokens that expired before it may be dropped
      • expiresAt: when the token stops working, epoch milliseconds
      Specified by:
      save in interface OneTimeTokenRepository
    • consume

      public String consume(String tokenHash, String purpose, long now)
      Description copied from interface: OneTimeTokenRepository
      Uses a token up. Answers the user it was given to, or null when there is none for purpose, it has expired, or another caller used it first: of two callers with one token, one is answered.
      Specified by:
      consume in interface OneTimeTokenRepository
    • removeAll

      public void removeAll(String username, String purpose)
      Description copied from interface: OneTimeTokenRepository
      Drops every token username has for purpose.
      Specified by:
      removeAll in interface OneTimeTokenRepository