JSecurity

org.jsecurity.realm
Class SimpleAccountRealm

java.lang.Object
  extended by org.jsecurity.realm.CachingRealm
      extended by org.jsecurity.realm.AuthenticatingRealm
          extended by org.jsecurity.realm.AuthorizingRealm
              extended by org.jsecurity.realm.SimpleAccountRealm
All Implemented Interfaces:
LogoutAware, Authorizer, PermissionResolverAware, CacheManagerAware, Realm, Initializable
Direct Known Subclasses:
TextConfigurationRealm

public class SimpleAccountRealm
extends AuthorizingRealm

A simple implementation of the Realm interface that uses a set of configured user accounts and roles to support authentication and authorization. Each account entry specifies the username, password, and roles for a user. Roles can also be mapped to permissions and associated with users.

User accounts and roles are stored in two caches, so it is the Cache manager implementation that determines if this class stores all data in memory or spools to disk or clusters it, etc based on the Caches it creates.

Since:
0.1
Author:
Jeremy Haile, Les Hazlewood

Field Summary
protected  Map<String,SimpleRole> roles
           
 
Constructor Summary
SimpleAccountRealm()
           
SimpleAccountRealm(String name)
           
 
Method Summary
protected  void accountAndRoleCachesCreated()
           
 boolean accountExists(String username)
           
protected  void add(SimpleAccount account)
           
protected  void add(SimpleRole role)
           
 void addAccount(String username, String password)
           
 void addAccount(String username, String password, String... roles)
           
 void addRole(String name)
           
 void afterAuthorizationCacheSet()
           
 void afterRoleCacheSet()
           
protected  AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
          Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given authentication token.
protected  AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
          Retrieves the AuthorizationInfo for the given principals from the underlying data store.
protected  Object getAuthorizationCacheKey(PrincipalCollection principals)
           
protected  SimpleRole getRole(String rolename)
           
protected  SimpleAccount getUser(String username)
           
protected  void initRoleCache()
           
 boolean roleExists(String name)
           
protected static Set<String> toSet(String delimited, String delimiter)
           
 
Methods inherited from class org.jsecurity.realm.AuthorizingRealm
afterCacheManagerSet, checkPermission, checkPermission, checkPermission, checkPermissions, checkPermissions, checkPermissions, checkRole, checkRole, checkRoles, checkRoles, clearCachedAuthorizationInfo, getAuthorizationCache, getAuthorizationCacheName, getAuthorizationInfo, getPermissionResolver, hasAllRoles, hasRole, hasRole, hasRoles, hasRoles, init, initAuthorizationCache, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, isPermittedAll, onLogout, setAuthorizationCache, setAuthorizationCacheName, setPermissionResolver
 
Methods inherited from class org.jsecurity.realm.AuthenticatingRealm
getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, setAuthenticationTokenClass, setCredentialsMatcher, supports
 
Methods inherited from class org.jsecurity.realm.CachingRealm
getCacheManager, getName, setCacheManager, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

roles

protected Map<String,SimpleRole> roles
Constructor Detail

SimpleAccountRealm

public SimpleAccountRealm()

SimpleAccountRealm

public SimpleAccountRealm(String name)
Method Detail

afterAuthorizationCacheSet

public void afterAuthorizationCacheSet()
Overrides:
afterAuthorizationCacheSet in class AuthorizingRealm

afterRoleCacheSet

public void afterRoleCacheSet()

initRoleCache

protected void initRoleCache()

getUser

protected SimpleAccount getUser(String username)

accountExists

public boolean accountExists(String username)

addAccount

public void addAccount(String username,
                       String password)

addAccount

public void addAccount(String username,
                       String password,
                       String... roles)

add

protected void add(SimpleAccount account)

getRole

protected SimpleRole getRole(String rolename)

roleExists

public boolean roleExists(String name)

addRole

public void addRole(String name)

add

protected void add(SimpleRole role)

toSet

protected static Set<String> toSet(String delimited,
                                   String delimiter)

accountAndRoleCachesCreated

protected void accountAndRoleCachesCreated()

doGetAuthenticationInfo

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
                                              throws AuthenticationException
Description copied from class: AuthenticatingRealm
Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given authentication token.

For most datasources, this means just 'pulling' authentication data for an associated subject/user and nothing more and letting JSecurity do the rest. But in some systems, this method could actually perform EIS specific log-in logic in addition to just retrieving data - it is up to the Realm implementation.

A null return value means that no account could be associated with the specified token.

Specified by:
doGetAuthenticationInfo in class AuthenticatingRealm
Parameters:
token - the authentication token containing the user's principal and credentials.
Returns:
an AuthenticationInfo object containing account data resulting from the authentication ONLY if the lookup is successful (i.e. account exists and is valid, etc.)
Throws:
AuthenticationException - if there is an error acquiring data or performing realm-specific authentication logic for the specified token

doGetAuthorizationInfo

protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
Description copied from class: AuthorizingRealm
Retrieves the AuthorizationInfo for the given principals from the underlying data store. When returning an instance from this method, you might want to consider using an instance of SimpleAuthorizationInfo, as it is suitable in most cases.

Specified by:
doGetAuthorizationInfo in class AuthorizingRealm
Parameters:
principals - the primary identifying principals of the AuthorizationInfo that should be retrieved.
Returns:
the AuthorizationInfo associated with this principals.
See Also:
SimpleAuthorizationInfo

getAuthorizationCacheKey

protected Object getAuthorizationCacheKey(PrincipalCollection principals)
Overrides:
getAuthorizationCacheKey in class AuthorizingRealm

JSecurity

Copyright © 2004-2008 JSecurity.