Skip to content

Commit 4f328c9

Browse files
committed
destroy() shuts down the taskScheduler
Issue gh-15735
1 parent 50cc36d commit 4f328c9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/src/main/java/org/springframework/security/authentication/ott/JdbcOneTimeTokenService.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.commons.logging.Log;
3131
import org.apache.commons.logging.LogFactory;
3232

33+
import org.springframework.beans.factory.DisposableBean;
3334
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
3435
import org.springframework.jdbc.core.JdbcOperations;
3536
import org.springframework.jdbc.core.PreparedStatementSetter;
@@ -55,7 +56,7 @@
5556
* @author Max Batischev
5657
* @since 6.4
5758
*/
58-
public final class JdbcOneTimeTokenService implements OneTimeTokenService {
59+
public final class JdbcOneTimeTokenService implements OneTimeTokenService, DisposableBean {
5960

6061
private final Log logger = LogFactory.getLog(getClass());
6162

@@ -187,6 +188,13 @@ public void cleanUpExpiredTokens() {
187188
this.logger.debug("Cleaned up " + deletedCount + " expired tokens");
188189
}
189190

191+
@Override
192+
public void destroy() throws Exception {
193+
if (this.taskScheduler != null) {
194+
this.taskScheduler.shutdown();
195+
}
196+
}
197+
190198
/**
191199
* Sets the {@link Clock} used when generating one-time token and checking token
192200
* expiry.

core/src/test/java/org/springframework/security/authentication/ott/JdbcOneTimeTokenServiceTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ void setUp() {
6868
}
6969

7070
@AfterEach
71-
public void tearDown() {
71+
public void tearDown() throws Exception {
7272
this.db.shutdown();
73+
this.oneTimeTokenService.destroy();
7374
}
7475

7576
private static EmbeddedDatabase createDb() {

0 commit comments

Comments
 (0)