C
- the type of credentials the authenticator can authenticateP
- the type of principals the authenticator returnspublic class CachingAuthenticator<C,P extends Principal> extends Object implements Authenticator<C,P>
Authenticator
decorator which uses a Caffeine cache to temporarily
cache credentials and their corresponding principals.Constructor and Description |
---|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder)
Creates a new cached authenticator.
|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder,
boolean cacheNegativeResult)
Creates a new cached authenticator.
|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder,
boolean cacheNegativeResult,
Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter> supplier)
Creates a new cached authenticator.
|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.github.benmanes.caffeine.cache.CaffeineSpec cacheSpec)
Creates a new cached authenticator.
|
Modifier and Type | Method and Description |
---|---|
Optional<P> |
authenticate(C credentials)
Given a set of user-provided credentials, return an optional principal.
|
void |
invalidate(C credentials)
Discards any cached principal for the given credentials.
|
void |
invalidateAll()
Discards all cached principals.
|
void |
invalidateAll(Iterable<C> credentials)
Discards any cached principal for the given collection of credentials.
|
void |
invalidateAll(Predicate<? super C> predicate)
Discards any cached principal for the collection of credentials satisfying the given predicate.
|
long |
size()
Returns the number of cached principals.
|
com.github.benmanes.caffeine.cache.stats.CacheStats |
stats()
Returns a set of statistics about the cache contents and usage.
|
public CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry, Authenticator<C,P> authenticator, com.github.benmanes.caffeine.cache.CaffeineSpec cacheSpec)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorcacheSpec
- a CaffeineSpec
public CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry, Authenticator<C,P> authenticator, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorbuilder
- a Caffeine
public CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry, Authenticator<C,P> authenticator, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder, boolean cacheNegativeResult)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorbuilder
- a Caffeine
cacheNegativeResult
- the boolean to enable negative cachepublic CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry, Authenticator<C,P> authenticator, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder, boolean cacheNegativeResult, Supplier<com.github.benmanes.caffeine.cache.stats.StatsCounter> supplier)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorbuilder
- a Caffeine
cacheNegativeResult
- the boolean to enable negative cachesupplier
- a Supplier
public Optional<P> authenticate(C credentials) throws AuthenticationException
Authenticator
Optional.of(Object)
.
If the credentials are invalid, returns an Optional.empty()
.authenticate
in interface Authenticator<C,P extends Principal>
credentials
- a set of user-provided credentialsAuthenticationException
- if the credentials cannot be authenticated due to an
underlying errorpublic void invalidate(C credentials)
credentials
- a set of credentialspublic void invalidateAll(Iterable<C> credentials)
credentials
- a collection of credentialspublic void invalidateAll(Predicate<? super C> predicate)
predicate
- a predicate to filter credentialspublic void invalidateAll()
public long size()
public com.github.benmanes.caffeine.cache.stats.CacheStats stats()
Copyright © 2011. All rights reserved.