Class JdbcOneTimeTokenService
java.lang.Object
org.springframework.security.authentication.ott.JdbcOneTimeTokenService
- All Implemented Interfaces:
- org.springframework.beans.factory.DisposableBean,- org.springframework.beans.factory.InitializingBean,- OneTimeTokenService
public final class JdbcOneTimeTokenService
extends Object
implements OneTimeTokenService, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
A JDBC implementation of an 
OneTimeTokenService that uses a
 JdbcOperations for OneTimeToken persistence.
 
 NOTE: This JdbcOneTimeTokenService depends on the table definition
 described in
 "classpath:org/springframework/security/core/ott/jdbc/one-time-tokens-schema.sql" and
 therefore MUST be defined in the database schema.
- Since:
- 6.4
- 
Constructor SummaryConstructorsConstructorDescriptionJdbcOneTimeTokenService(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenServiceusing the provide parameters.
- 
Method SummaryModifier and TypeMethodDescriptionvoidvoid@Nullable OneTimeTokenconsume(OneTimeTokenAuthenticationToken authenticationToken) Consumes a one-time token based on the provided authentication token.voiddestroy()generate(GenerateOneTimeTokenRequest request) Generates a one-time token based on the provided generate request.voidsetCleanupCron(String cleanupCron) Sets the chron expression used for cleaning up expired tokens.voidSets theClockused when generating one-time token and checking token expiry.
- 
Constructor Details- 
JdbcOneTimeTokenServicepublic JdbcOneTimeTokenService(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenServiceusing the provide parameters.- Parameters:
- jdbcOperations- the JDBC operations
 
 
- 
- 
Method Details- 
setCleanupCronSets the chron expression used for cleaning up expired tokens. The default is to run hourly. For more advanced use cases the cleanupCron may be set to null which will disable the built-in cleanup. Users can then invokecleanupExpiredTokens()using custom logic.- Parameters:
- cleanupCron- the chron expression passed to- CronTriggerused for determining how frequent to perform cleanup. The default is "@hourly".
- See Also:
- 
- CronTrigger
- cleanupExpiredTokens()
 
 
- 
generateDescription copied from interface:OneTimeTokenServiceGenerates a one-time token based on the provided generate request.- Specified by:
- generatein interface- OneTimeTokenService
- Parameters:
- request- the generate request containing the necessary information to generate the token
- Returns:
- the generated OneTimeToken, nevernull.
 
- 
consumeDescription copied from interface:OneTimeTokenServiceConsumes a one-time token based on the provided authentication token.- Specified by:
- consumein interface- OneTimeTokenService
- Parameters:
- authenticationToken- the authentication token containing the one-time token value to be consumed
- Returns:
- the consumed OneTimeTokenornullif the token is invalid
 
- 
cleanupExpiredTokenspublic void cleanupExpiredTokens()
- 
afterPropertiesSet- Specified by:
- afterPropertiesSetin interface- org.springframework.beans.factory.InitializingBean
- Throws:
- Exception
 
- 
destroy- Specified by:
- destroyin interface- org.springframework.beans.factory.DisposableBean
- Throws:
- Exception
 
- 
setClockSets theClockused when generating one-time token and checking token expiry.- Parameters:
- clock- the clock
 
 
-