Class JdbcTrustedDeviceRepository
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringColumns selected for every query.private static final StringQuery returning the unexpired devices of a user, newest first.private static final StringQuery returning an unexpired device of a user by the hash of its token.private static final StringStatement storing a device.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private final TrustedDeviceRowMapperMaps a row to a device. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdeleteByUser(UUID userId) Revokes every device of a user, for example when the second factor they skip is removed.intdeleteExpired(Instant now) Deletes the devices that expired before an instant.findByUser(UUID userId, Instant now) Lists the devices of a user that are still trusted.findUsable(UUID userId, String hashedToken, Instant now) Finds a device that is still trusted.booleanRevokes a device of a user.voidstore(TrustedDevice device) Stores a new trusted device.
-
Field Details
-
COLUMNS
Columns selected for every query.- See Also:
-
INSERT_DEVICE
Statement storing a device.- See Also:
-
FIND_USABLE
Query returning an unexpired device of a user by the hash of its token.- See Also:
-
FIND_BY_USER
Query returning the unexpired devices of a user, newest first.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
trustedDeviceRowMapper
Maps a row to a device.
-
-
Constructor Details
-
JdbcTrustedDeviceRepository
public JdbcTrustedDeviceRepository()
-
-
Method Details
-
store
Description copied from interface:TrustedDeviceRepositoryStores a new trusted device.- Specified by:
storein interfaceTrustedDeviceRepository- Parameters:
device- the device to store.
-
findUsable
Description copied from interface:TrustedDeviceRepositoryFinds a device that is still trusted.- Specified by:
findUsablein interfaceTrustedDeviceRepository- 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
Description copied from interface:TrustedDeviceRepositoryLists the devices of a user that are still trusted.- Specified by:
findByUserin interfaceTrustedDeviceRepository- Parameters:
userId- identifier of the user.now- current instant, compared against the expiry.- Returns:
- the unexpired devices, possibly empty.
-
revoke
Description copied from interface:TrustedDeviceRepositoryRevokes a device of a user.- Specified by:
revokein interfaceTrustedDeviceRepository- Parameters:
userId- identifier of the user, so nobody can revoke another user's device.id- identifier of the device.- Returns:
truewhen a device was revoked.
-
deleteByUser
Description copied from interface:TrustedDeviceRepositoryRevokes every device of a user, for example when the second factor they skip is removed.- Specified by:
deleteByUserin interfaceTrustedDeviceRepository- Parameters:
userId- identifier of the user.- Returns:
- the number of revoked devices.
-
deleteExpired
Description copied from interface:TrustedDeviceRepositoryDeletes the devices that expired before an instant.- Specified by:
deleteExpiredin interfaceTrustedDeviceRepository- Parameters:
now- current instant.- Returns:
- the number of deleted devices.
-