Interface RecoveryCodeRepository

All Known Implementing Classes:
JdbcRecoveryCodeRepository

public interface RecoveryCodeRepository
Port that stores the recovery codes of each user.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes every code of a user.
    findUnused(UUID userId)
    Lists the codes of a user that have not been spent.
    boolean
    markUsed(UUID id, Instant now)
    Spends a code, in one atomic step, so that two concurrent requests cannot both use it.
    void
    replaceAll(UUID userId, List<RecoveryCode> codes)
    Replaces every code of a user with a new set, which is what regenerating codes means.
  • Method Details

    • replaceAll

      void replaceAll(UUID userId, List<RecoveryCode> codes)
      Replaces every code of a user with a new set, which is what regenerating codes means.
      Parameters:
      userId - identifier of the user.
      codes - the new codes.
    • findUnused

      List<RecoveryCode> findUnused(UUID userId)
      Lists the codes of a user that have not been spent.
      Parameters:
      userId - identifier of the user.
      Returns:
      the unused codes, possibly empty.
    • markUsed

      boolean markUsed(UUID id, Instant now)
      Spends a code, in one atomic step, so that two concurrent requests cannot both use it.
      Parameters:
      id - identifier of the code.
      now - instant of the use.
      Returns:
      true when the code was unused and is now spent.
    • deleteByUser

      void deleteByUser(UUID userId)
      Deletes every code of a user.
      Parameters:
      userId - identifier of the user.