P
- the type of principals on which the authorizer operatespublic class CachingAuthorizer<P extends Principal> extends Object implements Authorizer<P>
Authorizer
decorator which uses a Caffeine
cache to
temporarily cache principals' role associations.
Cache entries include both inclusion and exclusion of a principal within a given role.
Constructor and Description |
---|
CachingAuthorizer(com.codahale.metrics.MetricRegistry metricRegistry,
Authorizer<P> authorizer,
com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder)
Creates a new cached authorizer.
|
CachingAuthorizer(com.codahale.metrics.MetricRegistry metricRegistry,
Authorizer<P> authorizer,
com.github.benmanes.caffeine.cache.CaffeineSpec cacheSpec)
Creates a new cached authorizer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
authorize(P principal,
String role)
Decides if access is granted for the given principal in the given role.
|
boolean |
authorize(P principal,
String role,
javax.ws.rs.container.ContainerRequestContext requestContext)
Decides if access is granted for the given principal in the given role.
|
void |
invalidate(P principal)
Discards any cached role associations for the given principal.
|
void |
invalidate(P principal,
String role,
javax.ws.rs.container.ContainerRequestContext requestContext)
Discards any cached role associations for the given principal and role.
|
void |
invalidateAll()
Discards all cached role associations.
|
void |
invalidateAll(Iterable<P> principals)
Discards any cached role associations for the given collection
of principals.
|
void |
invalidateAll(Predicate<? super P> predicate)
Discards any cached role associations for principals satisfying
the given predicate.
|
long |
size()
Returns the number of principals for which there are cached
role associations.
|
com.github.benmanes.caffeine.cache.stats.CacheStats |
stats()
Returns a set of statistics about the cache contents and usage.
|
public CachingAuthorizer(com.codahale.metrics.MetricRegistry metricRegistry, Authorizer<P> authorizer, com.github.benmanes.caffeine.cache.CaffeineSpec cacheSpec)
metricRegistry
- the application's registry of metricsauthorizer
- the underlying authorizercacheSpec
- CaffeineSpec
public CachingAuthorizer(com.codahale.metrics.MetricRegistry metricRegistry, Authorizer<P> authorizer, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> builder)
metricRegistry
- the application's registry of metricsauthorizer
- the underlying authorizerbuilder
- a CaffeineSpec
public boolean authorize(P principal, String role)
Authorizer
authorize
in interface Authorizer<P extends Principal>
principal
- a Principal
object, representing a userrole
- a user roletrue
, if the access is granted, false otherwise
public boolean authorize(P principal, String role, @Nullable javax.ws.rs.container.ContainerRequestContext requestContext)
Authorizer
authorize
in interface Authorizer<P extends Principal>
principal
- a Principal
object, representing a userrole
- a user rolerequestContext
- a request context.true
, if the access is granted, false otherwise
public void invalidate(P principal, String role, javax.ws.rs.container.ContainerRequestContext requestContext)
principal
- role
- requestContext
- public void invalidate(P principal)
principal
- public void invalidateAll(Iterable<P> principals)
principals
- a list of principalspublic void invalidateAll(Predicate<? super P> predicate)
predicate
- a predicate to filter credentialspublic void invalidateAll()
public long size()
public com.github.benmanes.caffeine.cache.stats.CacheStats stats()
Copyright © 2020. All rights reserved.