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
ConstructorDescriptionJdbcOneTimeTokenService
(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenService
using the provide parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
consume
(OneTimeTokenAuthenticationToken authenticationToken) Consumes a one-time token based on the provided authentication token.void
destroy()
generate
(GenerateOneTimeTokenRequest request) Generates a one-time token based on the provided generate request.void
setCleanupCron
(String cleanupCron) Sets the chron expression used for cleaning up expired sessions.void
Sets theClock
used when generating one-time token and checking token expiry.
-
Constructor Details
-
JdbcOneTimeTokenService
public JdbcOneTimeTokenService(org.springframework.jdbc.core.JdbcOperations jdbcOperations) Constructs aJdbcOneTimeTokenService
using the provide parameters.- Parameters:
jdbcOperations
- the JDBC operations
-
-
Method Details
-
setCleanupCron
Sets the chron expression used for cleaning up expired sessions. 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 toCronTrigger
used for determining how frequent to perform cleanup. The default is "@hourly".- See Also:
-
CronTrigger
cleanupExpiredTokens()
-
generate
Description copied from interface:OneTimeTokenService
Generates a one-time token based on the provided generate request.- Specified by:
generate
in interfaceOneTimeTokenService
- Parameters:
request
- the generate request containing the necessary information to generate the token- Returns:
- the generated
OneTimeToken
, nevernull
.
-
consume
Description copied from interface:OneTimeTokenService
Consumes a one-time token based on the provided authentication token.- Specified by:
consume
in interfaceOneTimeTokenService
- Parameters:
authenticationToken
- the authentication token containing the one-time token value to be consumed- Returns:
- the consumed
OneTimeToken
ornull
if the token is invalid
-
cleanupExpiredTokens
public void cleanupExpiredTokens() -
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
setClock
Sets theClock
used when generating one-time token and checking token expiry.- Parameters:
clock
- the clock
-