|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.shiro.codec.CodecSupport
org.apache.shiro.authc.credential.SimpleCredentialsMatcher
org.apache.shiro.authc.credential.HashedCredentialsMatcher
public abstract class HashedCredentialsMatcher
A HashedCredentialMatcher provides support for hashing of supplied AuthenticationToken credentials
before being compared to those in the AuthenticationInfo from the data store.
AuthenticationToken credentials supplied by the user during their login. It then
compares this hashed value directly with the AuthenticationInfo credentials stored in the system. The stored account
credentials are expected to already be in hashed form. If these two values are equal, the submitted credentials
match.
Md5Hash, Sha1Hash, etc)
support salting and multiple hash iterations via overloaded constructors.
hashSalted to
true. If you do enable it, the value used to salt the hash will be
obtained from getSalt(authenticationToken).
The default getSalt implementation merely returns
token.getPrincipal(), effectively using the user's identity as the salt, a most common
technique. If you wish to provide the authentication token's salt another way, you may override this
getSalt method.
hashIterations property.
Note: MD5 and
SHA-1 algorithms are now known to be vulnerable to
compromise and/or collisions (read the linked pages for more). While most applications are ok with either of these
two, if your application mandates high security, use the SHA-256 (or higher) hashing algorithms and their
supporting CredentialsMatcher implementations.
Md5Hash,
Sha1Hash,
Sha256Hash| Field Summary |
|---|
| Fields inherited from class org.apache.shiro.codec.CodecSupport |
|---|
PREFERRED_ENCODING |
| Constructor Summary | |
|---|---|
HashedCredentialsMatcher()
|
|
| Method Summary | |
|---|---|
protected Object |
getCredentials(AuthenticationInfo info)
Returns a Hash instance representing the already-hashed AuthenticationInfo credentials stored in the system. |
protected Object |
getCredentials(AuthenticationToken token)
As this is a HashedCredentialMatcher, this method overrides the parent method by returning a hashed value of the submitted token's credentials. |
int |
getHashIterations()
Returns the number of times a submitted AuthenticationToken's credentials will be hashed before
comparing to the credentials stored in the system. |
protected Object |
getSalt(AuthenticationToken token)
Returns a salt value used to hash the token's credentials. |
protected abstract Hash |
hashProvidedCredentials(Object credentials,
Object salt,
int hashIterations)
Hashes the provided credentials a total of hashIterations times, using the given salt. |
boolean |
isHashSalted()
Returns true if a submitted AuthenticationToken's credentials should be salted when hashing,
false if it should not be salted. |
boolean |
isStoredCredentialsHexEncoded()
Returns true if the system's stored credential hash is Hex encoded, false if it
is Base64 encoded. |
protected abstract AbstractHash |
newHashInstance()
Returns a new, uninitialized instance, without its byte array set. |
void |
setHashIterations(int hashIterations)
Sets the number of times a submitted AuthenticationToken's credentials will be hashed before comparing
to the credentials stored in the system. |
void |
setHashSalted(boolean hashSalted)
Sets whether or not to salt a submitted AuthenticationToken's credentials when hashing. |
void |
setStoredCredentialsHexEncoded(boolean storedCredentialsHexEncoded)
Sets the indicator if this system's stored credential hash is Hex encoded or not. |
| Methods inherited from class org.apache.shiro.authc.credential.SimpleCredentialsMatcher |
|---|
doCredentialsMatch, equals |
| Methods inherited from class org.apache.shiro.codec.CodecSupport |
|---|
isByteSource, objectToBytes, objectToString, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toBytes, toChars, toChars, toString, toString, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public HashedCredentialsMatcher()
| Method Detail |
|---|
public boolean isStoredCredentialsHexEncoded()
true if the system's stored credential hash is Hex encoded, false if it
is Base64 encoded.
Default value is true for convenience - all of Shiro's Hash#toString()
implementations return Hex encoded values by default, making this class's use with those implementations
easier.
true if the system's stored credential hash is Hex encoded, false if it
is Base64 encoded. Default is truepublic void setStoredCredentialsHexEncoded(boolean storedCredentialsHexEncoded)
true will cause this class to decode the system credential from Hex, a
value of false will cause this class to decode the system credential from Base64.
Unless overridden via this method, the default value is true for convenience - all of Shiro's
Hash#toString() implementations return Hex encoded values by default, making this class's use with
those implementations easier.
storedCredentialsHexEncoded - the indicator if this system's stored credential hash is Hex
encoded or not ('not' automatically implying it is Base64 encoded).public boolean isHashSalted()
true if a submitted AuthenticationToken's credentials should be salted when hashing,
false if it should not be salted.
If enabled, the salt used will be obtained via the getSalt method.
The default value is false.
true if a submitted AuthenticationToken's credentials should be salted when hashing,
false if it should not be salted.public void setHashSalted(boolean hashSalted)
AuthenticationToken's credentials when hashing.
If enabled, the salt used will be obtained via the getSalt method.
The default value is false.
hashSalted - whether or not to salt a submitted AuthenticationToken's credentials when hashing.public int getHashIterations()
AuthenticationToken's credentials will be hashed before
comparing to the credentials stored in the system.
Unless overridden, the default value is 1, meaning a normal hash execution will occur.
AuthenticationToken's credentials will be hashed before
comparing to the credentials stored in the system.public void setHashIterations(int hashIterations)
AuthenticationToken's credentials will be hashed before comparing
to the credentials stored in the system.
Unless overridden, the default value is 1, meaning a normal single hash execution will occur.
If this argument is less than 1 (i.e. 0 or negative), the default value of 1 is applied. There must always be
at least 1 hash iteration (otherwise there would be no hash).
hashIterations - the number of times to hash a submitted AuthenticationToken's credentials.protected Object getSalt(AuthenticationToken token)
token.getPrincipal(), effectively using the user's
identity (username, user id, etc) as the salt, a most common technique. If you wish to provide the
authentication token's salt another way, you may override this method.
token - the AuthenticationToken submitted during the authentication attempt.
protected Object getCredentials(AuthenticationToken token)
getCredentials in class SimpleCredentialsMatchertoken - the authentication token submitted during the authentication attempt.
protected Object getCredentials(AuthenticationInfo info)
Hash instance representing the already-hashed AuthenticationInfo credentials stored in the system.
This method reconstructs a Hash instance based on a info.getCredentials call,
but it does not hash that value - it is expected that method call will return an already-hashed value.
This implementation's reconstruction effort functions as follows:
account.getCredentials() to a byte array via the toBytes method.
account.getCredentials() was originally a String or char[] before toBytes was
called, check for encoding:
storedCredentialsHexEncoded, Hex decode that byte array, otherwise
Base64 decode the byte arrayHash implementation and return it.
getCredentials in class SimpleCredentialsMatcherinfo - the AuthenticationInfo from which to retrieve the credentials which assumed to be in already-hashed form.
Hash instance representing the given AuthenticationInfo's stored credentials.
protected abstract Hash hashProvidedCredentials(Object credentials,
Object salt,
int hashIterations)
hashIterations times, using the given salt. The hash
implementation/algorithm used is left to subclasses.
credentials - the submitted authentication token's credentials to hashsalt - the value to salt the hash, or null if a salt will not be used.hashIterations - the number of times to hash the credentials. At least one hash will always occur though,
even if this argument is 0 or negative.
protected abstract AbstractHash newHashInstance()
getCredentials(AuthenticationInfo) implementation.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||