Class JdbcPhoneVerificationRepository
java.lang.Object
com.irurueta.authserver.authorization.infrastructure.persistence.sms.JdbcPhoneVerificationRepository
- All Implemented Interfaces:
PhoneVerificationRepository
@Repository
public class JdbcPhoneVerificationRepository
extends Object
implements PhoneVerificationRepository
PhoneVerificationRepository over the pending_* columns of the user_phones table. It opens
no transaction: clearing a verification and then deleting an empty row runs in the caller's.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringStatement clearing every expired pending verification.private static final StringStatement clearing the pending columns of a user.private static final StringStatement deleting the rows that hold nothing at all.private static final StringStatement deleting the row of a user that holds neither a verified phone nor a pending verification.private static final StringQuery returning the pending verification of a user.private static final StringStatement counting a failed attempt atomically and returning the new count.private final org.springframework.jdbc.core.simple.JdbcClientJDBC client used to run the statements.private final PhoneVerificationRowMapperMaps a row to a verification.private static final StringStatement storing the pending verification of a user, creating the row if needed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByUserId(UUID userId) Removes the pending verification of a user.intdeleteExpired(Instant now) Deletes every pending verification that has expired.findByUserId(UUID userId) Finds the pending verification of a user.intincrementAttempts(UUID userId) Counts a wrong submission, in one atomic step.voidsave(PhoneVerification verification) Stores the pending verification of a user, replacing the one it had.
-
Field Details
-
UPSERT
Statement storing the pending verification of a user, creating the row if needed.- See Also:
-
FIND_BY_USER
Query returning the pending verification of a user.- See Also:
-
INCREMENT_ATTEMPTS
Statement counting a failed attempt atomically and returning the new count.- See Also:
-
CLEAR_PENDING
Statement clearing the pending columns of a user.- See Also:
-
DELETE_IF_EMPTY
Statement deleting the row of a user that holds neither a verified phone nor a pending verification.- See Also:
-
CLEAR_EXPIRED
Statement clearing every expired pending verification.- See Also:
-
DELETE_EMPTY_ROWS
Statement deleting the rows that hold nothing at all.- See Also:
-
jdbcClient
private final org.springframework.jdbc.core.simple.JdbcClient jdbcClientJDBC client used to run the statements. -
phoneVerificationRowMapper
Maps a row to a verification.
-
-
Constructor Details
-
JdbcPhoneVerificationRepository
public JdbcPhoneVerificationRepository()
-
-
Method Details
-
save
Description copied from interface:PhoneVerificationRepositoryStores the pending verification of a user, replacing the one it had.- Specified by:
savein interfacePhoneVerificationRepository- Parameters:
verification- the verification.
-
findByUserId
Description copied from interface:PhoneVerificationRepositoryFinds the pending verification of a user.- Specified by:
findByUserIdin interfacePhoneVerificationRepository- Parameters:
userId- identifier of the user.- Returns:
- the verification, or empty when there is none.
-
incrementAttempts
Description copied from interface:PhoneVerificationRepositoryCounts a wrong submission, in one atomic step.- Specified by:
incrementAttemptsin interfacePhoneVerificationRepository- Parameters:
userId- identifier of the user.- Returns:
- the number of attempts after the increment, or
0when there is no pending verification.
-
deleteByUserId
Description copied from interface:PhoneVerificationRepositoryRemoves the pending verification of a user.- Specified by:
deleteByUserIdin interfacePhoneVerificationRepository- Parameters:
userId- identifier of the user.
-
deleteExpired
Description copied from interface:PhoneVerificationRepositoryDeletes every pending verification that has expired.- Specified by:
deleteExpiredin interfacePhoneVerificationRepository- Parameters:
now- current instant.- Returns:
- the number of deleted verifications.
-