Class CounterStorageKeyFunction
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.idp.consent.logic.impl.CounterStorageKeyFunction
-
- All Implemented Interfaces:
Function<net.shibboleth.utilities.java.support.collection.Pair<org.opensaml.profile.context.ProfileRequestContext,List<String>>,List<String>>,net.shibboleth.utilities.java.support.component.Component,net.shibboleth.utilities.java.support.component.DestructableComponent,net.shibboleth.utilities.java.support.component.InitializableComponent
public class CounterStorageKeyFunction extends net.shibboleth.utilities.java.support.component.AbstractInitializableComponent implements Function<net.shibboleth.utilities.java.support.collection.Pair<org.opensaml.profile.context.ProfileRequestContext,List<String>>,List<String>>
Function to order storage keys by least-used and oldest first during pruning of storage records. For every storage key supplied as input, this function attempts to lookup the number of times the flow corresponding to the storage key has been executed. As such, this function depends on theUpdateCounteraction being executed prior to this function.
-
-
Field Summary
Fields Modifier and Type Field Description private Function<org.opensaml.profile.context.ProfileRequestContext,net.shibboleth.idp.profile.context.ProfileInterceptorContext>interceptorContextlookupStrategyStrategy used to find theProfileInterceptorContextfrom theProfileRequestContext.private LoggerlogClass logger.private Function<org.opensaml.profile.context.ProfileRequestContext,String>storageContextLookupStrategyStrategy used to determine the storage storageContext.
-
Constructor Summary
Constructors Constructor Description CounterStorageKeyFunction()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>apply(net.shibboleth.utilities.java.support.collection.Pair<org.opensaml.profile.context.ProfileRequestContext,List<String>> input)protected StringgetCounterStorageKey(String storageKey)Get the storage key for the storage record whose value is a counter.protected StringgetStorageContext(org.opensaml.profile.context.ProfileRequestContext profileRequestContext)Get the storage context by applying the storage context lookup strategy to the profile request context.protected LonggetStorageKeyCounter(org.opensaml.storage.StorageService storageService, String storageContext, String storageKey)Get the counter for the given storage key.protected Map<String,Long>getStorageKeyCounters(org.opensaml.profile.context.ProfileRequestContext profileRequestContext, List<String> storageKeys)Get the map of storage keys to counters.protected org.opensaml.storage.StorageServicegetStorageService(org.opensaml.profile.context.ProfileRequestContext profileRequestContext)Get the storage service from the flow descriptor of the profile interceptor context.voidsetInterceptorContextLookupStrategy(Function<org.opensaml.profile.context.ProfileRequestContext,net.shibboleth.idp.profile.context.ProfileInterceptorContext> strategy)Set the profile interceptor context lookup strategy.voidsetStorageContextLookupStrategy(Function<org.opensaml.profile.context.ProfileRequestContext,String> strategy)Set the storage context lookup strategy.-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, doInitialize, initialize, isDestroyed, isInitialized
-
-
-
-
Field Detail
-
log
@Nonnull private final Logger log
Class logger.
-
interceptorContextlookupStrategy
@Nonnull private Function<org.opensaml.profile.context.ProfileRequestContext,net.shibboleth.idp.profile.context.ProfileInterceptorContext> interceptorContextlookupStrategy
Strategy used to find theProfileInterceptorContextfrom theProfileRequestContext.
-
-
Method Detail
-
setInterceptorContextLookupStrategy
public void setInterceptorContextLookupStrategy(@Nonnull Function<org.opensaml.profile.context.ProfileRequestContext,net.shibboleth.idp.profile.context.ProfileInterceptorContext> strategy)Set the profile interceptor context lookup strategy.- Parameters:
strategy- the profile interceptor context lookup strategy
-
setStorageContextLookupStrategy
public void setStorageContextLookupStrategy(@Nonnull Function<org.opensaml.profile.context.ProfileRequestContext,String> strategy)Set the storage context lookup strategy.- Parameters:
strategy- the storage context lookup strategy
-
getStorageService
@Nonnull protected org.opensaml.storage.StorageService getStorageService(@Nonnull org.opensaml.profile.context.ProfileRequestContext profileRequestContext)Get the storage service from the flow descriptor of the profile interceptor context. The profile interceptor context is retrieved by applying the profile interceptor context lookup strategy to the profile request context. The storage service is retrieved from the flow descriptor of the last interceptor flow which was attempted.- Parameters:
profileRequestContext- the profile request context- Returns:
- the storage service
- Throws:
net.shibboleth.utilities.java.support.logic.ConstraintViolationException- if the lookup strategy returnsnull, the interceptor flow descriptor isnull, or the storage service isnull
-
getStorageContext
@Nonnull protected String getStorageContext(@Nonnull org.opensaml.profile.context.ProfileRequestContext profileRequestContext)
Get the storage context by applying the storage context lookup strategy to the profile request context.- Parameters:
profileRequestContext- the profile request context- Returns:
- the storage context
- Throws:
net.shibboleth.utilities.java.support.logic.ConstraintViolationException- if the lookup strategy returnsnull
-
getCounterStorageKey
@Nonnull protected String getCounterStorageKey(@Nonnull String storageKey)
Get the storage key for the storage record whose value is a counter.- Parameters:
storageKey- the storage key- Returns:
- the storage key for the storage record whose value is a counter
-
getStorageKeyCounter
@Nullable protected Long getStorageKeyCounter(@Nonnull org.opensaml.storage.StorageService storageService, @Nonnull String storageContext, @Nonnull String storageKey) throws IOException
Get the counter for the given storage key.- Parameters:
storageService- the storage servicestorageContext- the storage contextstorageKey- the storage key- Returns:
- the counter for the given storage key
- Throws:
IOException- if a storage service error occursNumberFormatException- if the storage record value cannot be parsed as an integer
-
getStorageKeyCounters
@Nonnull protected Map<String,Long> getStorageKeyCounters(@Nonnull org.opensaml.profile.context.ProfileRequestContext profileRequestContext, @Nonnull List<String> storageKeys)
Get the map of storage keys to counters.- Parameters:
profileRequestContext- the profile request contextstorageKeys- the storage keys- Returns:
- map of storage keys to counters
-
-