JdbcOneTimeTokenService.setCleanupCron

Spring Security uses setter methods for optional member variables. Allows
for a null cleanupCron to disable the cleanup.

In a clustered environment it is likely that users do not want all nodes
to be performing a cleanup because it will cause contention on the ott
table.

Another example is if a user wants to invoke cleanUpExpiredTokens with a
different strategy all together, they might want to disable the cron job.

Issue gh-15735
This commit is contained in:
Rob Winch
2024-10-01 08:49:42 -05:00
parent 4787ac254d
commit 612b15abcc
2 changed files with 38 additions and 15 deletions

View File

@@ -175,6 +175,17 @@ public class JdbcOneTimeTokenServiceTests {
assertThat(deletedOneTimeToken2).isNull();
}
@Test
void setCleanupChronWhenNullThenNoException() {
this.oneTimeTokenService.setCleanupCron(null);
}
@Test
void setCleanupChronWhenAlreadyNullThenNoException() {
this.oneTimeTokenService.setCleanupCron(null);
this.oneTimeTokenService.setCleanupCron(null);
}
private void saveToken(OneTimeToken oneTimeToken) {
List<SqlParameterValue> parameters = this.oneTimeTokenParametersMapper.apply(oneTimeToken);
PreparedStatementSetter pss = new ArgumentPreparedStatementSetter(parameters.toArray());