C
- the type of credentials the authenticator can authenticateP
- the type of principals the authenticator returnspublic class CachingAuthenticator<C,P> extends Object implements Authenticator<C,P>
Authenticator
decorator which uses a Guava cache to temporarily cache credentials and
their corresponding principals.Constructor and Description |
---|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.google.common.cache.CacheBuilder<Object,Object> builder)
Creates a new cached authenticator.
|
CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry,
Authenticator<C,P> authenticator,
com.google.common.cache.CacheBuilderSpec 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(com.google.common.base.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.google.common.cache.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.google.common.cache.CacheBuilderSpec cacheSpec)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorcacheSpec
- a CacheBuilderSpec
public CachingAuthenticator(com.codahale.metrics.MetricRegistry metricRegistry, Authenticator<C,P> authenticator, com.google.common.cache.CacheBuilder<Object,Object> builder)
metricRegistry
- the application's registry of metricsauthenticator
- the underlying authenticatorbuilder
- a CacheBuilder
public Optional<P> authenticate(C credentials) throws io.dropwizard.auth.AuthenticationException
Authenticator
If the credentials are valid and map to a principal, returns an Optional.of(p)
.
If the credentials are invalid, returns an Optional.empty()
.
authenticate
in interface Authenticator<C,P>
credentials
- a set of user-provided credentialsio.dropwizard.auth.AuthenticationException
- 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(com.google.common.base.Predicate<? super C> predicate)
predicate
- a predicate to filter credentialspublic void invalidateAll()
public long size()
public com.google.common.cache.CacheStats stats()
Copyright © 2014. All rights reserved.