public abstract class CachingRealm extends Object implements Realm, Nameable, CacheManagerAware, LogoutAware
Realm
interface that provides caching support for subclasses.
It also provides a convenience method,
getAvailablePrincipal(org.apache.shiro.subject.PrincipalCollection)
, which is useful across all
realm subclasses for obtaining a realm-specific principal/identity.
All actual Realm method implementations are left to subclasses.Constructor and Description |
---|
CachingRealm()
Default no-argument constructor that defaults
cachingEnabled (for general caching) to true and sets a
default name based on the class name. |
Modifier and Type | Method and Description |
---|---|
protected void |
afterCacheManagerSet()
Template method that may be implemented by subclasses should they wish to react to a
CacheManager instance being set on the realm instance via the
setCacheManager(org.apache.shiro.cache.CacheManager) mutator. |
protected void |
clearCache(PrincipalCollection principals)
Clears out any cached data associated with the specified account identity/identities.
|
protected void |
doClearCache(PrincipalCollection principals)
This implementation does nothing - it is a template to be overridden by subclasses if necessary.
|
protected Object |
getAvailablePrincipal(PrincipalCollection principals)
A utility method for subclasses that returns the first available principal of interest to this particular realm.
|
CacheManager |
getCacheManager()
Returns the CacheManager used for data caching to reduce EIS round trips, or null if
caching is disabled.
|
String |
getName()
Returns the (application-unique) name assigned to this
Realm . |
boolean |
isCachingEnabled()
|
void |
onLogout(PrincipalCollection principals)
If caching is enabled, this will clear any cached data associated with the specified account identity.
|
void |
setCacheManager(CacheManager cacheManager)
Sets the CacheManager to be used for data caching to reduce EIS round trips.
|
void |
setCachingEnabled(boolean cachingEnabled)
Sets whether or not caching should be used if a
CacheManager has been
configured . |
void |
setName(String name)
Sets the (preferably application unique) name for this component.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAuthenticationInfo, supports
public CachingRealm()
cachingEnabled
(for general caching) to true
and sets a
default name
based on the class name.
Note that while in general, caching may be enabled by default, subclasses have control over
if specific caching is enabled.public CacheManager getCacheManager()
public void setCacheManager(CacheManager cacheManager)
setCacheManager
in interface CacheManagerAware
cacheManager
- the CacheManager to use for data caching, or null to disable caching.public boolean isCachingEnabled()
true
if caching should be used if a CacheManager
has been
configured
, false
otherwise.
The default value is true
since the large majority of Realms will benefit from caching if a CacheManager
has been configured. However, memory-only realms should set this value to false
since they would
manage account data in memory already lookups would already be as efficient as possible.true
if caching will be globally enabled if a CacheManager
has been
configured, false
otherwisepublic void setCachingEnabled(boolean cachingEnabled)
CacheManager
has been
configured
.cachingEnabled
- whether or not to globally enable caching for this realm.public String getName()
Realm
Realm
. All realms configured for a single
application must have a unique name.public void setName(String name)
Nameable
protected void afterCacheManagerSet()
CacheManager
instance being set on the realm instance via the
setCacheManager(org.apache.shiro.cache.CacheManager)
mutator.public void onLogout(PrincipalCollection principals)
super.onLogout
first.
This default implementation merely calls clearCache(org.apache.shiro.subject.PrincipalCollection)
.onLogout
in interface LogoutAware
principals
- the application-specific Subject/user identifier that is logging out.clearCache(org.apache.shiro.subject.PrincipalCollection)
,
getAvailablePrincipal(org.apache.shiro.subject.PrincipalCollection)
protected void clearCache(PrincipalCollection principals)
doClearCache(org.apache.shiro.subject.PrincipalCollection)
.principals
- the principals of the account for which to clear any cached data.protected void doClearCache(PrincipalCollection principals)
principals
- principals the principals of the account for which to clear any cached data.protected Object getAvailablePrincipal(PrincipalCollection principals)
PrincipalCollection
via a
principals.fromRealm
(getName()
)
call.PrincipalCollection.getPrimaryPrincipal()
.null
principals
- the PrincipalCollection holding all principals (from all realms) associated with a single Subject.null
.Copyright © 2004-2016 The Apache Software Foundation. All Rights Reserved.