Class SimpleAccountRealm
java.lang.Object
org.apache.shiro.realm.CachingRealm
org.apache.shiro.realm.AuthenticatingRealm
org.apache.shiro.realm.AuthorizingRealm
org.apache.shiro.realm.SimpleAccountRealm
- All Implemented Interfaces:
LogoutAware,Authorizer,PermissionResolverAware,RolePermissionResolverAware,org.apache.shiro.cache.CacheManagerAware,org.apache.shiro.lang.util.Initializable,org.apache.shiro.lang.util.Nameable,Realm
- Direct Known Subclasses:
TextConfigurationRealm
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 Maps in memory, so it is expected that the total number of either
is not sufficiently large.- Since:
- 0.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String, SimpleRole> roleName-to-SimpleRole.protected final ReadWriteLockprotected final Map<String, SimpleAccount> username-to-SimpleAccount.protected final ReadWriteLock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccountExists(String username) protected voidadd(SimpleAccount account) protected voidadd(SimpleRole role) voidaddAccount(String username, String password) voidaddAccount(String username, String password, String... roles) voidprotected AuthenticationInfoRetrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc.) for the given authentication token.protected AuthorizationInfodoGetAuthorizationInfo(PrincipalCollection principals) Retrieves the AuthorizationInfo for the given principals from the underlying data store.protected SimpleRoleprotected SimpleAccountprotected StringgetUsername(SimpleAccount account) protected StringgetUsername(PrincipalCollection principals) booleanroleExists(String name) Methods inherited from class org.apache.shiro.realm.AuthorizingRealm
afterCacheManagerSet, checkPermission, checkPermission, checkPermission, checkPermissions, checkPermissions, checkPermissions, checkRole, checkRole, checkRoles, checkRoles, checkRoles, clearCachedAuthorizationInfo, doClearCache, getAuthorizationCache, getAuthorizationCacheKey, getAuthorizationCacheName, getAuthorizationInfo, getPermissionResolver, getPermissions, getRolePermissionResolver, hasAllRoles, hasRole, hasRole, hasRoles, hasRoles, isAuthorizationCachingEnabled, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, isPermittedAll, onInit, setAuthorizationCache, setAuthorizationCacheName, setAuthorizationCachingEnabled, setName, setPermissionResolver, setRolePermissionResolverMethods inherited from class org.apache.shiro.realm.AuthenticatingRealm
assertCredentialsMatch, clearCachedAuthenticationInfo, getAuthenticationCache, getAuthenticationCacheKey, getAuthenticationCacheKey, getAuthenticationCacheName, getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, init, isAuthenticationCachingEnabled, isAuthenticationCachingEnabled, setAuthenticationCache, setAuthenticationCacheName, setAuthenticationCachingEnabled, setAuthenticationTokenClass, setCredentialsMatcher, supportsMethods inherited from class org.apache.shiro.realm.CachingRealm
clearCache, getAvailablePrincipal, getCacheManager, getName, isCachingEnabled, onLogout, setCacheManager, setCachingEnabledMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.shiro.lang.util.Initializable
init
-
Field Details
-
users
username-to-SimpleAccount. -
roles
roleName-to-SimpleRole. -
usersLock
-
rolesLock
-
-
Constructor Details
-
SimpleAccountRealm
public SimpleAccountRealm() -
SimpleAccountRealm
-
-
Method Details
-
getUser
-
accountExists
-
addAccount
-
addAccount
-
getUsername
-
getUsername
-
add
-
getRole
-
roleExists
-
addRole
-
add
-
toSet
-
doGetAuthenticationInfo
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException Description copied from class:AuthenticatingRealmRetrieves 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 Shiro 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. Anullreturn value means that no account could be associated with the specified token.- Specified by:
doGetAuthenticationInfoin classAuthenticatingRealm- Parameters:
token- the authentication token containing the user's principal and credentials.- Returns:
- an
AuthenticationInfoobject 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
Description copied from class:AuthorizingRealmRetrieves 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 ofSimpleAuthorizationInfo, as it is suitable in most cases.- Specified by:
doGetAuthorizationInfoin classAuthorizingRealm- Parameters:
principals- the primary identifying principals of the AuthorizationInfo that should be retrieved.- Returns:
- the AuthorizationInfo associated with this principals.
- See Also:
-