JSecurity

org.jsecurity.mgt
Class RealmSecurityManager

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

public abstract class RealmSecurityManager
extends CachingSecurityManager

JSecurity support of a SecurityManager class hierarchy based around a collection of Realms. All actual SecurityManager method implementations are left to subclasses.

Since:
0.9
Author:
Les Hazlewood

Field Summary
protected  Collection<Realm> realms
          Internal collection of Realms used for all authentication and authorization operations.
 
Fields inherited from class org.jsecurity.mgt.CachingSecurityManager
cacheManager
 
Constructor Summary
RealmSecurityManager()
          Default no-arg constructor.
 
Method Summary
protected  void afterCacheManagerSet()
          Simply calls applyCacheManagerToRealms() to allow the newly set CacheManager to be propagated to the internal collection of Realm that would need to use it.
protected  void applyCacheManagerToRealms()
          Sets the internal CacheManager on any internal configured Realms that implement the CacheManagerAware interface.
protected  void beforeCacheManagerDestroyed()
          First calls beforeRealmsDestroyed() to allow subclasses to clean up first, then calls destroyRealms() to clean up the internal Realms collection.
protected  void beforeRealmsDestroyed()
          Template hook for subclasses to perform clean up logic during shut-down.
protected  Realm createDefaultRealm()
          Creates a default Realm implementation to use in lazy-initialization use cases.
protected  void destroyRealms()
          Cleans up ('destroys') the internal collection of Realms by calling LifecycleUtils.destroy(getRealms()).
protected  void ensureRealms()
          Ensures at least one realm exists, and if not calls createDefaultRealm() and sets it on this instance via the setRealm method.
 Collection<Realm> getRealms()
          Returns the Realms managed by this SecurityManager instance.
 void setRealm(Realm realm)
          Convenience method for applications using a single realm that merely wraps the realm in a list and then invokes the setRealms(java.util.Collection) method.
 void setRealms(Collection<Realm> realms)
          Sets the realms managed by this SecurityManager instance.
 
Methods inherited from class org.jsecurity.mgt.CachingSecurityManager
createCacheManager, destroy, destroyCacheManager, ensureCacheManager, getCacheManager, setCacheManager
 
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

realms

protected Collection<Realm> realms
Internal collection of Realms used for all authentication and authorization operations.

Constructor Detail

RealmSecurityManager

public RealmSecurityManager()
Default no-arg constructor.

Method Detail

setRealm

public void setRealm(Realm realm)
Convenience method for applications using a single realm that merely wraps the realm in a list and then invokes the setRealms(java.util.Collection) method.

Parameters:
realm - the realm to set for a single-realm application.
Since:
0.2

setRealms

public void setRealms(Collection<Realm> realms)
Sets the realms managed by this SecurityManager instance.

Parameters:
realms - the realms managed by this SecurityManager instance.

ensureRealms

protected void ensureRealms()
Ensures at least one realm exists, and if not calls createDefaultRealm() and sets it on this instance via the setRealm method.

This method is used to lazily ensure at least one default Realm exists in all environments, even if it is just with demo data, to ensure that JSecurity is usuable with the smallest (even no) configuration.


createDefaultRealm

protected Realm createDefaultRealm()
Creates a default Realm implementation to use in lazy-initialization use cases.

The implementation returned is a PropertiesRealm, which supports very simple properties-based user/role/permission configuration in testing, sample, and simple applications.

Returns:
the default Realm implementation (a PropertiesRealm to use in lazy-init use cases.

getRealms

public Collection<Realm> getRealms()
Returns the Realms managed by this SecurityManager instance.

Returns:
the Realms managed by this SecurityManager instance.

applyCacheManagerToRealms

protected void applyCacheManagerToRealms()
Sets the internal CacheManager on any internal configured Realms that implement the CacheManagerAware interface.

This method is called after setting a cacheManager on this securityManager via the setCacheManager method to allow it to be propagated down to all the internal Realms that would need to use it.

It is also called after setting one or more realms via the setRealm or setRealms methods to allow these newly available realms to be given the cache manager already in use.


afterCacheManagerSet

protected void afterCacheManagerSet()
Simply calls applyCacheManagerToRealms() to allow the newly set CacheManager to be propagated to the internal collection of Realm that would need to use it.

Overrides:
afterCacheManagerSet in class CachingSecurityManager

beforeCacheManagerDestroyed

protected void beforeCacheManagerDestroyed()
First calls beforeRealmsDestroyed() to allow subclasses to clean up first, then calls destroyRealms() to clean up the internal Realms collection.

Overrides:
beforeCacheManagerDestroyed in class CachingSecurityManager

beforeRealmsDestroyed

protected void beforeRealmsDestroyed()
Template hook for subclasses to perform clean up logic during shut-down.


destroyRealms

protected void destroyRealms()
Cleans up ('destroys') the internal collection of Realms by calling LifecycleUtils.destroy(getRealms()).


JSecurity

Copyright © 2004-2008 JSecurity.