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 Summary
ConstructorsConstructorDescriptionJdbcOneTimeTokenService(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenServiceusing the provide parameters. -
Method Summary
Modifier 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
-
JdbcOneTimeTokenService
public JdbcOneTimeTokenService(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenServiceusing the provide parameters.- Parameters:
jdbcOperations- the JDBC operations
-
-
Method Details
-
setCleanupCron
Sets 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 toCronTriggerused for determining how frequent to perform cleanup. The default is "@hourly".- See Also:
-
CronTriggercleanupExpiredTokens()
-
generate
Description copied from interface:OneTimeTokenServiceGenerates a one-time token based on the provided generate request.- Specified by:
generatein interfaceOneTimeTokenService- Parameters:
request- the generate request containing the necessary information to generate the token- Returns:
- the generated
OneTimeToken, nevernull.
-
consume
Description copied from interface:OneTimeTokenServiceConsumes a one-time token based on the provided authentication token.- Specified by:
consumein interfaceOneTimeTokenService- Parameters:
authenticationToken- the authentication token containing the one-time token value to be consumed- Returns:
- the consumed
OneTimeTokenornullif the token is invalid
-
cleanupExpiredTokens
public void cleanupExpiredTokens() -
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
setClock
Sets theClockused when generating one-time token and checking token expiry.- Parameters:
clock- the clock
-