Interface OneTimeTokenRepository

All Known Implementing Classes:
InMemoryOneTimeTokenRepository, JdbcOneTimeTokenRepository

public interface OneTimeTokenRepository
Where OneTimeTokenService keeps the tokens it has given out: never a token, only its hash.
  • Method Summary

    Modifier and Type
    Method
    Description
    consume(String tokenHash, String purpose, long now)
    Uses a token up.
    void
    removeAll(String username, String purpose)
    Drops every token username has for purpose.
    void
    save(String tokenHash, String purpose, String username, long now, long expiresAt)
    Keeps a token for username, in place of any that user had for purpose: the newest link is the only one that works.
  • Method Details

    • save

      void save(String tokenHash, String purpose, String username, long now, long expiresAt)

      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
    • consume

      String consume(String tokenHash, String purpose, long now)
      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.
    • removeAll

      void removeAll(String username, String purpose)
      Drops every token username has for purpose.