java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.mfa.JdbcTrustedDeviceRepository
All Implemented Interfaces:
TrustedDeviceRepository

@Repository public class JdbcTrustedDeviceRepository extends Object implements TrustedDeviceRepository
TrustedDeviceRepository over the trusted_devices table. It joins the transaction of its caller.
  • Field Details

    • COLUMNS

      private static final String COLUMNS
      Columns selected for every query.
      See Also:
    • INSERT_DEVICE

      private static final String INSERT_DEVICE
      Statement storing a device.
      See Also:
    • FIND_USABLE

      private static final String FIND_USABLE
      Query returning an unexpired device of a user by the hash of its token.
      See Also:
    • FIND_BY_USER

      private static final String FIND_BY_USER
      Query returning the unexpired devices of a user, newest first.
      See Also:
    • jdbcClient

      private final org.springframework.jdbc.core.simple.JdbcClient jdbcClient
      JDBC client used to run the statements.
    • trustedDeviceRowMapper

      private final TrustedDeviceRowMapper trustedDeviceRowMapper
      Maps a row to a device.
  • Constructor Details

    • JdbcTrustedDeviceRepository

      public JdbcTrustedDeviceRepository()
  • Method Details

    • store

      public void store(TrustedDevice device)
      Description copied from interface: TrustedDeviceRepository
      Stores a new trusted device.
      Specified by:
      store in interface TrustedDeviceRepository
      Parameters:
      device - the device to store.
    • findUsable

      public Optional<TrustedDevice> findUsable(UUID userId, String hashedToken, Instant now)
      Description copied from interface: TrustedDeviceRepository
      Finds a device that is still trusted.
      Specified by:
      findUsable in interface TrustedDeviceRepository
      Parameters:
      userId - identifier of the user.
      hashedToken - hash of the device token presented by the browser.
      now - current instant, compared against the expiry.
      Returns:
      the device, or an empty optional when there is no such unexpired device.
    • findByUser

      public List<TrustedDevice> findByUser(UUID userId, Instant now)
      Description copied from interface: TrustedDeviceRepository
      Lists the devices of a user that are still trusted.
      Specified by:
      findByUser in interface TrustedDeviceRepository
      Parameters:
      userId - identifier of the user.
      now - current instant, compared against the expiry.
      Returns:
      the unexpired devices, possibly empty.
    • revoke

      public boolean revoke(UUID userId, UUID id)
      Description copied from interface: TrustedDeviceRepository
      Revokes a device of a user.
      Specified by:
      revoke in interface TrustedDeviceRepository
      Parameters:
      userId - identifier of the user, so nobody can revoke another user's device.
      id - identifier of the device.
      Returns:
      true when a device was revoked.
    • deleteByUser

      public int deleteByUser(UUID userId)
      Description copied from interface: TrustedDeviceRepository
      Revokes every device of a user, for example when the second factor they skip is removed.
      Specified by:
      deleteByUser in interface TrustedDeviceRepository
      Parameters:
      userId - identifier of the user.
      Returns:
      the number of revoked devices.
    • deleteExpired

      public int deleteExpired(Instant now)
      Description copied from interface: TrustedDeviceRepository
      Deletes the devices that expired before an instant.
      Specified by:
      deleteExpired in interface TrustedDeviceRepository
      Parameters:
      now - current instant.
      Returns:
      the number of deleted devices.