Class JdbcEmailAddressRequestRepository
java.lang.Object
org.jwcarman.who.emaillink.JdbcEmailAddressRequestRepository
- All Implemented Interfaces:
EmailAddressRequestRepository
public class JdbcEmailAddressRequestRepository
extends Object
implements EmailAddressRequestRepository
JDBC implementation of
EmailAddressRequestRepository on
who_email_address_request.-
Constructor Summary
ConstructorsConstructorDescriptionJdbcEmailAddressRequestRepository(org.springframework.jdbc.core.simple.JdbcClient jdbcClient) Creates a new repository. -
Method Summary
Modifier and TypeMethodDescriptionattemptCode(UUID identityId, int maxAttempts, Instant now) Counts a code attempt against the identity's live request, if it has attempts left.consumeCode(UUID requestId, String codeHash, Instant now) Consumes a live request whose code hash matches.consumeToken(UUID identityId, String tokenHash, Instant now) Consumes the identity's live request with the token.voidDeletes a request, as when its email could not be sent.booleansave(EmailAddressRequest request, String tokenHash, String codeHash, Duration resendInterval) Saves the identity's request in place of an older one, unless one was made too recently: by this identity for any address, or by anyone for this address, withinresendInterval.
-
Constructor Details
-
JdbcEmailAddressRequestRepository
public JdbcEmailAddressRequestRepository(org.springframework.jdbc.core.simple.JdbcClient jdbcClient) Creates a new repository.- Parameters:
jdbcClient- the JDBC client used to execute queries
-
-
Method Details
-
save
public boolean save(EmailAddressRequest request, String tokenHash, String codeHash, Duration resendInterval) Description copied from interface:EmailAddressRequestRepositorySaves the identity's request in place of an older one, unless one was made too recently: by this identity for any address, or by anyone for this address, withinresendInterval.- Specified by:
savein interfaceEmailAddressRequestRepository- Parameters:
request- the requesttokenHash- the SHA-256 hash of the link's tokencodeHash- the keyed hash of the code, bound to the request's idresendInterval- how long a request holds off another- Returns:
- whether it was saved
-
consumeToken
Description copied from interface:EmailAddressRequestRepositoryConsumes the identity's live request with the token.- Specified by:
consumeTokenin interfaceEmailAddressRequestRepository- Parameters:
identityId- the identity confirming; a token works only for the identity that askedtokenHash- the SHA-256 hash of the presented tokennow- the current time- Returns:
- the request, or empty if none matches
-
attemptCode
Description copied from interface:EmailAddressRequestRepositoryCounts a code attempt against the identity's live request, if it has attempts left.- Specified by:
attemptCodein interfaceEmailAddressRequestRepository- Parameters:
identityId- the identity confirmingmaxAttempts- how many attempts a code allowsnow- the current time- Returns:
- the request's id and code hash, or empty if there is no live request with attempts left
-
consumeCode
Description copied from interface:EmailAddressRequestRepositoryConsumes a live request whose code hash matches.- Specified by:
consumeCodein interfaceEmailAddressRequestRepository- Parameters:
requestId- the requestcodeHash- the presented code's hashnow- the current time- Returns:
- the request, or empty if it was used, expired or the hash differs
-
delete
Description copied from interface:EmailAddressRequestRepositoryDeletes a request, as when its email could not be sent.- Specified by:
deletein interfaceEmailAddressRequestRepository- Parameters:
requestId- the request
-