|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.shiro.realm.CachingRealm
org.apache.shiro.realm.AuthenticatingRealm
public abstract class AuthenticatingRealm
A top-level abstract implementation of the Realm interface that only implements authentication support (log-in) operations and leaves authorization (access control) behavior to subclasses.
Since a Realm provides both authentication and authorization operations, the implementation approach for this class could have been reversed. That is, authorization support could have been implemented here and authentication support left to subclasses.
The reason the existing implementation is in place though (authentication support) is that most authentication operations are fairly common across the large majority of applications, whereas authorization operations are more so heavily dependent upon the application's data model, which can vary widely.
By providing the most common authentication operations here and leaving data-model specific authorization checks to subclasses, a top-level abstract class for most common authentication behavior is more useful as an extension point for most applications.
| Constructor Summary | |
|---|---|
AuthenticatingRealm()
|
|
AuthenticatingRealm(CacheManager cacheManager)
|
|
AuthenticatingRealm(CacheManager cacheManager,
CredentialsMatcher matcher)
|
|
AuthenticatingRealm(CredentialsMatcher matcher)
|
|
| Method Summary | |
|---|---|
protected abstract AuthenticationInfo |
doGetAuthenticationInfo(AuthenticationToken token)
Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given authentication token. |
AuthenticationInfo |
getAuthenticationInfo(AuthenticationToken token)
Returns an account's authentication-specific information for the specified token, or null if no account could be found based on the token. |
Class |
getAuthenticationTokenClass()
Returns the authenticationToken class supported by this realm. |
CredentialsMatcher |
getCredentialsMatcher()
Returns the CredentialsMatcher used during an authentication attempt to verify submitted
credentials with those stored in the system. |
void |
onLogout(PrincipalCollection principals)
Default implementation that does nothing (no-op) and exists as a convenience mechanism in case subclasses wish to override it to implement realm-specific logout logic for the given user account logging out. |
void |
setAuthenticationTokenClass(Class<? extends AuthenticationToken> authenticationTokenClass)
Sets the authenticationToken class supported by this realm. |
void |
setCredentialsMatcher(CredentialsMatcher credentialsMatcher)
Sets the CrendialsMatcher used during an authentication attempt to verify submitted credentials with those stored in the system. |
boolean |
supports(AuthenticationToken token)
Convenience implementation that returns getAuthenticationTokenClass().isAssignableFrom( token.getClass() );. |
| Methods inherited from class org.apache.shiro.realm.CachingRealm |
|---|
afterCacheManagerSet, getCacheManager, getName, isCachingEnabled, setCacheManager, setCachingEnabled, setName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.apache.shiro.authz.Authorizer |
|---|
checkPermission, checkPermission, checkPermissions, checkPermissions, checkRole, checkRoles, hasAllRoles, hasRole, hasRoles, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll |
| Constructor Detail |
|---|
public AuthenticatingRealm()
public AuthenticatingRealm(CacheManager cacheManager)
public AuthenticatingRealm(CredentialsMatcher matcher)
public AuthenticatingRealm(CacheManager cacheManager,
CredentialsMatcher matcher)
| Method Detail |
|---|
public CredentialsMatcher getCredentialsMatcher()
CredentialsMatcher used during an authentication attempt to verify submitted
credentials with those stored in the system.
Unless overridden by the setCredentialsMatcher method, the default
value is a SimpleCredentialsMatcher instance.
CredentialsMatcher used during an authentication attempt to verify submitted
credentials with those stored in the system.public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher)
Unless overridden by this method, the default value is a
SimpleCredentialsMatcher instance.
credentialsMatcher - the matcher to use.public Class getAuthenticationTokenClass()
The default value is UsernamePasswordToken.class, since
about 90% of realms use username/password authentication, regardless of their protocol (e.g. over jdbc, ldap,
kerberos, http, etc).
If subclasses haven't already overridden the Realm.supports(AuthenticationToken) method,
they must set a new class if they won't support
UsernamePasswordToken authentication token submissions.
setAuthenticationTokenClass(java.lang.Class extends org.apache.shiro.authc.AuthenticationToken>)public void setAuthenticationTokenClass(Class<? extends AuthenticationToken> authenticationTokenClass)
Unless overridden by this method, the default value is
UsernamePasswordToken.class to support the majority of applications.
authenticationTokenClass - the class of authentication token instances supported by this realm.getAuthenticationTokenClass() for more explanation.public boolean supports(AuthenticationToken token)
Most configurations will only need to set a different class via
setAuthenticationTokenClass(java.lang.Class extends org.apache.shiro.authc.AuthenticationToken>), as opposed to overriding this method.
supports in interface Realmtoken - the token being submitted for authentication.
public final AuthenticationInfo getAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException
RealmThis method effectively represents a login attempt for the corresponding user with the underlying EIS datasource. Most implementations merely just need to lookup and return the account data only (as the method name implies) and let Shiro do the rest, but implementations may of course perform eis specific login operations if so desired.
getAuthenticationInfo in interface Realmtoken - the application-specific representation of an account principal and credentials.
AuthenticationException - if there is an error obtaining or constructing an AuthenticationInfo object based on the
specified token or implementation-specifc login behavior fails.
protected abstract AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException
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.
A null return value means that no account could be associated with the specified token.
token - the authentication token containing the user's principal and credentials.
AuthenticationInfo object containing account data resulting from the
authentication ONLY if the lookup is successful (i.e. account exists and is valid, etc.)
AuthenticationException - if there is an error acquiring data or performing
realm-specific authentication logic for the specified tokenpublic void onLogout(PrincipalCollection principals)
principals method
argument will be the same as that which is contained in the AuthenticationInfo object returned by the
doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken) method (that is, info.getPrincipals()).
In a multi-realm Shiro configuration, the given principals method
argument could contain principals returned by many realms. Therefore the subclass implementation would need
to know how to extract the principal(s) relevant to only itself and ignore other realms' principals. This is
usually done by calling principals.fromRealm(name),
using the realm's own name.
onLogout in interface LogoutAwareprincipals - the application-specific Subject/user identifier that is logging out.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||