CachingRealm

A very basic abstract extension point for the {@link Realm} interface that provides caching support for subclasses. <p/> It also provides a convenience method, {@link #getAvailablePrincipal(hunt.shiro.subject.PrincipalCollection)}, which is useful across all realm subclasses for obtaining a realm-specific principal/identity. <p/> All actual Realm method implementations are left to subclasses.

@see #clearCache(hunt.shiro.subject.PrincipalCollection) @see #onLogout(hunt.shiro.subject.PrincipalCollection) @see #getAvailablePrincipal(hunt.shiro.subject.PrincipalCollection)

Constructors

this
this()

Default no-argument constructor that defaults {@link #isCachingEnabled() cachingEnabled} (for general caching) to {@code true} and sets a default {@link #getName() name} based on the class name. <p/> Note that while in general, caching may be enabled by default, subclasses have control over if specific caching is enabled.

Members

Functions

afterCacheManagerSet
void afterCacheManagerSet()

Template method that may be implemented by subclasses should they wish to react to a {@link CacheManager} instance being set on the realm instance via the {@link #setCacheManager(hunt.shiro.cache.CacheManager)} mutator.

clearCache
void clearCache(PrincipalCollection principals)

Clears out any cached data associated with the specified account identity/identities. <p/> This implementation will return quietly if the principals argument is null or empty. Otherwise it delegates to {@link #doClearCache(hunt.shiro.subject.PrincipalCollection)}.

doClearCache
void doClearCache(PrincipalCollection principals)

This implementation does nothing - it is a template to be overridden by subclasses if necessary.

getAvailablePrincipal
Object getAvailablePrincipal(PrincipalCollection principals)

A utility method for subclasses that returns the first available principal of interest to this particular realm. The heuristic used to acquire the principal is as follows: <ul> <li>Attempt to get <em>this particular Realm's</em> 'primary' principal in the {@code PrincipalCollection} via a <code>principals.{@link PrincipalCollection#fromRealm(string) fromRealm}({@link #getName() getName()})</code> call.</li> <li>If the previous call does not result in any principals, attempt to get the overall 'primary' principal from the PrincipalCollection via {@link hunt.shiro.subject.PrincipalCollection#getPrimaryPrincipal()}.</li> <li>If there are no principals from that call (or the PrincipalCollection argument was null to begin with), return {@code null}</li> </ul>

getCacheManager
CacheManager getCacheManager()

Returns the <tt>CacheManager</tt> used for data caching to reduce EIS round trips, or <tt>null</tt> if caching is disabled.

getName
string getName()
Undocumented in source. Be warned that the author may not have intended to support it.
isCachingEnabled
bool isCachingEnabled()

Returns {@code true} if caching should be used if a {@link CacheManager} has been {@link #setCacheManager(hunt.shiro.cache.CacheManager) configured}, {@code false} otherwise. <p/> The default value is {@code 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 {@code false} since they would manage account data in memory already lookups would already be as efficient as possible.

onLogout
void onLogout(PrincipalCollection principals)

If caching is enabled, this will clear any cached data associated with the specified account identity. Subclasses are free to override for additional behavior, but be sure to call {@code super.onLogout} first. <p/> This default implementation merely calls {@link #clearCache(hunt.shiro.subject.PrincipalCollection)}.

setCacheManager
void setCacheManager(CacheManager cacheManager)

Sets the <tt>CacheManager</tt> to be used for data caching to reduce EIS round trips. <p/> This property is <tt>null</tt> by default, indicating that caching is turned off.

setCachingEnabled
void setCachingEnabled(bool cachingEnabled)

Sets whether or not caching should be used if a {@link CacheManager} has been {@link #setCacheManager(hunt.shiro.cache.CacheManager) configured}.

setName
void setName(string name)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From Realm

getName
string getName()

Returns the (application-unique) name assigned to this <code>Realm</code>. All realms configured for a single application must have a unique name.

supports
bool supports(AuthenticationToken token)

Returns <tt>true</tt> if this realm wishes to authenticate the Subject represented by the given {@link hunt.shiro.authc.AuthenticationToken AuthenticationToken} instance, <tt>false</tt> otherwise.

getAuthenticationInfo
AuthenticationInfo getAuthenticationInfo(AuthenticationToken token)

Returns an account's authentication-specific information for the specified <tt>token</tt>, or <tt>null</tt> if no account could be found based on the <tt>token</tt>.

From Nameable

setName
void setName(string name)

Sets the (preferably application unique) name for this component. @param name the preferably application unique name for this component.

From CacheManagerAware

setCacheManager
void setCacheManager(CacheManager cacheManager)

Sets the available CacheManager instance on this component.

From LogoutAware

onLogout
void onLogout(PrincipalCollection principals)

Callback triggered when a <code>Subject</code> logs out of the system.

Meta