JSecurity

org.jsecurity.mgt
Class CachingSecurityManager

java.lang.Object
  extended by org.jsecurity.mgt.CachingSecurityManager
All Implemented Interfaces:
Authenticator, Authorizer, CacheManagerAware, SecurityManager, SessionFactory, Destroyable
Direct Known Subclasses:
RealmSecurityManager

public abstract class CachingSecurityManager
extends Object
implements SecurityManager, Destroyable, CacheManagerAware

A very basic extension point for the SecurityManager interface that merely provides logging and caching support. All SecurityManager method implementations are left to subclasses.

Upon instantiation, a sensible default CacheManager will be attempt to be created automatically by the ensureCacheManager() method. This CacheManager can then be used by subclass implementations and children components for use to achieve better application performance.

Since:
0.9
Author:
Les Hazlewood, Jeremy Haile

Field Summary
protected  CacheManager cacheManager
           
 
Constructor Summary
CachingSecurityManager()
          Default no-arg constructor that will automatically attempt to initialize a default cacheManager by calling ensureCacheManager().
 
Method Summary
protected  void afterCacheManagerSet()
          Template callback to notify subclasses that a CacheManager has been set and is available for use via the getCacheManager() method.
protected  void beforeCacheManagerDestroyed()
           
protected  CacheManager createCacheManager()
          Creates a CacheManager instance to be used by this SecurityManager and potentially any of its children components.
 void destroy()
          Called when this object is being destroyed, allowing any necessary cleanup of internal resources.
protected  void destroyCacheManager()
           
protected  void ensureCacheManager()
          Simple lazy-initialization method that checks to see if a cacheManager has been set, and if not, attempts to create one and uses that to set the class attribute.
 CacheManager getCacheManager()
          Returns the CacheManager used by this SecurityManager.
 void setCacheManager(CacheManager cacheManager)
          Sets the CacheManager used by this SecurityManager and potentially any of its children components.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jsecurity.mgt.SecurityManager
getSubject, login, logout
 
Methods inherited from interface org.jsecurity.authc.Authenticator
authenticate
 
Methods inherited from interface org.jsecurity.authz.Authorizer
checkPermission, checkPermission, checkPermissions, checkPermissions, checkRole, checkRoles, hasAllRoles, hasRole, hasRoles, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll
 
Methods inherited from interface org.jsecurity.session.SessionFactory
getSession, start
 

Field Detail

cacheManager

protected CacheManager cacheManager
Constructor Detail

CachingSecurityManager

public CachingSecurityManager()
Default no-arg constructor that will automatically attempt to initialize a default cacheManager by calling ensureCacheManager().

Method Detail

getCacheManager

public CacheManager getCacheManager()
Returns the CacheManager used by this SecurityManager.

Returns:
the cacheManager used by this SecurityManager

setCacheManager

public void setCacheManager(CacheManager cacheManager)
Sets the CacheManager used by this SecurityManager and potentially any of its children components.

After the cacheManager attribute has been set, the template method afterCacheManagerSet() is executed to allow subclasses to adjust when a cacheManager is available.

Specified by:
setCacheManager in interface CacheManagerAware
Parameters:
cacheManager - the CacheManager used by this SecurityManager and potentially any of its children components.

ensureCacheManager

protected void ensureCacheManager()
Simple lazy-initialization method that checks to see if a cacheManager has been set, and if not, attempts to create one and uses that to set the class attribute.

The default implementation functions as follows:


 CacheManager cm = getCacheManager();
 if (cm == null) {
     cm = createCacheManager();
     if (cm != null) {
         setCacheManager(cm);
     }
 }


afterCacheManagerSet

protected void afterCacheManagerSet()
Template callback to notify subclasses that a CacheManager has been set and is available for use via the getCacheManager() method.


createCacheManager

protected CacheManager createCacheManager()
Creates a CacheManager instance to be used by this SecurityManager and potentially any of its children components.

This default implementation attempts to create an EhCacheManager, assuming that ehcache is in the classpath. If Ehcache is not in the classpath, no cache manager will be created and this method does nothing.

This can be overridden by subclasses for a different implementation, but it is often easier to set a different implementation via the setCacheManager method, for example in code or Dependency Injection frameworks (a la Spring or JEE 3).

Returns:
a newly created CacheManager instance.
See Also:
ensureCacheManager()

destroy

public void destroy()
Description copied from interface: Destroyable
Called when this object is being destroyed, allowing any necessary cleanup of internal resources.

Specified by:
destroy in interface Destroyable

beforeCacheManagerDestroyed

protected void beforeCacheManagerDestroyed()

destroyCacheManager

protected void destroyCacheManager()

JSecurity

Copyright © 2004-2008 JSecurity.