Package org.springframework.security.authentication.ott

# Class InMemoryOneTimeTokenService

java.lang.Object
org.springframework.security.authentication.ott.InMemoryOneTimeTokenService

All Implemented Interfaces:
  `OneTimeTokenService`

public final class InMemoryOneTimeTokenService extends Object implements OneTimeTokenService
Provides an in-memory implementation of the `OneTimeTokenService` interface that uses a `ConcurrentHashMap` to store the generated `OneTimeToken`. A random `UUID` is used as the token value. A clean-up of the expired tokens is made if there is more or equal than 100 tokens stored in the map.

Since:
  6.4

## Constructor Summary

Constructors
Constructor
Description
`InMemoryOneTimeTokenService()`

## Method Summary

Modifier and Type
Method
Description
`OneTimeToken`
`consume(OneTimeTokenAuthenticationToken authenticationToken)`
Consumes a one-time token based on the provided authentication token.
`OneTimeToken`
`generate(GenerateOneTimeTokenRequest request)`
Generates a one-time token based on the provided generate request.
`void`
`setClock(Clock clock)`
Sets the `Clock` used when generating one-time token and checking token expiry.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### InMemoryOneTimeTokenService

public InMemoryOneTimeTokenService()

## Method Details

### generate

@NonNull public OneTimeToken generate(GenerateOneTimeTokenRequest request)
Description copied from interface: `OneTimeTokenService`
Generates a one-time token based on the provided generate request.

Specified by:
  `generate` in interface `OneTimeTokenService`
Parameters:
  `request` - the generate request containing the necessary information to generate the token
Returns:
  the generated `OneTimeToken`, never `null`.

### consume

public OneTimeToken consume(OneTimeTokenAuthenticationToken authenticationToken)
Description copied from interface: `OneTimeTokenService`
Consumes a one-time token based on the provided authentication token.

Specified by:
  `consume` in interface `OneTimeTokenService`
Parameters:
  `authenticationToken` - the authentication token containing the one-time token value to be consumed
Returns:
  the consumed `OneTimeToken` or `null` if the token is invalid

### setClock

public void setClock(Clock clock)
Sets the `Clock` used when generating one-time token and checking token expiry.

Parameters:
  `clock` - the clock