Package net.shibboleth.idp.plugin.authn.webauthn.storage.impl

# Class CacheServiceImpl

java.lang.Object
net.shibboleth.idp.plugin.authn.webauthn.storage.impl.CacheServiceImpl

All Implemented Interfaces:
  `CacheService`

public final class CacheServiceImpl extends Object implements CacheService
An implementation of a `CacheService` that handles the consistent conversion between `CredentialRecord`s and username cache entries using the supplied strategies.

Since:
  1.3.0

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`CacheServiceImpl.Builder`
A builder to safely construct this object.
`static interface`
`CacheServiceImpl.IBuildStage`
A builder stage.
`static interface`
`CacheServiceImpl.IUserHandleMappingCacheStage`
A builder stage.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final Cache<String,String>`
`cache`
The mapping cache.
`private final Function<CredentialRecord,String>`
`keyExtractionStrategy`
The strategy to use to convert a `CredentialRecord` into a key suitable for the cache.
`private final org.slf4j.Logger`
`log`
Class logger.
`private final Function<com.yubico.webauthn.data.ByteArray,String>`
`lookupKeyExtractionStrategy`
The strategy to use to convert a ByteArray into a key suitable for the cache.
`private final Function<CredentialRecord,String>`
`valueExtractionStrategy`
The strategy to use to convert a `CredentialRecord` into a suitable value for the cache.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`CacheServiceImpl(CacheServiceImpl.Builder builder)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`static CacheServiceImpl.IUserHandleMappingCacheStage`
`builder()`
Create a new builder.
`protected Cache<String,String>`
`getCache()`
Get the cache, for testing.
`String`
`getIfPresent(com.yubico.webauthn.data.ByteArray keyBytes)`
Returns the value associated with key in this cache, or `null` if there is no cached value.
`void`
`invalidate(com.yubico.webauthn.data.ByteArray key)`
Removes any cached value for the key.
`void`
`invalidateAll()`
Removes all entries in the cache.
`void`
`put(CredentialRecord registration)`
Associates the registration with the username in this cache.

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

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

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### cache

@Nonnull private final Cache<String,String> cache
The mapping cache.

### keyExtractionStrategy

@Nonnull private final Function<CredentialRecord,String> keyExtractionStrategy
The strategy to use to convert a `CredentialRecord` into a key suitable for the cache.

### lookupKeyExtractionStrategy

@Nonnull private final Function<com.yubico.webauthn.data.ByteArray,String> lookupKeyExtractionStrategy
The strategy to use to convert a ByteArray into a key suitable for the cache.

### valueExtractionStrategy

@Nonnull private final Function<CredentialRecord,String> valueExtractionStrategy
The strategy to use to convert a `CredentialRecord` into a suitable value for the cache.

## Constructor Details

### CacheServiceImpl

private CacheServiceImpl(CacheServiceImpl.Builder builder)
Constructor.

Parameters:
  `builder` - the builder used to construct the class

## Method Details

### getCache

protected Cache<String,String> getCache()
Get the cache, for testing.

Returns:
  the cache

### getIfPresent

public String getIfPresent(@Nonnull com.yubico.webauthn.data.ByteArray keyBytes)
Description copied from interface: `CacheService`
Returns the value associated with key in this cache, or `null` if there is no cached value.

Specified by:
  `getIfPresent` in interface `CacheService`
Parameters:
  `keyBytes` - the key to use
Returns:
  the username associated with key in the cache, or `null` if no mapping is found.

### put

public void put(@Nonnull CredentialRecord registration)
Description copied from interface: `CacheService`
Associates the registration with the username in this cache. If the cache previously contained a value associated with this registration, the old value is replaced by the username in the registration.

Specified by:
  `put` in interface `CacheService`
Parameters:
  `registration` - the registration to extract the mapping from.

### invalidate

public void invalidate(@Nonnull com.yubico.webauthn.data.ByteArray key)
Description copied from interface: `CacheService`
Removes any cached value for the key.

Specified by:
  `invalidate` in interface `CacheService`
Parameters:
  `key` - the key

### invalidateAll

public void invalidateAll()
Description copied from interface: `CacheService`
Removes all entries in the cache.

Specified by:
  `invalidateAll` in interface `CacheService`

### builder

public static CacheServiceImpl.IUserHandleMappingCacheStage builder()
Create a new builder.

Returns:
  the builder